为什么我的导入语句无法识别它

为什么我的导入语句无法识别它

本文介绍了如果我正确安装了Pandas,为什么我的导入语句无法识别它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个要处理csv文件的项目,但是我无法让熊猫工作.到目前为止,我研究的所有内容都告诉我要确保已安装熊猫.使用pip我已经成功安装了熊猫.当我尝试运行我的python程序并导入大熊猫时,我得到:

I'm working on a project to play around with a csv file, however, I can't get pandas to work. Everything I have researched so far has just told me to make sure that pandas is installed. Using pip I have managed to install pandas just fine. When I try to run my python program and import pandas I get:

Traceback (most recent call last):
  File "analysis.py", line 1, in <module>
    import pandas as pd
ImportError: No module named pandas

我不知道这是否相关,但是我试图查看它是否适用于conda install pandas,但是,我收到此导入错误:

I don't know if this is related, but I was trying to see see if this would work with conda install pandas however, I get this import error:

(同样,Anaconda已正确安装在我的系统上)

(Again, Anaconda is correctly installed on my system)

Traceback (most recent call last):
  File "/usr/local/bin/conda", line 9, in <module>
load_entry_point('conda==4.2.7', 'console_scripts', 'conda')()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2627, in load_entry_point
return ep.load()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2287, in load
return self.resolve()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2293, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Library/Python/2.7/site-packages/conda/cli/__init__.py", line 8, in <module>
from .main import main  # NOQA
  File "/Library/Python/2.7/site-packages/conda/cli/main.py", line 46, in <module>
from ..base.context import context
  File "/Library/Python/2.7/site-packages/conda/base/context.py", line 18, in <module>
from ..common.configuration import (Configuration, MapParameter, PrimitiveParameter,
  File "/Library/Python/2.7/site-packages/conda/common/configuration.py", line 40, in <module>
from ruamel.yaml.comments import CommentedSeq, CommentedMap  # pragma: no cover
ImportError: No module named ruamel.yaml.comments

有人在导入库方面有类似的经历吗?我试图确保我具有适用于Python3的正确版本,但这似乎不是问题.任何帮助将不胜感激!谢谢你.

Anyone have a similar experience importing libraries? I have tried to make sure that I have the correct versions for Python3 but that doesn't seem to be the issue. Any help would be greatly appreciated! Thank you.

推荐答案

问题是pip将内容安装到的'lib'文件夹为您正在使用的每个python环境提供了一个单独的子目录(默认为python2.7).一个简单的解决方法是构建python3的虚拟环境,然后将pandas或任何您想要的软件包安装到其中.为此,请尝试以下操作:

The problem is that the 'lib' folder that pip installs things into has a separate subdirectory for each python environment that you're working with (by default this is python2.7). A simple workaround is to build a virtual environment of python3 and then installing pandas or whatever package you want into it. To achieve this, try the following:

virtualenv -p /usr/bin/python3 python3

现在,每次您要点安装python3软件包时,运行

Now, each time you want to pip install a python3 package, run

source python3/bin/activate
pip install pandas --user

希望这会有所帮助

这篇关于如果我正确安装了Pandas,为什么我的导入语句无法识别它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:16