If I have Pandas installed correctly, why won'

2019-06-11 02:41发布

问题:

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     

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:

(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

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.

回答1:

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

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

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

Hope this helps



回答2:

Go to powershell on your system and pip install pandas. you will see a successfully installed command. you can install other modules too like matplotlib et al.