Skip to content

Instantly share code, notes, and snippets.

@yasushisakai
Last active April 21, 2017 15:26
Show Gist options
  • Save yasushisakai/86da64df10581d37af709387f45f9312 to your computer and use it in GitHub Desktop.
Save yasushisakai/86da64df10581d37af709387f45f9312 to your computer and use it in GitHub Desktop.
different Jupyter python path (installed by anaconda)

if jupyter notebook has different paths that python has.... causing No module named ** when you are sure its there in python

how to check

do this in both python and jupyter

import sys
print(sys.path)

and compare the paths. you might want to copy and paste the result from the terminal and do the following

import sys
python_path = [] #list copy and pasted from terminal

for p in sys.path:
  if p not in python_path:
    print p

how to add path to jupyter's sys.path

in terminal do

jupyter notebook --generate-config

go to the path and open jupyter_notebook_config.py, in my case /Users/username/.jupyter/ add following line

c.InteractiveShellApp.exec_lines=[
'import sys; sys.path.append("path-to-add")'
]
@seojey79
Copy link

seojey79 commented Aug 8, 2016

Thanks, but not working...
I think.. this option is just for ipython.
What can I do for this problem ?

@ffeast
Copy link

ffeast commented Nov 11, 2016

It won't work unfortunately

@justinanderson
Copy link

Jupyter itself is language agnostic, so you need to add InteractiveShellApp options to iPython's kernel config file.

ipython profile create
echo "c.InteractiveShellApp.exec_lines=[
    'import sys; sys.path.append(\"path/to/add\")'
]" >> ~/.ipython/profile_default/ipython_kernel_config.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment