PYTHONPATH environment variable set on windows machines causes salt-call commands to fail
search cancel

PYTHONPATH environment variable set on windows machines causes salt-call commands to fail

book

Article ID: 386326

calendar_today

Updated On: 01-21-2025

Products

VMware Aria Suite

Issue/Introduction

If the PYTHONPATH environment variable is set on windows machines salt-call commands get the following error:
C:\Windows\system32> salt-call test.ping
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = xxxx
  program name = 'C:\Program Files\Salt Project\Salt\Scripts\python.exe'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'C:\\Program Files\\Salt Project\\Salt\\Scripts\\python.exe'
  sys.base_prefix = 'C:\\Program Files\\Salt Project\\Salt'
  sys.base_exec_prefix = 'C:\\Program Files\\Salt Project\\Salt'
  sys.platlibdir = 'lib'
  sys.executable = 'C:\\Program Files\\Salt Project\\Salt\\Scripts\\python.exe'
  sys.prefix = 'C:\\Program Files\\Salt Project\\Salt'
  sys.exec_prefix = 'C:\\Program Files\\Salt Project\\Salt'
  sys.path = [
    xxxx
    'C:\\Program Files\\Salt Project\\Salt\\Scripts\\python310.zip',
    'C:\\Program Files\\Salt Project\\Salt\\DLLs',
    'C:\\Program Files\\Salt Project\\Salt\\lib',
    'C:\\Program Files\\Salt Project\\Salt\\Scripts',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ImportError: bad magic number in 'encodings': b'\xb3\xf2\r\n'

Environment

Salt-minions on Windows

Resolution

You can check this by looking at the settings in the service. You can view this by running the following command from within the Salt folder:

cd "\Program Files\Salt Project\Salt"
ssm.exe edit salt-minion

Then navigate to the "Environment" tab

There should be an entry there that says "PYTHONPATH="
If there is not you can run the following command to set it.

ssm.exe set salt-minion AppEnvironmentExtra PYTHONPATH=