Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  47] [ 0]  / answers: 1 / hits: 389931  / 2 Years ago, mon, february 7, 2022, 10:25:38

I have this in my ~/.profile:



export PYTHONPATH=/home/dev/python-files


In the python-files directory, I have a few projects cloned from git-hub (flask, curveship and py-vgdl).



Whenever I try to start up any of the examples in these projects, I get errors similar to the following:



$ python ~/python-files/py-vgdl/examples/gridphysics/frogs.py 
Traceback (most recent call last):
File "/home/dev/python-files/py-vgdl/examples/gridphysics/frogs.py", line 67, in <module>
from vgdl.core import VGDLParser
ImportError: No module named vgdl.core


It seems to me that I shouldn't get this error because I have that PYTHONPATH environmental variable set up?



Running the python interactive interpreter:



>>> import os
>>> os.environ["PYTHONPATH"]
'/home/dev/python-files'

More From » python

 Answers
3

Try appending to PYTHONPATH instead of overwriting it completely.



export PYTHONPATH=$PYTHONPATH:/home/dev/python-files


References:



According to the the Python documentation on PYTHONPATH




Augment the default search path for module files. [...]



The default search path is installation dependent, but generally begins with prefix/lib/pythonversion (see PYTHONHOME above). It is always appended to PYTHONPATH.




meaning that some values exist in PYTHONPATH and the default search path is also only appended.



Additionally, this blog post (Archive.org link) also explains clearly why you need to append to PYTHONPATH and not overwrite it. Scrolling down to the section - Special cases and examining the search path explains it clearly (unfortunately no relative URL to that link so you'll have to scroll). Although the user gives the examples on a mac they are very much relevant to any platform


[#32857] Tuesday, February 8, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pilun

Total Points: 270
Total Questions: 100
Total Answers: 94

Location: England
Member since Sat, Feb 13, 2021
3 Years ago
;