New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import installed libraries #397

Closed
rsmith31415 opened this Issue Sep 5, 2015 · 48 comments

Comments

Projects
None yet
@rsmith31415
Contributor

rsmith31415 commented Sep 5, 2015

In a new conda environment, I run conda install ipython-notebook and then conda install matplotlib. I launch the notebook using jupyter notebook as usual and everything looks okay. However, when I'm trying to import matplotlib (import matplotlib.pyplot as plt or simply import matplotlib) I get ImportError: No module named matplotlib.pyplot and an error in the terminal:

[IPKernelApp] ERROR | No such comm target registered: ipython.widget

The same happens when I install pandas. What did I do wrong? Running conda list shows that both packages are installed in the current environment.

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Sep 5, 2015

Member

Is sys.executable what you expect?

Member

minrk commented Sep 5, 2015

Is sys.executable what you expect?

@rsmith31415

This comment has been minimized.

Show comment
Hide comment
@rsmith31415

rsmith31415 Sep 5, 2015

Contributor
In [2]: sys.executable
Out[2]: '/home/user/anaconda/envs/jupyter-notebook/bin/python'

That looks okay. I forgot to add that matplotlib and pandas are working from the ipython console, but the qtconsole and the notebook are having this same issue.

UPDATE:

I tried that in the console, which is giving the correct environment. However, running the same in the notebook actually gives the wrong environment. Why? The other environment is not active right now and doesn't have matplotlib or pandas listed as installed.

Contributor

rsmith31415 commented Sep 5, 2015

In [2]: sys.executable
Out[2]: '/home/user/anaconda/envs/jupyter-notebook/bin/python'

That looks okay. I forgot to add that matplotlib and pandas are working from the ipython console, but the qtconsole and the notebook are having this same issue.

UPDATE:

I tried that in the console, which is giving the correct environment. However, running the same in the notebook actually gives the wrong environment. Why? The other environment is not active right now and doesn't have matplotlib or pandas listed as installed.

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Sep 5, 2015

Member

And sys.executable is the same in IPython when matplotlib is working?

Member

minrk commented Sep 5, 2015

And sys.executable is the same in IPython when matplotlib is working?

@juhasch

This comment has been minimized.

Show comment
Hide comment
@juhasch

juhasch Sep 5, 2015

Contributor

Take a look at your kernelspec. The path for calling python will probably point to the wrong environment.

Contributor

juhasch commented Sep 5, 2015

Take a look at your kernelspec. The path for calling python will probably point to the wrong environment.

@rsmith31415

This comment has been minimized.

Show comment
Hide comment
@rsmith31415

rsmith31415 Sep 5, 2015

Contributor

@minrk When I run sys.executable in IPython outside of the jupyter-notebook environment, it gives /home/user/anaconda/bin/python and inside the other environment also gives the correct output. I just restarted and created a new environment but the problem persists.

@juhasch Certainly points to the wrong environment. The interesting thing is that I don't have the jupyter notebook installed in the other environment. I installed jupyter_client there, though.

Contributor

rsmith31415 commented Sep 5, 2015

@minrk When I run sys.executable in IPython outside of the jupyter-notebook environment, it gives /home/user/anaconda/bin/python and inside the other environment also gives the correct output. I just restarted and created a new environment but the problem persists.

@juhasch Certainly points to the wrong environment. The interesting thing is that I don't have the jupyter notebook installed in the other environment. I installed jupyter_client there, though.

@rsmith31415

This comment has been minimized.

Show comment
Hide comment
@rsmith31415

rsmith31415 Sep 5, 2015

Contributor

Uhm... where is located the kernel for IPython? ~/.jupyter only shows "migrated" and ~/.ipython shows kernels for R and Julia.

Contributor

rsmith31415 commented Sep 5, 2015

Uhm... where is located the kernel for IPython? ~/.jupyter only shows "migrated" and ~/.ipython shows kernels for R and Julia.

@juhasch

This comment has been minimized.

Show comment
Hide comment
@juhasch

juhasch Sep 5, 2015

Contributor

The location of the kernel spec depends on your system. Should be in one of these:

from jupyter_core.paths import jupyter_data_dir
print(jupyter_data_dir())

I am sure @minrk can explain this better.

Contributor

juhasch commented Sep 5, 2015

The location of the kernel spec depends on your system. Should be in one of these:

from jupyter_core.paths import jupyter_data_dir
print(jupyter_data_dir())

I am sure @minrk can explain this better.

@rsmith31415

This comment has been minimized.

Show comment
Hide comment
@rsmith31415

rsmith31415 Sep 5, 2015

Contributor

Yes, that explains it. I have this:

{
"display_name": "Python 2",
"language": "python",
"argv": [
"/home/user/anaconda/envs/other-environment/bin/python",
"-m",
"ipykernel",
"-f",
"{connection_file}"
]
}

Is there some way to share the kernel to be used in both environments?

Contributor

rsmith31415 commented Sep 5, 2015

Yes, that explains it. I have this:

{
"display_name": "Python 2",
"language": "python",
"argv": [
"/home/user/anaconda/envs/other-environment/bin/python",
"-m",
"ipykernel",
"-f",
"{connection_file}"
]
}

Is there some way to share the kernel to be used in both environments?

@juhasch

This comment has been minimized.

Show comment
Hide comment
@juhasch

juhasch Sep 5, 2015

Contributor

I changed my kernel spec to just python without the absolute path.

Contributor

juhasch commented Sep 5, 2015

