Jupyter python3 notebook 无法识别熊猫
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40553560/
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
Jupyter python3 notebook cannot recognize pandas
提问by William Ross
I am using the Jupyter notebook with Python 3 selected. On the first line of a cell I am entering:
我正在使用 Jupyter 笔记本并选择了 Python 3。在我输入的单元格的第一行:
import pandas as pd
The error I get from the notebook is, ImportError: No module named 'pandas'. How can I install pandas to the jupyter notebook? The computer I launched the Jupyter notebook from definitely has pandas.
我从笔记本中得到的错误是,ImportError: No module named 'pandas'。如何将 Pandas 安装到 jupyter notebook?我启动 Jupyter 笔记本的计算机肯定有 Pandas。
I tried doing:
我试着做:
!pip install pandas
And it says it is already installed but for Python 2.7 at the bottom. My script shows it is a Python 3 script at the top though.
它说它已经安装,但底部是 Python 2.7。我的脚本显示它是顶部的 Python 3 脚本。
When I do echo $PATH in Ubuntu is shows that '/home/user/anaconda2/bin' is on the first entry. I think I may need to change this to be anaconda3?
当我在 Ubuntu 中执行 echo $PATH 时,显示 '/home/user/anaconda2/bin' 在第一个条目上。我想我可能需要将其更改为 anaconda3?
UPDATE: When I try and launch a Python3 script through jupyter the command line which launched Jupyter gives me the error "ImportError: No module named 'IPython.paths'. Then there is a timeout waiting for 'kernel_info' reply. Additionally, I tried removing anaconda but still experience the same error. I have tried to make so many quick fixes now, that I am not sure what the next step is to get this working.
更新:当我尝试通过 jupyter 启动 Python3 脚本时,启动 Jupyter 的命令行给了我错误“ImportError: No module named 'IPython.paths'。然后等待'kernel_info'回复超时。此外,我试过删除 anaconda 但仍然遇到同样的错误。我现在已经尝试了很多快速修复,我不确定下一步是什么让这个工作正常进行。
采纳答案by amin
As your default python version is 2.x , if you don't have any emphasis on the python 3.x you can try from the first by the below scripts.
由于您的默认 python 版本是 2.x ,如果您对 python 3.x 没有任何重视,您可以通过以下脚本从第一个开始尝试。
pip install --upgrade pip
pip install jupyter
then in jupyter notebook:
然后在 jupyter 笔记本中:
!pip install pandas
The version of notebook will be 2.x. Otherwise install pip3 by the below Linux commands.
notebook 的版本为 2.x。否则,请通过以下 Linux 命令安装 pip3。
sudo apt-get install python3-setuptools
sudo easy_install3 pip
now you can add pandas to the notebook by !pip3 install pandas
.
现在您可以通过 将熊猫添加到笔记本中!pip3 install pandas
。
回答by Boud
If you use anaconda already as a distribution, stop using pip in that context. Use conda instead and you will stop having headaches. The command lines and procedures for setting up a new environment are pretty well documented here.
如果您已经使用 anaconda 作为发行版,请停止在该上下文中使用 pip。改用 conda,您将不再头疼。用于设置新环境的命令行和过程在此处有详细说明。
Basically upgrading python or having specific branches:
基本上升级python或有特定的分支:
conda update python
conda install python=3.5
Or using specific environments:
或使用特定环境:
conda create -n py35 python=3.5 anaconda
回答by Axel Juraske
If pip3 is install you could run
如果安装了 pip3,您可以运行
!pip3 install pandas
回答by X Personified
simple step to resolve the problem is
解决问题的简单步骤是
( NOTE:Remember what you have selected python 2 or python 3).
(注意:请记住您选择了 python 2 或 python 3)。
for python 2+
蟒蛇 2+
!pip install pandas
or if you have user permission error type
或者如果您有用户权限错误类型
!pip install pandas --user
for python 3+
蟒蛇 3+
!pip3 install pandas
or if you have user permission error type
或者如果您有用户权限错误类型
!pip3 install pandas --user
回答by Mohamed AL ANI
Did you try the solution here : https://github.com/jupyter/notebook/issues/270
您是否尝试过这里的解决方案:https: //github.com/jupyter/notebook/issues/270
回答by Yaman Ahlawat
This is what i have done in my system:
这是我在我的系统中所做的:
I have installed both anaconda for python 2.7 and anaconda for python 3.5. Anaconda helps keep both the environment separate.
我已经为 python 2.7 安装了 anaconda,为 python 3.5 安装了 anaconda。Anaconda 有助于将两个环境分开。
In Ubuntu:
在 Ubuntu 中:
The directory structure is like this: anaconda2/bin/ anaconda3/bin/
目录结构是这样的:anaconda2/bin/anaconda3/bin/
Whenever i want to use python 2.7 i go to anaconda2/bin/ and create an environment or activate already existing environment and install or import all the necessary packages and same goes for python3.5 (go to anconda3/bin/ create or activate the required environment). This helps me keep things separate.
每当我想使用 python 2.7 时,我都会转到 anaconda2/bin/ 并创建一个环境或激活已经存在的环境并安装或导入所有必要的包,python3.5 也是如此(转到 anconda3/bin/ 创建或激活所需的环境)。这有助于我将事情分开。
Since you are using anaconda you should first use "conda install " if that package is not found, then you can use pip install .
由于您使用的是 anaconda,如果未找到该软件包,您应该首先使用“conda install”,然后您可以使用 pip install 。
In Windows:
在 Windows 中:
If you install both anaconda2 and anaconda3, its quite easy.. the shortcuts for anaconda prompt are in C:\Users\your-username\
如果你同时安装 anaconda2 和 anaconda3,它很容易.. anaconda 提示的快捷方式在 C:\Users\your-username\
there will be two folders anconda2 and anaconda3, you can start conda prompt for python2.7 from anaconda2 and python3.5 from anconda3
将有两个文件夹 anconda2 和 anaconda3,您可以从 anaconda2 启动 python2.7 的 conda prompt 和从 anconda3 启动 python3.5
So, once you start the anaconda prompt you can just type "jupyter notebook" to open jupyter notebook in browser and import pandas(or any package).
因此,一旦您启动 anaconda 提示符,您只需键入“jupyter notebook”即可在浏览器中打开 jupyter notebook 并导入 pandas(或任何包)。
You can check this link:
您可以查看此链接:
回答by Samuel S. Ampofo
This worked for me
这对我有用
in Jupiter notebook
import sys print(sys.executable)
copy path eg:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
install the module on the terminal like this.
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas
在木星笔记本中
import sys print(sys.executable)
复制路径例如:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
像这样在终端上安装模块。
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas
回答by X Personified
For Windows
对于 Windows
The first step is to create a new conda environment. A conda environment is like a virtualenv that allows you to specify a specific version of Python and set of libraries. Run the following commands from a terminal window:
第一步是创建一个新的 conda 环境。conda 环境就像一个 virtualenv,它允许您指定特定版本的 Python 和一组库。从终端窗口运行以下命令:
conda create -n name_of_my_env python
This will create a minimal environment with only Python installed in it. To put your self inside this environment run:
这将创建一个仅安装 Python 的最小环境。把你自己放在这个环境中运行:
source activate name_of_my_env
On Windows the command is:
在 Windows 上,命令是:
activate name_of_my_env
The final step required is to install pandas. This can be done with the following command:
所需的最后一步是安装熊猫。这可以通过以下命令完成:
conda install pandas
To install a specific pandas version:
要安装特定的 Pandas 版本:
conda install pandas=0.20.3
To install other packages, IPython for example:
要安装其他软件包,例如 IPython:
conda install ipython
To install the full Anaconda distribution:
要安装完整的 Anaconda 发行版:
conda install anaconda
If you need packages that are available to pip but not conda, then install pip, and then use pip to install those packages:
如果您需要可用于 pip 但不可用于 conda 的软件包,请安装 pip,然后使用 pip 安装这些软件包:
conda install pip
pip install django
回答by zhao
I meet the same problem in jupyter notebook, and I run the command below and solve my problem:
我在 jupyter notebook 中遇到了同样的问题,我运行下面的命令并解决了我的问题:
!pip install pandas
回答by Santosh sanwal
I was getting the error
我收到错误
modulenotfounderror: no module named 'pandas'
modulenotfounderror: 没有名为“pandas”的模块
in jupyter. I tried the command:
在 jupyter 中。我试过命令:
!pip install pandas
and it worked like a charm.
它就像一个魅力。