简体   繁体   English

Jupyter python3笔记本无法识别pandas

[英]Jupyter python3 notebook cannot recognize pandas

I am using the Jupyter notebook with Python 3 selected.我正在使用选择了 Python 3 的 Jupyter 笔记本。 On the first line of a cell I am entering:在我输入的单元格的第一行:

import pandas as pd

The error I get from the notebook is, ImportError: No module named 'pandas'.我从笔记本中得到的错误是,ImportError:没有名为“pandas”的模块。 How can I install pandas to the jupyter notebook?如何将 pandas 安装到 jupyter notebook? The computer I launched the Jupyter notebook from definitely has pandas.我启动 Jupyter Notebook 的计算机肯定有 pandas。

I tried doing:我试着做:

!pip install pandas

And it says it is already installed but for Python 2.7 at the bottom.它说它已经安装,但底部为 Python 2.7。 My script shows it is a Python 3 script at the top though.我的脚本在顶部显示它是一个 Python 3 脚本。

When I do echo $PATH in Ubuntu is shows that '/home/user/anaconda2/bin' is on the first entry.当我在 Ubuntu 中回显 $PATH 时,显示“/home/user/anaconda2/bin”在第一个条目上。 I think I may need to change this to be anaconda3?我想我可能需要将其更改为 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:没有名为'IPython.paths'的模块。然后等待'kernel_info'回复超时。此外,我试过删除 anaconda 但仍然遇到相同的错误。我现在已经尝试了很多快速修复,但我不确定下一步是什么才能让它正常工作。

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. notebook 的版本为 2.x。 Otherwise install pip3 by the below Linux commands.否则,请通过以下 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将 pandas 添加到笔记本中。

This worked for me这对我有用

  1. in Jupiter notebook在木星笔记本中

     import sys print(sys.executable)
  2. copy path eg:复制路径例如:

     /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
  3. install the module on the terminal like this.像这样在终端上安装模块。

     /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas

Or it can be installed directly from Jupyter Cell as follows或者可以直接从 Jupyter Cell 安装,如下所示

! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas

If you use anaconda already as a distribution, stop using pip in that context.如果您已经使用 anaconda 作为发行版,请停止在该上下文中使用 pip。 Use conda instead and you will stop having headaches.改用 conda,您将不再头疼。 The command lines and procedures for setting up a new environment are pretty well documented here .用于设置新环境的命令行和过程在此处有详细说明。

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

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

如果安装了 pip3,您可以运行

!pip3 install pandas

您是否在这里尝试过该解决方案: https : //github.com/jupyter/notebook/issues/270

This is what i have done in my system:这是我在我的系统中所做的:

I have installed both anaconda for python 2.7 and anaconda for python 3.5.我已经为 python 2.7 安装了 anaconda,为 python 3.5 安装了 anaconda。 Anaconda helps keep both the environment separate. 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).每当我想使用 python 2.7 时,我都会转到 anaconda2/bin/ 并创建一个环境或激活已经存在的环境并安装或导入所有必要的包,python3.5 也是如此(转到 anconda3/bin/ 创建或激活所需的环境)。 This helps me keep things separate.这有助于我将事情分开。

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:您可以查看此链接:

http://conda.pydata.org/docs/test-drive.html#managing-conda http://conda.pydata.org/docs/test-drive.html#managing-conda

我在 jupyter notebook 中遇到了同样的问题,我运行下面的命令并解决了我的问题:

!pip install pandas

For Windows对于 Windows

The first step is to create a new conda environment.第一步是创建一个新的 conda 环境。 A conda environment is like a virtualenv that allows you to specify a specific version of Python and set of libraries. conda 环境就像一个 virtualenv,它允许您指定特定版本的 Python 和一组库。 Run the following commands from a terminal window:从终端窗口运行以下命令:

conda create -n name_of_my_env python

This will create a minimal environment with only Python installed in it.这将创建一个仅安装 Python 的最小环境。 To put your self inside this environment run:把你自己放在这个环境中运行:

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

Iuse window 7 for work and I had the same problems when I tried to import Pandas.我使用 window 7 进行工作,当我尝试导入 Pandas 时也遇到了同样的问题。 So I tried to install packages under each environment:所以我尝试在每个环境下安装软件包:

Run cmd and type the following code:运行cmd并输入以下代码:

activate py27 
conda install pandas 

If the system asks you do you want to install the following new packages, choose Y for [yes]如果系统询问您是否要安装以下新软件包,请为 [yes] 选择 Y

And install pandas for each different environment if you installed Python27, Python 35 and Python 36, as I did.如果您像我一样安装了 Python27、Python 35 和 Python 36,则为每个不同的环境安装 pandas。

Then problem solved if you run jupyter notebook again and you can import pandas successfully.然后问题解决了,如果你再次运行 jupyter notebook 并且你可以成功导入熊猫。

You can also solve the same problem for packages like numpy, scipy, etc..您还可以为 numpy、scipy 等包解决相同的问题。

Maybe its a broken (pip) installation.也许它是一个损坏的(pip)安装。 Following worked for me:以下为我工作:

sudo apt --fix-broken install sudo apt --fix-broken 安装

Followed by:紧随其后的是:

sudo pip3 install pandas须藤 pip3 安装熊猫

Hope this helps.希望这会有所帮助。

I was getting the error我收到错误

modulenotfounderror: no module named 'pandas' modulenotfounderror: 没有名为“pandas”的模块

in jupyter.在 jupyter 中。 I tried the command:我试过命令:

!pip install pandas

and it worked like a charm.它就像一个魅力。

My pandas version was 0.20.3 I have updated to 0.25 using conda update pandas .我的熊猫版本是 0.20.3 我已经使用conda update pandas更新到 0.25 。 I have checked in Command Line Interface(CLI) its pd.__version__ '0.25.1' .我已经检查了命令行界面(CLI)的pd.__version__ '0.25.1'

In Jupyter notebook its showing '0.20.3'.在 Jupyter 笔记本中,它显示“0.20.3”。

Please restart jupyter notebook.请重新启动 jupyter 笔记本。 note is cache your pandas.注意是缓存你的熊猫。 or you can create a new notebook或者你可以创建一个新的笔记本

One silly mistake that you could make is to invoke Jupyter with your local machine python installation and not the anaconda python.您可能犯的一个愚蠢错误是使用本地机器 python 安装而不是 anaconda python 调用 Jupyter。 I had the same problem and just setting the PATH did not work for me.我遇到了同样的问题,只是设置 PATH 对我不起作用。

FIX: By default, anaconda binaries are in "<Path_to_anaconda>/bin".修复:默认情况下,anaconda 二进制文件位于“<Path_to_anaconda>/bin”中。 For example, in my case, they are in "/home/klakhotia/anaconda3/bin".例如,就我而言,它们位于“/home/klakhotia/anaconda3/bin”中。 This directory will also contain the binary to anaconda jupyter.此目录还将包含 anaconda jupyter 的二进制文件。 Launch the jupyter from here or create an alias in your .bashrc that points to this file.从这里启动 jupyter 或在您的 .bashrc 中创建一个指向此文件的别名。

What worked for me was:对我有用的是:

pip3 install pandas jupyter

Simple solution : In a Notebook's cell type and execute the code:简单的解决方案:在笔记本的单元格类型中并执行代码:

import sys  
!{sys.executable} -m pip install pandas

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM