Here's what I found out: PYTHONPATH is the directory to add to the Python import search path "sys.path", which consists of the current directory. CWD, PYTHONPATH, a standard and shared library, as well as a client library. For example:
% python3 -c "import sys;print(sys.path)" ['', '/home/username/Documents/DjangoTutorial/mySite', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
where the first path '' denotes the current directory, the 2nd path through
%export PYTHONPATH=/home/username/Documents/DjangoTutorial/mySite
which can be added to ~ / .bashrc to make it permanent, and the rest are standard Python and a dynamic shared library , as well as third-party libraries like django.
As said, donโt mess with PYTHONHOME, even if you set it to '' or 'None', the python3 shell will stop working:
% export PYTHONHOME='' % python3 Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings' Current thread 0x00007f18a44ff740 (most recent call first): Aborted (core dumped)
Note that if you run the Python script, CWD will be the script directory. For example:
username@bud:~/Documents/DjangoTutorial% python3 mySite/manage.py runserver ==== Printing sys.path ==== /home/username/Documents/DjangoTutorial/mySite
You can also add the path to sys.path at runtime: Suppose you have a Fibonacci.py file in the ~ / Documents / Python directory:
username@bud:~/Documents/DjangoTutorial% python3 >>> sys.path.append("/home/username/Documents") >>> print(sys.path) ['', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/home/username/Documents'] >>> from Python import Fibonacci as fibo
or through
% PYTHONPATH=/home/username/Documents:$PYTHONPATH % python3 >>> print(sys.path) ['', '/home/username/Documents', '/home/username/Documents/DjangoTutorial/mySite', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages'] >>> from Python import Fibonacci as fibo