Add file to sys.path permanently - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Add file to sys.path permanently (/thread-32255.html) |
Add file to sys.path permanently - hcccs - Jan-30-2021 I'm running Python 3.7.3 and trying to add a library to sys.path. I can add it but it doesn't stick after next reload. I edited ~/.bashrc with the following: PYTHONPATH="${PYTHONPATH}:/home/pi/Code" export PYTHONPATH PYTHONPATH now contains just '/home/pi/Code'. I have added an empty file '__site__.py' to the library. Is there something missing? RE: Add file to sys.path permanently - Axel_Erfurt - Jan-31-2021 https://linuxize.com/post/how-to-add-directory-to-path-in-linux/ RE: Add file to sys.path permanently - Gribouillis - Jan-31-2021 DO NOT USE PYTHONPATH. Instead do this:
Edit: Sorry, it is usercustomize and not sitecustomize. The latter also exists but it is usually stored in the global site-packages directory. RE: Add file to sys.path permanently - hcccs - Jan-31-2021 (Jan-31-2021, 10:55 AM)Gribouillis Wrote: DO NOT USE PYTHONPATH. Instead do this: Gribouillis site.getusersitepackages() gives me /home/pi/.local/lib/python3.7/site-packages but when I go into Unix shell to create the usercustomize.py there is no directory 'lib' in '.local', just a 'share' directory. Should it be done in python shell? RE: Add file to sys.path permanently - Gribouillis - Jan-31-2021 I think you can create the directory by yourself if they don't exist. RE: Add file to sys.path permanently - hcccs - Jan-31-2021 (Jan-31-2021, 11:10 AM)Gribouillis Wrote: I think you can create the directory by yourself if they don't exist. I did and removed the contents of PYTHONPATH and reloading the sys.path contains my library. The strange thing is I've been searching the web for hours and got different ideas how to implement this and they were obviously all wrong. Thanks! |