I changed my kernel spec to just python without the absolute path.

@rsmith31415

This comment has been minimized.

Show comment
Hide comment
@rsmith31415

rsmith31415 Sep 5, 2015

Contributor

That works great! Thank you.

What was the cause of using a particular environment in the kernels.json file? Is that standard behavior?

Contributor

rsmith31415 commented Sep 5, 2015

That works great! Thank you.

What was the cause of using a particular environment in the kernels.json file? Is that standard behavior?

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Sep 8, 2015

Member

The full path of sys.executable of the Python used to install the kernel is written to kernel.json by default.

Member

minrk commented Sep 8, 2015

The full path of sys.executable of the Python used to install the kernel is written to kernel.json by default.

@rsmith31415

This comment has been minimized.

Show comment
Hide comment
@rsmith31415

rsmith31415 Sep 8, 2015

Contributor

Oh, okay. In any case, @juhasch's solution is working perfectly.

Contributor

rsmith31415 commented Sep 8, 2015

Oh, okay. In any case, @juhasch's solution is working perfectly.

@resurgo

This comment has been minimized.

Show comment
Hide comment
@resurgo

resurgo Jun 30, 2016

I had this problem - it was due to /usr/local/bin/jupyter-kernelspec being read first by Jupyter before /opt/conda/bin/jupyter-kernelspec when /opt/conda/bin/jupyter had been run.. There is a path bug here.

Removing the previous install solved the problem.

resurgo commented Jun 30, 2016

I had this problem - it was due to /usr/local/bin/jupyter-kernelspec being read first by Jupyter before /opt/conda/bin/jupyter-kernelspec when /opt/conda/bin/jupyter had been run.. There is a path bug here.

Removing the previous install solved the problem.

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Jun 30, 2016

Member

If /usr/local/bin is before /opt/conda/bin on your PATH, I think that's expected behaviour.

If the directory where jupyter exists is not on PATH, we add it, but we don't currently do anything to prioritise that location over the rest of PATH. Maybe we should - I can see arguments both ways. @minrk ?

Member

takluyver commented Jun 30, 2016

If /usr/local/bin is before /opt/conda/bin on your PATH, I think that's expected behaviour.

If the directory where jupyter exists is not on PATH, we add it, but we don't currently do anything to prioritise that location over the rest of PATH. Maybe we should - I can see arguments both ways. @minrk ?

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Jun 30, 2016

Member

I might prefer the current behavior, that jupyter kernelspec always behaves the same as jupyter-kernelspec, which it would not if we forced the jupyter dir to the head of the PATH. Rather than what we do now, which is adding it to the end in the unlikely event that it wasn't already present.

But I don't feel strongly about it. We could give the reverse priority a try if we want to enforce that /path/to/jupyter kernelspec is identical to /path/to/jupyter-kernelspec. I don't see a good way to accomplish what @resurgo is trying to do without that. At the same time, using PATH to override/wrap commands would not be possible if we made that change. I'm not sure if that's something we want/need to allow, though.

Member

minrk commented Jun 30, 2016

I might prefer the current behavior, that jupyter kernelspec always behaves the same as jupyter-kernelspec, which it would not if we forced the jupyter dir to the head of the PATH. Rather than what we do now, which is adding it to the end in the unlikely event that it wasn't already present.

But I don't feel strongly about it. We could give the reverse priority a try if we want to enforce that /path/to/jupyter kernelspec is identical to /path/to/jupyter-kernelspec. I don't see a good way to accomplish what @resurgo is trying to do without that. At the same time, using PATH to override/wrap commands would not be possible if we made that change. I'm not sure if that's something we want/need to allow, though.

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Jun 30, 2016

Member

jupyter/jupyter_core#79 implements the described priority, if that's the way we want to go.

Member

minrk commented Jun 30, 2016

jupyter/jupyter_core#79 implements the described priority, if that's the way we want to go.

@eldad-a

This comment has been minimized.

Show comment
Hide comment
@eldad-a

eldad-a Sep 7, 2016

@resurgo +1

I had this problem - it was due to /usr/local/bin/jupyter-kernelspec being read first by Jupyter before /opt/conda/bin/jupyter-kernelspec when /opt/conda/bin/jupyter had been run.. There is a path bug here.
Removing the previous install solved the problem.

Many thanks!

eldad-a commented Sep 7, 2016

@resurgo +1

I had this problem - it was due to /usr/local/bin/jupyter-kernelspec being read first by Jupyter before /opt/conda/bin/jupyter-kernelspec when /opt/conda/bin/jupyter had been run.. There is a path bug here.
Removing the previous install solved the problem.

Many thanks!

@rylanchiu

This comment has been minimized.

Show comment
Hide comment
@rylanchiu

rylanchiu Feb 2, 2017

thanks for your answer @resurgo . But what do you mean by "Removing the previous install"? Should I remove /usr/local/bin/jupyter-kernelspec directly? But I have tried it and it doesn't solve my problem. Do you have any idea? Thanks!

rylanchiu commented Feb 2, 2017

thanks for your answer @resurgo . But what do you mean by "Removing the previous install"? Should I remove /usr/local/bin/jupyter-kernelspec directly? But I have tried it and it doesn't solve my problem. Do you have any idea? Thanks!

@wjlu

This comment has been minimized.

Show comment
Hide comment
@wjlu

wjlu Feb 8, 2017

my environment is mac and python3
i also on jupyter can not import matplotlib

