Jan-31-2021, 11:07 AM
(Jan-31-2021, 10:55 AM)Gribouillis Wrote: DO NOT USE PYTHONPATH. Instead do this:
You can add more directories to extend sys.path automatically this way. This is by far the most flexible way to do this. PYTHONPATH is a plague because if you install several python interpreters on your computer, it will apply to all of them and this is not what you want.
- Find the per user site-packages directory. For this, start python and run
>>> import site >>> site.getusersitepackages()On the computer where I'm writing this, it prints'/home/eric/.local/lib/python3.6/site-packages'
. This is the path to the directory
- In this directory, create a file named
usercustomize.py
. In this file add code
# usercustomize.py import sys sys.path.extend(['/home/pi/Code',])
Edit: Sorry, it is usercustomize and not sitecustomize. The latter also exists but it is usually stored in the global site-packages directory.
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?