0

I would like to add a path to the PYTHONPATH environment variable.

When I execute the following code

for path in os.environ["PYTHONPATH"].split( ";" ):
    print( path ) 

I get the following output:

[PythonInstallationPath]\Python\Python37\DLLs
[PythonInstallationPath]\Python37\lib
[PythonInstallationPath]\Python\Python37
[PythonInstallationPath]\Python\Python37\lib\site-packages
[PythonInstallationPath]\Python\Python37\lib\site-packages\win32
[PythonInstallationPath]\Python\Python37\lib\site-packages\win32\lib
[PythonInstallationPath]\Python\Python37\lib\site-packages\Pythonwin

When I add the path directly in the code, it works perfecty fine.

import sys
sys.path.append( [MyPath] )

But I would like to permanently add the path [MyPath] to the automatically imported folders. So, I went to the registry editor but I did not find the PYHTONPATH variable. The only entry I saw was in HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.7\PythonPath. Sadly, when I added the desired path to this registry entry, it did not change anything. The files at [MyPath] were still not recognized.

I read some stuff, that Python is adding some variables at its startup: Can't find my PYTHONPATH. This would explain, why I can not find PYTHONPATH inside the environment variables. But then, where do I have to mention [MyPath] so it is added to the variable at the Python startup?

The other solution could be to add the folder to my path variable. But like this, eclipse does not seem to recognize the imports. The code runs fine, but the IDE is showing an error.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Blackbriar
  • 477
  • 4
  • 14

0 Answers0