on jupyter run sys.executable is '/Library/Frameworks/Python.framework/Versions/3.5/bin/python3'
on terminal run sys.executable is '/Users/abc/anaconda/bin/python3'

so what can i do to solve the problem ?

and just rm jupyter-kernelspec seemed can not work

wjlu commented Feb 8, 2017

my environment is mac and python3
i also on jupyter can not import matplotlib

on jupyter run sys.executable is '/Library/Frameworks/Python.framework/Versions/3.5/bin/python3'
on terminal run sys.executable is '/Users/abc/anaconda/bin/python3'

so what can i do to solve the problem ?

and just rm jupyter-kernelspec seemed can not work

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Feb 8, 2017

Member

If there's an old install of Jupyter/IPython/ipykernel on your system, try to get rid of that.

Removing the jupyter-kernelspec script is usually not the right thing to do; you probably want to run jupyter kernelspec list to see where it's finding kernels, and then install/remove kernelspecs to arrive at the situation you want.

Member

takluyver commented Feb 8, 2017

If there's an old install of Jupyter/IPython/ipykernel on your system, try to get rid of that.

Removing the jupyter-kernelspec script is usually not the right thing to do; you probably want to run jupyter kernelspec list to see where it's finding kernels, and then install/remove kernelspecs to arrive at the situation you want.

@rylanchiu

This comment has been minimized.

Show comment
Hide comment
@rylanchiu

rylanchiu Feb 19, 2017

@takluyver Can you explain how to install kernelspecs?

rylanchiu commented Feb 19, 2017

@takluyver Can you explain how to install kernelspecs?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Feb 20, 2017

Member

In general it's up to the kernel to provide a convenient way to install it. For instance, here are the instructions for the IPython kernel:
http://ipython.readthedocs.io/en/stable/install/kernel_install.html

Member

takluyver commented Feb 20, 2017

In general it's up to the kernel to provide a convenient way to install it. For instance, here are the instructions for the IPython kernel:
http://ipython.readthedocs.io/en/stable/install/kernel_install.html

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 May 9, 2017

I am having a similar problem, after installing Anaconda (for Python3, Jupyter, Numpy, Pandas etc.)
(Mac OS Sierra 10.12.4)
Numpy & Pandas are fine if I call to import them in a *.py file and run from the terminal. But if called from within a Jupyter notebook I get:
ImportError: No module named numpy
Following advice in threads on similar issues, I have tried:
from sys import executable print(executable)
in both Jupyter notebook and from a Python interpreter prompt in bash.
In Jupyter notebook I get:
/Users/Chris/anaconda3/envs/ipykernel_py3/bin/python
(or py2 for Python 2 kernel), BUT in the Python interpreter I get:
/Users/Chris/anaconda3/bin/python3
As far as I understand the thread above - this is likely the problem.
How should I fix it? (as a relative newcomer)?
Thanks

chrisrb10 commented May 9, 2017

I am having a similar problem, after installing Anaconda (for Python3, Jupyter, Numpy, Pandas etc.)
(Mac OS Sierra 10.12.4)
Numpy & Pandas are fine if I call to import them in a *.py file and run from the terminal. But if called from within a Jupyter notebook I get:
ImportError: No module named numpy
Following advice in threads on similar issues, I have tried:
from sys import executable print(executable)
in both Jupyter notebook and from a Python interpreter prompt in bash.
In Jupyter notebook I get:
/Users/Chris/anaconda3/envs/ipykernel_py3/bin/python
(or py2 for Python 2 kernel), BUT in the Python interpreter I get:
/Users/Chris/anaconda3/bin/python3
As far as I understand the thread above - this is likely the problem.
How should I fix it? (as a relative newcomer)?
Thanks

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver May 9, 2017

Member

The easiest way is probably to install those packages into the environment you're using, e.g.

source activate ipykernel_py3
conda install numpy pandas
# Add any other packages you want
Member

takluyver commented May 9, 2017

The easiest way is probably to install those packages into the environment you're using, e.g.

source activate ipykernel_py3
conda install numpy pandas
# Add any other packages you want
@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 May 9, 2017

That seems to work - thank you. (A very BIG thank you - this has been bugging me for hours).
But there seems odd about this - wouldn't it be better (/ correct?) to have Jupyter notebook and the bash interpreter pointing at the same environments?

chrisrb10 commented May 9, 2017

That seems to work - thank you. (A very BIG thank you - this has been bugging me for hours).
But there seems odd about this - wouldn't it be better (/ correct?) to have Jupyter notebook and the bash interpreter pointing at the same environments?

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 May 9, 2017

It also doesn't seem to work for BeautifulSoup4.
I have run:
conda install beautifulsoup4 from within the ipkernel_py3 environment that notebook is using.
But if I try to call from that library in the notebook:
from beautifulsoup4 import *
the it returns a module not found error.
I am a novice - but it would seem 'neater' (and less error prone) to get the notebook pointing at the same Python 2 and Python 3 environments as the bash interpreter. How should I do this? Thanks

chrisrb10 commented May 9, 2017

It also doesn't seem to work for BeautifulSoup4.
I have run:
conda install beautifulsoup4 from within the ipkernel_py3 environment that notebook is using.
But if I try to call from that library in the notebook:
from beautifulsoup4 import *
the it returns a module not found error.
I am a novice - but it would seem 'neater' (and less error prone) to get the notebook pointing at the same Python 2 and Python 3 environments as the bash interpreter. How should I do this? Thanks

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 May 9, 2017

