pandas 无法在 Jupyter Notebook 上导入熊猫
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41913580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to import pandas on Jupyter Notebook
提问by Saber Alex
I've installed both pandas and jupyter notebook on my virtualenvs(python3).
When I check which jupyter
, it's correctly refer to my envs. However, I can't import pandas when I run it in the browser.
When I run the ipython, I can import the pandas module though...
我已经在我的 virtualenvs(python3) 上安装了 pandas 和 jupyter notebook。当我检查时which jupyter
,它正确地指的是我的环境。但是,当我在浏览器中运行它时,我无法导入Pandas。当我运行 ipython 时,我可以导入 pandas 模块...
ImportError: No module named 'pandas'
ImportError: No module named 'pandas'
Any help?
有什么帮助吗?
回答by Aleksey Bilogur
Jupyter is built with the Anaconda Python distribution (and the conda
environment manager) in mind. Although some work has been done to remediate this issue, using jupyter
with virtualenv
is discouraged.
Jupyter 在构建时考虑到了 Anaconda Python 发行版(和conda
环境管理器)。虽然已经做了一些工作来修复这个问题,但不鼓励使用jupyter
with virtualenv
。
In this case it sounds like jupyter
is using your default (root) Python environment, because it's not aware of your virtualenv
one. See herefor details on how to fix that.
在这种情况下,听起来像是jupyter
在使用您的默认(根)Python 环境,因为它不知道您的环境virtualenv
。有关如何解决此问题的详细信息,请参见此处。
回答by Félix Fu
If you land here looking for the answer, this is it (taken from the question @Aleksey Bilogur refers):
如果你降落在这里寻找答案,就是这样(取自@Aleksey Bilogur 所指的问题):
source activate ENVNAME
pip install ipykernel
python -m ipykernel install --user --name ENVNAME --display-name "Python (whatever you want to call it)"
It is really important that you install ipykernel in your virtualenv and that you launch jupyter notebook
also from you ENVNAME.
在 virtualenv 中安装 ipykernel 并jupyter notebook
从 ENVNAME启动非常重要。
Once you've done that, check if the path to your ENVNAME appears when executing from your notebook:
完成后,检查从笔记本执行时是否出现 ENVNAME 路径:
import sys
sys.path
If it does not, something went wrong and it won't work.
如果没有,则出现问题并且无法正常工作。