pandas Python3无法识别的熊猫

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49265260/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:19:29  来源:igfitidea点击:

Pandas unrecognized by Python3

python-3.xpandascentos

提问by dduque

I am using python3 in CentOS and I was able to install pandas using pip3, but when I do import pandas in python3, it throws import error: no module named pandas.

我在 CentOS 中使用 python3 并且我能够使用 pip3 安装Pandas,但是当我在 python3 中导入Pandas时,它抛出导入错误:没有名为Pandas的模块。

采纳答案by Aristu

There are many reasons to not install packages through piponly, one is that you may end up installing them globally, meaning you either wont be able or will have trouble using two different versions of the same package.

不只通过安装软件包的原因有很多pip,一个是您最终可能会全局安装它们,这意味着您要么无法使用同一软件包的两个不同版本,要么会遇到问题。

It's better to let each project have it's own dependencies, if something goes really (really) wrong you'll just nuke your project environment without hurting other projects. One of the most acceptable ways of doing this is by using virtual environments.

最好让每个项目都有自己的依赖项,如果真的(真的)出了问题,你只会破坏你的项目环境而不会伤害其他项目。这样做的最可接受的方法之一是使用虚拟环境

With virtualenv

使用虚拟环境

To create a virtualenv

创建一个虚拟环境

$ virtualenv ENV

Then activate it

然后激活它

$ source bin/activate

Now install pandas

现在安装Pandas

$ pip install pandas

To leave the environment:

离开环境:

$ deactivate

With pipenv

用pipenv

You can also combine pyenv(which lets you install different Python versions) with pipenv.

您还可以将pyenv(允许您安装不同的 Python 版本)与pipenv 结合使用

Example:

例子:

# creating a directory for my project
$ mkdir pandas-env && cd pandas-env

# creating an environment with Python 3.6.4
$ pipenv --python 3.6.4

# installing pandas in your environment
$ pipenv install pandas

# enter your environment
$ pipenv shell

# and check your python version, it's probably different 
# from the older system's version
$ python
Python 3.6.4 (default, Mar  6 2018, 10:29:06) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

# now import pandas
>>> import pandas as pd
>>>

To leave your environment just press CTL+D.

要离开您的环境,只需按 CTL+D。