The environment variable PYTHONPATH is actually only added to the list of locations Python searches for modules. You can print out the full list in the terminal like this:

python -c "import sys; print(sys.path)"

Or if want the output in the UNIX directory list style (separated by :) you can do this:

python -c "import sys; print(':'.join(x for x in sys.path if x))"

Which will output something like this:

/usr/local/lib/python2.7/dist-packages/feedparser-5.1.3-py2.7.egg:/usr/local/lib/
python2.7/dist-packages/stripogram-1.5-py2.7.egg:/home/qiime/lib:/home/debian:/us
r/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib
/python2.7/lib-old:/usr/lib/python2.7/lib- dynload:/usr/local/lib/python2.7/dist-
packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages/PIL:/u
sr/lib/python2.7/dist-packages/gst-0.10:/usr/lib/python2.7/dist-packages/gtk-2.0:
/usr/lib/pymodules/python2.7
Answer from Hubro on Stack Overflow
๐ŸŒ
Ask Ubuntu
askubuntu.com โ€บ questions โ€บ 941919 โ€บ which-python-and-echo-pythonpath-give-different-directories-what-does-this
16.04 - 'which python' and 'echo PYTHONPATH' give different directories, what does this mean? - Ask Ubuntu
August 1, 2017 - Stack Exchange network consists ... Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I'm using Ubuntu 16.04 with python 2.7. I'm trying to run python from a directory other than the one given by ... into my bashrc file. Now, which python returns /usr/bin/python and echo PYTHONPATH returns ...
๐ŸŒ
Super User
superuser.com โ€บ questions โ€บ 917675 โ€บ pythonpath-variable-cant-be-echoed-by-non-root
linux - PYTHONPATH variable can't be echoed by non-root - Super User
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I added Defaults env_keep += "PYTHONPATH" to the sudoers file. Then from root, I echoed PYTHONPATH as echo $PYTHONPATH and it echoed successfully.
Top answer
1 of 1
2

I'm running Mint 19.3 and kernel version 4.15.0-106-generic - so not far off from you.

(python3-venv) me@mycomp:chap10-Batteries_Included$ cat/etc/*release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=19.3
DISTRIB_CODENAME=tricia
DISTRIB_DESCRIPTION="Linux Mint 19.3 Tricia"
...
(python3-venv) me@mycomp:chap10-Batteries_Included$ uname -r
4.15.0-106-generic

running in a Python 3 virtual environment. I'm working on "Beginning Python, From Novice to Professional" by Magnus Lie Hetland and got to Chapter 10 where it talks about this very thing. When I first get into my shell, I find nothing assigned to $PYTHONPATH either:

(python3-venv) me@mycomp:chap10-Batteries_Included$ echo $PYTHONPATH
 
(python3-venv) me@mycomp:chap10-Batteries_Included$

So I do what is suggested everywhere on the web, and in the book($PWD being my working directory, which happened to be the directory I wanted added):

(python3-venv) me@mycomp:chap10-Batteries_Included$ export PYTHONPATH=$PYTHONPATH:$PWD
(python3-venv) me@mycomp:chap10-Batteries_Included$ echo $PYTHONPATH
:/home/me/Documents/CodingProjects/python/Beginning-Python/book/chap10-Batteries_Included
(python3-venv) me@mycomp:chap10-Batteries_Included$

And there we go, it's there:

(python3-venv) me@mycomp:chap10-Batteries_Included$ python -O
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, pprint
>>> pprint.pprint(sys.path)
['',
 '/home/me/Documents/CodingProjects/python/Beginning-Python/book/chap10-Batteries_Included',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/home/me/python3-venv/lib/python3.6/site-packages']
>>> 

I noticed, and would have commented had I been able to without having 50 points on here, that you have export export PYTHONPATH=$PYTHONPATH:.... - you only need export once. You can add this export PYTHONPATH=... to your ~/.profile to make it permanent, too. I hope this helps.

Find elsewhere
Top answer
1 of 2
3

Module search path:

  • First it searches for a built-in module
  • Next it searches for the module in a list of directories given by sys.path, which is initialized from these locations:

    • The directory containing the input script (or current directory)
    • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH)
    • The installation-dependent default

How to alter sys.path:

  • sys.path.insert(_number_, '/whateverfilepath/')
  • Use 1 instead of 0 for number so that Python will look in the current working directory first
2 of 2
1

You're just seeing your current working directory plus the path defaults from your site (Anaconda) installation. From the docs:

sys.path: A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.

As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.

A program is free to modify this list for its own purposes.

Changed in version 2.3: Unicode strings are no longer ignored.

See also Module site This describes how to use .pth files to extend sys.path.

๐ŸŒ
Linux Mint Forums
forums.linuxmint.com โ€บ board index โ€บ main edition support โ€บ beginner questions
no $PYTHONPATH environment variable? - Linux Mint Forums
September 4, 2013 - Add the line "PYTHONPATH=/usr/bin/python" to the file (don't use quotes). Save, logout, login again and it will be there. One other thing, you can add "#!/usr/bin/python" (don't use quotes) to the top line of any file if you want it to execute using python. ... I did as instructed and "echo ...
๐ŸŒ
Ask Ubuntu
askubuntu.com โ€บ questions โ€บ 1472071 โ€บ where-is-pythonpath-added
command line - Where is PYTHONPATH added? - Ask Ubuntu
June 12, 2023 - when I checked the PYTHONPATH with echo $PYTHONPATH the results is so complicated. I want to remove some lines. However, it s not in the bashrc,profile or enviroment file. Is there any way to fix ...