Reputation: 9865
I'm able to import modules in my jupyter notebook as follows:
import sys
sys.path.append('path/to/library')
But I want to edit the files that jupyter notebook runs upon startup, so that I don't have to add a path for every single library.
How do I modify the path that jupyter notebook uses?
I tried modifying PATH
but that didn't seem to work. I did export PATH=path/to/library:$PATH
. And then I restarted the jupyter notebook but that didn't solve it.
How do I modify the path that jupyter notebook uses when it starts?
EDIT
The libraries that I'm unable to load are not modules that I've created - they are things like numpy
and scipy
. I know where these libraries are in my system: numpy
is at /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
and scipy
for some reason is at a different location /Library/Python/2.7/site-packages
. But I'm not able to import these when I boot up jupyter notebook, yet I can launch python in the terminal, and do import scipy
or import numpy
perfectly fine.
So, I assume that when I launch python
from the terminal, it is using the correct environmental variable PATH
. However, when I launch jupyter notebook it is NOT able to do import scipy
or import numpy
. So, I assume it is NOt using the correct environmental variable PATH
.
How do I modify the latter so that it is like the former?
Upvotes: 0
Views: 1738
Reputation: 6281
You could use the PYTHONPATH environment variable to set the path used to locate modules, or the PYTHONSTARTUP environment variable to run the code appending to sys.path
.
Upvotes: 1
Reputation: 2159
You could use os.chdir.OS module in Python provides functions for interacting with the operating system. OS, comes under Python’s standard utility modules.
import os
os.chdir(r"path/to/library")
Upvotes: 1