pandas not working

2019-08-21 17:23发布

It seems that I already have pandas downloaded but I can't seem to use it in my program

I am using a mac with version 10.12.6

Any help would be greatly appreciated

here is my console commands

➜  Downloads cat code.py
import pandas

➜  Downloads pip3 install pandas
Requirement already satisfied: pandas in /usr/local/lib/python3.6/site-    packages
Requirement already satisfied: numpy>=1.7.0 in     /usr/local/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: python-dateutil>=2 in /usr/local/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: pytz>=2011k in     /usr/local/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/site-packages (from python-dateutil>=2->pandas)
➜  Downloads python code.py
Traceback (most recent call last):
  File "code.py", line 1, in <module>
    import pandas
ImportError: No module named pandas
➜  Downloads

标签: python macos pip
1条回答
做自己的国王
2楼-- · 2019-08-21 18:04

If you want to use Python3 on a Mac under homebrew, you need to:

  • install homebrew, by going to the homebrew website
  • install Python3 with

    brew install python3

  • install any Python3 packages with pip3 rather than pip:

    pip3 install PACKAGE # e.g. pip3 install pandas


If Python3 is installed correctly under homebrew, you will see that /usr/local/bin/python3 is a symlink to something in homebrew's Cellar:

ls -l /usr/local/bin/python3

lrwxr-xr-x  1 mark  admin      35  6 Oct 16:13 /usr/local/bin/python3 -> ../Cellar/python3/3.6.3/bin/python3

If that is not the case, you have either not installed Python3 or you had a previous installation and homebrew was reluctant to overwrite it. In which case, if you really want to run with homebrew's Python3, run:

brew link python3 --force

and check again if it is a symlink.


Then, when you run any Python3 scripts, you either need to put the full path in your shebang:

#!/usr/local/bin/python3
import something
import something-else

or, run with:

/usr/local/bin/python3 some-script.py

or, if your PATH includes /usr/local/bin:

python3 some-script.py

You can check your PATH with:

echo $PATH

and see if it has /usr/local/bin near the start - which is what you want if you use homebrew.


If you have set up correctly, and you run:

type python3

it will report:

python3 is /usr/local/bin/python3

because homebrew installs package binaries into /usr/local/bin. If it tells you anything other than /usr/local/bin/python3, then your PATH is incorrect and it needs setting both in your current session, with something like:

export PATH=/usr/local/bin:$PATH

and with a similar command in your login profile for subsequent login sessions - that will be something like $HOME/.profile, or $HOME/.bash_profile if you use bash.


In general, if you are running homebrew, you should check your system health every now and then with:

brew doctor

and follow the good doctor's advice - he's pretty good - I trained him ;-)

查看更多
登录 后发表回答