How to force Jupyter to use PYTHONPATH in system variables without hacking sys.path directly?

Same issue as sys.path in this other question in Jupyter and Python - how to import custom modules into Jupyter? . In pure Python, it adds the PYTHONPATH variable to the sys.path system variable, but the Jupyter laptop does not, so I cannot import my own module.

There are many similar questions asked on SO, and the solution is to directly manipulate sys.path in the script.

Can I use a Jupyter laptop to use my PYTHONPATH variable in a system, like in pure python?

+9
source share
2 answers

Jupyter uses its own environment variable JUPYTER_PATH .

+1
source

--Just called back here as the accepted answer did not give a complete solution--

You can add the path to your modules to the JUPYTER_PATH environment JUPYTER_PATH , just as you would change the PYTHONPATH environment variable:

 export JUPYTER_PATH="${JUPYTER_PATH}:/path/to/add/here/" 

If you are running on a Mac or other Unix system, just put the above line into your ~/.bash_profile

Hint: make sure you run source ~/.bash_profile to make changes and close and restart the Jupyter laptop.

0
source

All Articles