related to this issue - I am also regularly seeing the message:
[IPKernelApp] ERROR | No such comm target registered: jupyter.widget.version
appearing in the message stream in the terminal window where I starter jupyter notebook.
I am guessing this is related?

chrisrb10 commented May 9, 2017

related to this issue - I am also regularly seeing the message:
[IPKernelApp] ERROR | No such comm target registered: jupyter.widget.version
appearing in the message stream in the terminal window where I starter jupyter notebook.
I am guessing this is related?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver May 9, 2017

Member

But if I try to call from that library in the notebook:
from beautifulsoup4 import *

The import name doesn't necessarily match the install name - with that hint, I'll let you look at the docs. 😉

I am a novice - but it would seem 'neater' (and less error prone) to get the notebook pointing at the same Python 2 and Python 3 environments as the bash interpreter. How should I do this? Thanks

Yep, that's probably neater. Run jupyter kernelspec list to see what kernel information it has recorded. If you don't have a python3 kernelspec it will run Python from the environment you launch Jupyter in. More info here: http://ipython.readthedocs.io/en/stable/install/kernel_install.html

(I'm planning to rethink the kernelspec system, because it's become more confusing than we had hoped)

Member

takluyver commented May 9, 2017

But if I try to call from that library in the notebook:
from beautifulsoup4 import *

The import name doesn't necessarily match the install name - with that hint, I'll let you look at the docs. 😉

I am a novice - but it would seem 'neater' (and less error prone) to get the notebook pointing at the same Python 2 and Python 3 environments as the bash interpreter. How should I do this? Thanks

Yep, that's probably neater. Run jupyter kernelspec list to see what kernel information it has recorded. If you don't have a python3 kernelspec it will run Python from the environment you launch Jupyter in. More info here: http://ipython.readthedocs.io/en/stable/install/kernel_install.html

(I'm planning to rethink the kernelspec system, because it's become more confusing than we had hoped)

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 May 9, 2017

:) - got it. Read the doc before asking dumb question. Sorted now on bs4.

I have run `jupyter kernelspec list' from bash and get

Available kernels: python2 /Users/Chris/Library/Jupyter/kernels/python2 python3 /Users/Chris/Library/Jupyter/kernels/python3

(note - I had originally created the kernels after installing Anaconda follwing the advice at the page you mentioned, long before I discoverd this thread. - here

But it's possible that I had tried both methods (under the 'kernels for Python2 and 3' headers), for both Python 2 and 3. All in the midst of multiple installs and uninstalls of both anaconda and Python3 (using Homebrew). So it's probably all a bit of a mess.

What should I do to align Jupyter with the bash interpreter environments?
Thanks

chrisrb10 commented May 9, 2017

:) - got it. Read the doc before asking dumb question. Sorted now on bs4.

I have run `jupyter kernelspec list' from bash and get

Available kernels: python2 /Users/Chris/Library/Jupyter/kernels/python2 python3 /Users/Chris/Library/Jupyter/kernels/python3

