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

Answer from Nitin Venkatesh on askubuntu.com
Top answer
1 of 3
73
  1. PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. e.g.:

    # make python look in the foo subdirectory of your home directory for   
    # modules and packages 
    export PYTHONPATH=${PYTHONPATH}:${HOME}/foo 
    

    Here I use the sh syntax. For other shells (e.g. csh,tcsh), the syntax would be slightly different. To make it permanent, set the variable in your shell's init file (usually ~/.bashrc).

  2. Ubuntu comes with python already installed. There may be reasons for installing other (independent) python versions, but I've found that to be rarely necessary.

  3. The folder where your modules live is dependent on PYTHONPATH and where the directories were set up when python was installed. For the most part, the installed stuff you shouldn't care about where it lives -- Python knows where it is and it can find the modules. Sort of like issuing the command ls -- where does ls live? /usr/bin? /bin? 99% of the time, you don't need to care -- Just use ls and be happy that it lives somewhere on your PATH so the shell can find it.

  4. I'm not sure I understand the question. 3rd party modules usually come with install instructions. If you follow the instructions, python should be able to find the module and you shouldn't have to care about where it got installed.

  5. Configure PYTHONPATH to include the directory where your module resides and python will be able to find your module.

2 of 3
46
  1. PYTHONPATH is an environment variable
  2. Yes (see https://unix.stackexchange.com/questions/24802/on-which-unix-distributions-is-python-installed-as-part-of-the-default-install)
  3. /usr/lib/python2.7 on Ubuntu
  4. you shouldn't install packages manually. Instead, use pip. When a package isn't in pip, it usually has a setuptools setup script which will install the package into the proper location (see point 3).
  5. if you use pip or setuptools, then you don't need to set PYTHONPATH explicitly

If you look at the instructions for pyopengl, you'll see that they are consistent with points 4 and 5.

Discussions

ubuntu - How to set up Python path? - Unix & Linux Stack Exchange
PYTHONPATH=/usr/lib/my_python_distribution export PYTHON ... root1@master:/usr/lib/python2.7$ echo $PATH /home/root1/anaconda3/bin:/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8... More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 31, 2015
python - Permanently add a directory to PYTHONPATH? - Stack Overflow
On linux you can create a symbolic link from your package to a directory of the PYTHONPATH without having to deal with the environment variables. Something like: ... For me it worked when I changed the .bash_profile file. Just changing .bashrc file worked only till I restarted the shell. ... export ... More on stackoverflow.com
🌐 stackoverflow.com
What does PYTHONPATH=. do?
It sets the path where Python looks for modules to the current directory or the directory one level above current. Why are you running those commands? More on reddit.com
🌐 r/learnpython
7
2
January 20, 2017
PYTHONPATH not being used in Windows Subsystem for Linux Ubuntu
PYTHONPATH is not defined in ~/.bashrc or ~/.bash_profile, as seen by the subsystem for Linux. If you export PYTHONPATH=... in one of these files, as seen by the subsystem for Linux, do the paths show up in PYTHONPATH Manager? More on github.com
🌐 github.com
December 19, 2023
People also ask

Is PYTHONPATH required to import installed packages?
Python adds applicable package locations through its normal initialization. If an installed package cannot be imported, identify the active interpreter before adding extra paths.
🌐
askpython.com
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
How do I set multiple directories in PYTHONPATH?
Join directory paths with the operating system’s separator. It is a colon on Linux and macOS and a semicolon on Windows, and os.pathsep reports the appropriate character.
🌐
askpython.com
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
How do I add PYTHONPATH inside a Python script?
Changing os.environ["PYTHONPATH"] changes the process environment and can affect child processes started afterwards. For an import in the running interpreter, add the intended directory to sys.path before importing, or install the package into that interpreter’s environment.
🌐
askpython.com
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
Top answer
1 of 4
5

I'm assuming that when you installed anaconda 2, you manually set the PYTHONPATH environment variable, by putting something like

PYTHONPATH=/home/user/anaconda2/python
export PYTHONPATH

in your .bash_profile or .bash_rc.

But since you deleted the /home/user/anacanda2/ directory, that path no longer exists.

Thus you want to change PYTHONPATH to point to the executable in /usr/lib, by changing the above to

PYTHONPATH=/usr/lib/my_python_distribution
export PYTHON
2 of 4
3
  1. execute the command: echo $PATH

    root1@master:/usr/lib/python2.7$ echo $PATH
    /home/root1/anaconda3/bin:/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/bin
    
  2. Remove your anaconda3 from your path variable that is

    /home/root1/anaconda3/bin:
    
  3. Again set PATH variable with remaining information like below

    export PATH=/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/bin
    
  4. Execute python command and should redirect to your python interpreter

    root1@master:/usr/lib/python2.7$ python
    Python 2.7.14 (default, Sep 18 2017, 00:00:00) 
    [GCC 4.8.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    
🌐
GitHub
bic-berkeley.github.io › psych-214-fall-2016 › using_pythonpath.html
Using PYTHONPATH — Functional MRI methods
$ # Set PYTHONPATH to path to the working directory + /code $ # This is for the "bash" shell on Unix / git bash on Windows $ export PYTHONPATH="$PWD/code" $ # Now the script can find "a_module" $ python3 scripts/a_script.py Running useful function
Find elsewhere
🌐
AskPython
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
4 weeks ago - You do not need to copy Python’s standard-library or site-packages directories into PYTHONPATH. In Bash on Linux or macOS, print the variable with printf, keeping its value together through quoting and accepting an unset variable through parameter expansion.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-set-your-python-path-on-linux
How to set your python path on Linux?
March 24, 2026 - # Add to ~/.bashrc or ~/.zshrc echo 'export PYTHONPATH=${PYTHONPATH}:${HOME}/mymodules' >> ~/.bashrc source ~/.bashrc
🌐
Reddit
reddit.com › r/learnpython › what does pythonpath=. do?
r/learnpython on Reddit: What does PYTHONPATH=. do?
January 20, 2017 -

I've often times run these commands blindly: export PYTHONPATH=. or PYTHONPATH=.. but I don't understand what they're doing...?

Top answer
1 of 2
2
It sets the path where Python looks for modules to the current directory or the directory one level above current. Why are you running those commands?
2 of 2
1
export creates or changes an environment variable for the current session in your operating system. ctrl-f for that particular one here to see what it means/does/is: https://docs.python.org/3/using/cmdline.html "." and ".." are coming from the relative path tradition. "." means "current directory" and ".." means parent directory (of the current directory). There is also "~" (for linux) which means "home directory" (which expands to "/home/your_user_name"). You can find more information about that here: https://en.wikipedia.org/wiki/Path_(computing)#Absolute_and_relative_paths You should not need to set these yourself, in almost all cases. I would look into how pip and virtualenv are used. The former installs libraries where python would expect to find them. I usually use it as python -m pip install some_library The latter creates a virtual environment (inside a folder) and puts basic libraries in it. virtualenv venv/ # create the venv directory in the current directory and copy over basic python stuff, for linux virtual venv\ # same as above if using Windows source venv/bin/activate # for linux, activate that virtual environment venv\Scripts\activate.bin # same as above if using Windows which python # in linux, check where your default python is; first executable listed should be the one inside venv/ or something is wrong where python # same as above, if using windows python -m pip install some_library # installs library inside that virtual environment/directory pip freeze > requirements.txt # records which libraries are installed; would in turn be used to install those libraries in another system/computer your_favorite_ide your_code.py # start editing your code using your virtual environment (if you're using Emacs, look into Elpy instead of this part; other IDEs also have their own way of configuring where the virtual environment is)
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 485410 › python-path-linux
python path Linux [SOLVED] | DaniWeb
The easiest, safest way to make your private library directory available without replacing Python’s defaults is to append that directory to PYTHONPATH in a shell startup file so it persists. Put the export line into the appropriate file for your session (interactive shells use ~/.bashrc, login/GUI sessions often read ~/.profile or ~/.bash_profile) and restart or source that file.
🌐
GitHub
github.com › spyder-ide › spyder › issues › 21633
PYTHONPATH not being used in Windows Subsystem for Linux Ubuntu · Issue #21633 · spyder-ide/spyder
December 19, 2023 - $ pip install foo --prefix=/opt/foo $ export PYTHONPATH=/opt/foo/lib/python3.8/site-packages:$PYTHONPATH · @PAGWatson Is it something similar for you? What is the content of your PYTHONPATH? ... Hi there - I was using RHEL8 Linux at the time and set PYTHONPATH in the .bashrc.
🌐
Redreamality
redreamality.com › blog › pythonpathvs-code
How to Set PYTHONPATH on Windows, Linux, macOS and VS Code
August 21, 2025 - On Unix-like systems (such as macOS and Linux), setting environment variables is similar and typically involves modifying the shell configuration files. The path separator is a colon (:). This setting is only valid for the current terminal session. ... To make PYTHONPATH available every time you open a new terminal, you need to add it to your shell configuration file.
🌐
Amazonaws
bebi103.caltech.edu.s3-website-us-east-1.amazonaws.com › 2014 › handouts › ho2_setting_pythonpath.html
Setting your PYTHONPATH environment variable
If you are using Linux, you should launch Canopy from the command line. To set your PYTHONPATH, either edit your ~/.profile file or the appropriate rc file for the shell you are using. Here ~/ is an abbreviation for your home directory. In my case, I would add the following line to my ~/.profile ...
🌐
Urban Fresh Produce
urbanfreshproduce.ca › post › export-pythonpath
export pythonpath
December 17, 2024 - Always remember to replace /path/to/your/modules with the actual path to your modules or packages. On Linux and macOS systems, you typically use the export command in your shell (Bash, Zsh, etc.):
🌐
IT trip
en.ittrip.xyz › python
Setting and Using the PYTHONPATH Environment Variable: A Guide for Project Utilization | IT trip
December 3, 2024 - After activating the virtual environment, run the following to set PYTHONPATH: Linux/Mac: export PYTHONPATH=/path/to/your/directory:$PYTHONPATH
🌐
Uchicago
geosci.uchicago.edu › ~rtp1 › PrinciplesPlanetaryClimate › Python › ShellsNStuff.html
About Shells, Paths and Environment Variables
On Linux and Mac OSX systems, the business of telling Python where to look for modules is handled by setting the PYTHONPATH environment variable, which lists the directories Python should look in (besides the default ones) when a script imports a module. Get ready for some truly geeky stuff ...
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.

🌐
Net Informations
net-informations.com › python › intro › path.htm
How to set python path
bash shell (Linux): type export ATH="$PATH:/usr/local/bin/python" and press Enter. sh or ksh shell: type PATH="$PATH:/usr/local/bin/python" and press Enter. /usr/local/bin/python is the default path of the Python directory. PYTHONPATH functions as an environment variable that enables the inclusion ...
🌐
LinuxVox
linuxvox.com › blog › python-path-linux
Mastering Python Paths on Linux — linuxvox.com
You can do this temporarily for the current shell session or permanently by adding it to your shell profile. export PYTHONPATH=/path/to/your/modules:$PYTHONPATH python your_script.py
🌐
Real Python
realpython.com › add-python-to-path
How to Add Python to PATH – Real Python
July 23, 2026 - This command adds export PATH="<PATH_TO_PYTHON>:$PATH" to the end of .profile. The command export PATH="<PATH_TO_PYTHON>:$PATH" prepends <PATH_TO_PYTHON> to the PATH environment variable.