(note - I had originally created the kernels after installing Anaconda follwing the advice at the page you mentioned, long before I discoverd this thread. - here

But it's possible that I had tried both methods (under the 'kernels for Python2 and 3' headers), for both Python 2 and 3. All in the midst of multiple installs and uninstalls of both anaconda and Python3 (using Homebrew). So it's probably all a bit of a mess.

What should I do to align Jupyter with the bash interpreter environments?
Thanks

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver May 10, 2017

Member

You probably want to get rid of the kernelspec for the Python that you start Jupyter with. Based on the paths you showed previously, it looks like that's Python 3, so remove ~/Library/Jupyter/kernels/python3. It should still show Python 3 available in your root environment.

If you want kernels for other environments, you can follow instructions on the same page, under "Kernels for different environments".

Member

takluyver commented May 10, 2017

You probably want to get rid of the kernelspec for the Python that you start Jupyter with. Based on the paths you showed previously, it looks like that's Python 3, so remove ~/Library/Jupyter/kernels/python3. It should still show Python 3 available in your root environment.

If you want kernels for other environments, you can follow instructions on the same page, under "Kernels for different environments".

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 May 10, 2017

That seems to have done the trick - many thanks. Same path for executable showing in both notebook and terminal translator.
Thanks so much for your help.

chrisrb10 commented May 10, 2017

That seems to have done the trick - many thanks. Same path for executable showing in both notebook and terminal translator.
Thanks so much for your help.

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 Jul 3, 2017

Hi @takluyver ,

A problem seems to have occured based on this core kernel path issue , I think.

If I run jupyter kernelspec list in root environment, I now get:

Available kernels:
  python3    /Users/Chris/anaconda3/lib/python3.6/site-packages/ipykernel/resources
  python2    /Users/Chris/Library/Jupyter/kernels/python2

and if I run

from sys import executable 
print(executable)  

In Jupyter notebook and python interpreted running on my Python 3 kernel, I get:

/Users/Chris/anaconda3/bin/python

When installing packages etc. I have gone into:

source activate ipykernel_py3

before using conda install to add new packages.

But I am having a problem now with pandas-datareader. I installed using conda install within the ipykernel_py3 environment, with:

conda install -c anaconda pandas-datareader=0.4.0

Which seemed to work, and with conda list , I see:

# packages in environment at /Users/Chris/anaconda3/envs/ipykernel_py3:
#
appnope                   0.1.0                    py36_0  
beautifulsoup4            4.5.3                    py36_0  
cycler                    0.10.0                   py36_0  
decorator                 4.0.11                   py36_0  
freetype                  2.5.5                         2  
icu                       54.1                          0  
ipykernel                 4.6.1                    py36_0  
ipython                   6.0.0                    py36_0  
ipython_genutils          0.2.0                    py36_0  
jupyter_client            5.0.1                    py36_0  
jupyter_core              4.3.0                    py36_0  
libpng                    1.6.27                        0  
matplotlib                2.0.2               np112py36_0  
mkl                       2017.0.1                      0  
numpy                     1.12.1                   py36_0  
openssl                   1.0.2k                        1  
pandas                    0.20.1              np112py36_0  
pandas-datareader         0.4.0                    py36_0    anaconda
path.py                   10.3.1                   py36_0  
pexpect                   4.2.1                    py36_0  
pickleshare               0.7.4                    py36_0  
pip                       9.0.1                    py36_1  
prompt_toolkit            1.0.14                   py36_0  
ptyprocess                0.5.1                    py36_0  
pygments                  2.2.0                    py36_0  
pyparsing                 2.1.4                    py36_0  
pyqt                      5.6.0                    py36_2  
python                    3.6.1                         0  
python-dateutil           2.6.0                    py36_0  
pytz                      2017.2                   py36_0  
pyzmq                     16.0.2                   py36_0  
qt                        5.6.2                         2  
readline                  6.2                           2  
requests                  2.14.2                   py36_0    anaconda
requests-file             1.4.1                    py36_0    anaconda
requests-ftp              0.3.1                    py36_0    anaconda
scipy                     0.19.0              np112py36_0  
seaborn                   0.7.1                    py36_0  
setuptools                27.2.0                   py36_0  
simplegeneric             0.8.1                    py36_1  
sip                       4.18                     py36_0  
six                       1.10.0                   py36_0  
sqlite                    3.13.0                        0  
tk                        8.5.18                        0  
tornado                   4.5.1                    py36_0  
traitlets                 4.3.2                    py36_0  
wcwidth                   0.1.7                    py36_0  
wheel                     0.29.0                   py36_0  
xz                        5.2.2                         1  
zlib                      1.2.8                         3  

But when I try to import pandas_datareader (the correct import name, based on the documentation here within either a Jupyter notebook on the Py3 kernel, or the interpreter
import pandas_datareader as pdr

I get
ModuleNotFoundError: No module named 'pandas_datareader'

Which I don't understand.

This install approach has worked for other modules (e.g. seaborn, which seems to be working fine).

Can you help me understand why this module isn't working, or being recognised?

Many thanks

chrisrb10 commented Jul 3, 2017

Hi @takluyver ,

A problem seems to have occured based on this core kernel path issue , I think.

If I run jupyter kernelspec list in root environment, I now get:

Available kernels:
  python3    /Users/Chris/anaconda3/lib/python3.6/site-packages/ipykernel/resources
  python2    /Users/Chris/Library/Jupyter/kernels/python2

and if I run

from sys import executable 
print(executable)  

In Jupyter notebook and python interpreted running on my Python 3 kernel, I get:

/Users/Chris/anaconda3/bin/python

When installing packages etc. I have gone into:

source activate ipykernel_py3

before using conda install to add new packages.

But I am having a problem now with pandas-datareader. I installed using conda install within the ipykernel_py3 environment, with:

conda install -c anaconda pandas-datareader=0.4.0

Which seemed to work, and with conda list , I see:

# packages in environment at /Users/Chris/anaconda3/envs/ipykernel_py3:
#
appnope                   0.1.0                    py36_0  
beautifulsoup4            4.5.3                    py36_0  
cycler                    0.10.0                   py36_0  
decorator                 4.0.11                   py36_0  
freetype                  2.5.5                         2  
icu                       54.1                          0  
ipykernel                 4.6.1                    py36_0  
ipython                   6.0.0                    py36_0  
ipython_genutils          0.2.0                    py36_0  
jupyter_client            5.0.1                    py36_0  
jupyter_core              4.3.0                    py36_0  
libpng                    1.6.27                        0  
matplotlib                2.0.2               np112py36_0  
mkl                       2017.0.1                      0  
numpy                     1.12.1                   py36_0  
openssl                   1.0.2k                        1  
pandas                    0.20.1              np112py36_0  
pandas-datareader         0.4.0                    py36_0    anaconda
path.py                   10.3.1                   py36_0  
pexpect                   4.2.1                    py36_0  
pickleshare               0.7.4                    py36_0  
pip                       9.0.1                    py36_1  
prompt_toolkit            1.0.14                   py36_0  
ptyprocess                0.5.1                    py36_0  
pygments                  2.2.0                    py36_0  
pyparsing                 2.1.4                    py36_0  
pyqt                      5.6.0                    py36_2  
python                    3.6.1                         0  
python-dateutil           2.6.0                    py36_0  
pytz                      2017.2                   py36_0  
pyzmq                     16.0.2                   py36_0  
qt                        5.6.2                         2  
readline                  6.2                           2  
requests                  2.14.2                   py36_0    anaconda
requests-file             1.4.1                    py36_0    anaconda
requests-ftp              0.3.1                    py36_0    anaconda
scipy                     0.19.0              np112py36_0  
seaborn                   0.7.1                    py36_0  
setuptools                27.2.0                   py36_0  
simplegeneric             0.8.1                    py36_1  
sip                       4.18                     py36_0  
six                       1.10.0                   py36_0  
sqlite                    3.13.0                        0  
tk                        8.5.18                        0  
tornado                   4.5.1                    py36_0  
traitlets                 4.3.2                    py36_0  
wcwidth                   0.1.7                    py36_0  
wheel                     0.29.0                   py36_0  
xz                        5.2.2                         1  
zlib                      1.2.8                         3  

But when I try to import pandas_datareader (the correct import name, based on the documentation here within either a Jupyter notebook on the Py3 kernel, or the interpreter
import pandas_datareader as pdr

I get
ModuleNotFoundError: No module named 'pandas_datareader'

Which I don't understand.

This install approach has worked for other modules (e.g. seaborn, which seems to be working fine).

Can you help me understand why this module isn't working, or being recognised?

Many thanks

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 Jul 3, 2017

An update to the comment above.

After some comparison to my macbook installation (which never had multiple environments, and a look at Anaconda Navigator, I have worked out the following:

  • conda commands work directly from the bash command line on the Macbook, but do not on the iMac. On the iMac they only work after using a source activate command to start a particular kernel.

  • on the IMac (which most of this thread refers to) there is a 'root' environment (apologies if this was obvious to all but me!). Using a source activate root command allow me to execute conda command (incl install) commands.

  • Having installed in the 'root' environment like this, then the pandas-datareader module works okay.

  • The ipykernel_py3 environment is still there (based on Anaconda Navigator), but I don't know how to open a Jupyter notebook in that environment. I wonder if this may be a function of deleting the python3 folder from jupyter/kernels (see earlier in thread)?

I am still concerned that my Jupyter / Conda installation and setup is flawed, and will cause issues in the future. Anyway you can advise to check this is all configured in line with best practice?

many thanks

chrisrb10 commented Jul 3, 2017

An update to the comment above.

After some comparison to my macbook installation (which never had multiple environments, and a look at Anaconda Navigator, I have worked out the following:

  • conda commands work directly from the bash command line on the Macbook, but do not on the iMac. On the iMac they only work after using a source activate command to start a particular kernel.

  • on the IMac (which most of this thread refers to) there is a 'root' environment (apologies if this was obvious to all but me!). Using a source activate root command allow me to execute conda command (incl install) commands.

  • Having installed in the 'root' environment like this, then the pandas-datareader module works okay.

  • The ipykernel_py3 environment is still there (based on Anaconda Navigator), but I don't know how to open a Jupyter notebook in that environment. I wonder if this may be a function of deleting the python3 folder from jupyter/kernels (see earlier in thread)?

I am still concerned that my Jupyter / Conda installation and setup is flawed, and will cause issues in the future. Anyway you can advise to check this is all configured in line with best practice?

many thanks

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Jul 3, 2017

Member

This value of sys.executable:

/Users/Chris/anaconda3/bin/python

Means that your Python 3 kernel is running in your conda root environment, not the ipykernel_py3 environment you created. If it was in that environment, it you would see something like /Users/Chris/anaconda3/envs/ipykernel_py3/bin/python.

Member

takluyver commented Jul 3, 2017

This value of sys.executable:

/Users/Chris/anaconda3/bin/python

Means that your Python 3 kernel is running in your conda root environment, not the ipykernel_py3 environment you created. If it was in that environment, it you would see something like /Users/Chris/anaconda3/envs/ipykernel_py3/bin/python.

@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 Jul 3, 2017

Thanks - I had arrived at the same conclusion.

My challenge now is that I can't seem to get the Jupyter notebook to operate in an environment that corresponds to the active environment in the terminal window.

Subsequent to my last post, and with more research, I had gone back to my .bash_profile, and amended / commented out lines added in previous troubleshooting of this problem, so now the bash_profile reads (in full):

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
#PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

# added by Anaconda3 4.3.1 installer
export PATH="/Users/Chris/anaconda3/bin:$PATH"


#export PATH=/usr/local/bin:/usr/local/sbin:$PATH

So conda commands now run on the 'root' bash prompt. Using

conda info --envs

yields:

# conda environments:
#
ipykernel_py2            /Users/Chris/anaconda3/envs/ipykernel_py2
ipykernel_py3            /Users/Chris/anaconda3/envs/ipykernel_py3
test_env                 /Users/Chris/anaconda3/envs/test_env
root                  *  /Users/Chris/anaconda3

But if I activate test_env, and then try

sys.executable

then in the python interpreter I get:

/Users/Chris/anaconda3/envs/test_env/bin/python

but in a notebook activated from within this environment, if I do the same

sys.executable

yields:

/Users/Chris/anaconda3/bin/python

Which is not the same.

And the drop down of kernels in the notebook does note seem to correspond to the list of conda environments presented above - as the drop down only shows 'Python 2' or 'Python 3'
(I can't seem to attach a screengrab to illustrate this).

I wonder if this has anything to do with the action to

it looks like that's Python 3, so remove

~/Library/Jupyter/kernels/python3.

that we arrived at in the previous discussion around this problem.

So, basically, I seem to have got the Jupyter installation to a point where the kernels it offers do not appear to correspond to those recognised by conda as available environments.

Any ideas how to correct this?

Many thanks

chrisrb10 commented Jul 3, 2017

Thanks - I had arrived at the same conclusion.

My challenge now is that I can't seem to get the Jupyter notebook to operate in an environment that corresponds to the active environment in the terminal window.

Subsequent to my last post, and with more research, I had gone back to my .bash_profile, and amended / commented out lines added in previous troubleshooting of this problem, so now the bash_profile reads (in full):

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
#PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

# added by Anaconda3 4.3.1 installer
export PATH="/Users/Chris/anaconda3/bin:$PATH"


#export PATH=/usr/local/bin:/usr/local/sbin:$PATH

So conda commands now run on the 'root' bash prompt. Using

conda info --envs

yields:

# conda environments:
#
ipykernel_py2            /Users/Chris/anaconda3/envs/ipykernel_py2
ipykernel_py3            /Users/Chris/anaconda3/envs/ipykernel_py3
test_env                 /Users/Chris/anaconda3/envs/test_env
root                  *  /Users/Chris/anaconda3

But if I activate test_env, and then try

sys.executable

then in the python interpreter I get:

/Users/Chris/anaconda3/envs/test_env/bin/python

but in a notebook activated from within this environment, if I do the same

sys.executable

yields:

/Users/Chris/anaconda3/bin/python

Which is not the same.

And the drop down of kernels in the notebook does note seem to correspond to the list of conda environments presented above - as the drop down only shows 'Python 2' or 'Python 3'
(I can't seem to attach a screengrab to illustrate this).

I wonder if this has anything to do with the action to

it looks like that's Python 3, so remove

~/Library/Jupyter/kernels/python3.

that we arrived at in the previous discussion around this problem.

So, basically, I seem to have got the Jupyter installation to a point where the kernels it offers do not appear to correspond to those recognised by conda as available environments.

Any ideas how to correct this?

Many thanks

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Jul 3, 2017

Member

Your options are:

  • Install a kernel for each environment you're interested in.
  • Reinstall all of Jupyter in each environment (conda install jupyter) and run the notebook server from inside the environment.
  • Use conda's nb_conda_kernels extension, which exposes environments as kernels. This comes with some confusion of its own, though.
Member

takluyver commented Jul 3, 2017

Your options are:

  • Install a kernel for each environment you're interested in.
  • Reinstall all of Jupyter in each environment (conda install jupyter) and run the notebook server from inside the environment.
  • Use conda's nb_conda_kernels extension, which exposes environments as kernels. This comes with some confusion of its own, though.
@chrisrb10

This comment has been minimized.

Show comment
Hide comment
@chrisrb10

chrisrb10 Jul 6, 2017

Many thanks. I think it's sorted now.

the nb_conda extension seems to work. Are there any particular confusions I should watch out for?

chrisrb10 commented Jul 6, 2017

Many thanks. I think it's sorted now.

the nb_conda extension seems to work. Are there any particular confusions I should watch out for?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Jul 6, 2017

Member

Exchanging notebooks with other people who don't use nb_conda_kernels can be a pain, because the kernel name embedded in the notebook refers to the conda env you ran it in. It's not a big problem, but either side may have to manually select a kernel on opening the notebook.

Member

takluyver commented Jul 6, 2017

Exchanging notebooks with other people who don't use nb_conda_kernels can be a pain, because the kernel name embedded in the notebook refers to the conda env you ran it in. It's not a big problem, but either side may have to manually select a kernel on opening the notebook.

@bopeebs

This comment has been minimized.

Show comment
Hide comment
@bopeebs

bopeebs Jul 13, 2017

I seem to be having the same issue as @chrisrb10..
Normally I use an Atom as a text editor but am using the notebook for its convenience in widgets.
On Atom I don't seem to be having a problem when importing the module Rebound, the error only occurs in the notebook.

I am able to import Rebound fine, it just will not allow me to access an attribute in the module. I get the error: AttributeError: module 'rebound' has no attribute 'Simulation'.
Running from sys import executable print(executable) in Atom gives me /Users/anaconda/bin/python,
and Notebook gives me /Users/Dean/anaconda3/bin/python.
I'm not entirely sure if this is where the problem lies for me since I'm able to import but not access an attribute but would anyone have an idea of what is going on?

bopeebs commented Jul 13, 2017

I seem to be having the same issue as @chrisrb10..
Normally I use an Atom as a text editor but am using the notebook for its convenience in widgets.
On Atom I don't seem to be having a problem when importing the module Rebound, the error only occurs in the notebook.

I am able to import Rebound fine, it just will not allow me to access an attribute in the module. I get the error: AttributeError: module 'rebound' has no attribute 'Simulation'.
Running from sys import executable print(executable) in Atom gives me /Users/anaconda/bin/python,
and Notebook gives me /Users/Dean/anaconda3/bin/python.
I'm not entirely sure if this is where the problem lies for me since I'm able to import but not access an attribute but would anyone have an idea of what is going on?

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Jul 14, 2017

Member

That is likely the problem. It looks like you have to installs of anaconda, one in /Users/anaconda and one in /Users/Dean/anaconda3. The difference is probably in the PATH environment variable in atom vs when you launch the notebook. Whichever one of those you mean to be using, make sure it is first on your PATH, e.g.

export PATH=/Users/Dean/anaconda3/bin:$PATH
Member

minrk commented Jul 14, 2017

That is likely the problem. It looks like you have to installs of anaconda, one in /Users/anaconda and one in /Users/Dean/anaconda3. The difference is probably in the PATH environment variable in atom vs when you launch the notebook. Whichever one of those you mean to be using, make sure it is first on your PATH, e.g.

export PATH=/Users/Dean/anaconda3/bin:$PATH
@bhanu-mnit

This comment has been minimized.

Show comment
Hide comment
@bhanu-mnit

bhanu-mnit Sep 6, 2017

On Mac, for me it was a little different. When I ran the command jupyter kernelspec list I got this:
`Available kernels:

python2 /usr/local/etc/jupyter/kernels/python2

python3 /usr/local/etc/jupyter/kernels/python3`

I just ran pip2 install pandas which then installed it for python2 kernel which was being used in my jupyter notebook. Apparently for pip the path of the kernel is a little different.

bhanu-mnit commented Sep 6, 2017

On Mac, for me it was a little different. When I ran the command jupyter kernelspec list I got this:
`Available kernels:

python2 /usr/local/etc/jupyter/kernels/python2

python3 /usr/local/etc/jupyter/kernels/python3`

I just ran pip2 install pandas which then installed it for python2 kernel which was being used in my jupyter notebook. Apparently for pip the path of the kernel is a little different.

@EmilioSantias

This comment has been minimized.

Show comment
Hide comment
@EmilioSantias

EmilioSantias Apr 12, 2018

Hello, it is weird for me but I can import some libraries such as pandas, numpy etc however I can't import some libraries such as seaborn or scikit learn.
ModuleNotFoundError: No module named 'seaborn'
How can I fix it and import those two: seaborn and scikit learn?
tks in advance

EmilioSantias commented Apr 12, 2018

Hello, it is weird for me but I can import some libraries such as pandas, numpy etc however I can't import some libraries such as seaborn or scikit learn.
ModuleNotFoundError: No module named 'seaborn'
How can I fix it and import those two: seaborn and scikit learn?
tks in advance

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Apr 12, 2018

Member

They're probably not installed. You can install them with pip or conda depending on what setup you're using (if you're not sure, try conda, and if it's not there, use pip).

Member

takluyver commented Apr 12, 2018

They're probably not installed. You can install them with pip or conda depending on what setup you're using (if you're not sure, try conda, and if it's not there, use pip).

@EmilioSantias

This comment has been minimized.

Show comment
Hide comment
@EmilioSantias

EmilioSantias Apr 12, 2018

Hi takluyver, tks.
I used pip and conda, they are already installed and requirements have been satisfied. any idea?

EmilioSantias commented Apr 12, 2018

Hi takluyver, tks.
I used pip and conda, they are already installed and requirements have been satisfied. any idea?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Apr 12, 2018

Member

It sounds like you're trying an import in two different installations of Python, or two different environments. Check sys.executable to see which Python and environment you're running in, and sys.path to see where it looks to import modules.

Python packages must be installed separately for each copy of Python you use, and if you are using virtualenvs or conda envs, packages must be installed into each environment where you need them. Either the package is not installed in one, or a different version of the package is installed.

To install packages to a particular Python installation or environment using pip, you can run it like this:

path/to/python -m pip install ...
# Replace path/to/python with the path of the Python executable (sys.executable)

If you are using conda environments, you can install packages from conda like this:

source activate myenv  # On Windows, just 'activate myenv' (no 'source')
conda install ...

For more detail, see this blog post.

[ This is a saved reply because I answer similar questions often - sorry if it doesn't exactly fit your case ]

Member

takluyver commented Apr 12, 2018

It sounds like you're trying an import in two different installations of Python, or two different environments. Check sys.executable to see which Python and environment you're running in, and sys.path to see where it looks to import modules.

Python packages must be installed separately for each copy of Python you use, and if you are using virtualenvs or conda envs, packages must be installed into each environment where you need them. Either the package is not installed in one, or a different version of the package is installed.

To install packages to a particular Python installation or environment using pip, you can run it like this:

path/to/python -m pip install ...
# Replace path/to/python with the path of the Python executable (sys.executable)

If you are using conda environments, you can install packages from conda like this:

source activate myenv  # On Windows, just 'activate myenv' (no 'source')
conda install ...

For more detail, see this blog post.

[ This is a saved reply because I answer similar questions often - sorry if it doesn't exactly fit your case ]

@EmilioSantias

This comment has been minimized.

Show comment
Hide comment
@EmilioSantias

EmilioSantias Apr 12, 2018

TKS a LOT, now it seems is working properly.

EmilioSantias commented Apr 12, 2018

TKS a LOT, now it seems is working properly.

@DanlanChen

This comment has been minimized.

Show comment
Hide comment
@DanlanChen

DanlanChen Jun 11, 2018

restart the kernel works for me

DanlanChen commented Jun 11, 2018

restart the kernel works for me

@Kprzeorski

This comment has been minimized.

Show comment
Hide comment
@Kprzeorski

Kprzeorski Jun 22, 2018

Using Jupyter notebooks with Anaconda, after installing a package, in my case tensorflow, Jupyter notebook could not import the package(due to some configuration issue I screwed up while trying to configure R with Jupyter). The underlying fix for Jupyter to find packages installed by Anaconda was hinted above by user 'rsmith31415'.... I revised the first line of the argv value to point to environment folder (py36):

`{

"argv": [
"/home/kap/anaconda3/envs/py36/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
}`

Kprzeorski commented Jun 22, 2018

Using Jupyter notebooks with Anaconda, after installing a package, in my case tensorflow, Jupyter notebook could not import the package(due to some configuration issue I screwed up while trying to configure R with Jupyter). The underlying fix for Jupyter to find packages installed by Anaconda was hinted above by user 'rsmith31415'.... I revised the first line of the argv value to point to environment folder (py36):

`{

"argv": [
"/home/kap/anaconda3/envs/py36/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
}`

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