6

I run the following command to install pandas via pip:

sudo pip install pandas --upgrade

which outputs

Requirement already up-to-date: pandas in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Requirement already up-to-date: numpy>=1.7.0 in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from pandas)
Requirement already up-to-date: python-dateutil>=2 in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from pandas)
Requirement already up-to-date: pytz>=2011k in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from pandas)
Requirement already up-to-date: six>=1.5 in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from python-dateutil>=2->pandas)

However, when I use python3 in the command line, I cannot import pandas:

$ python3
>>> import pandas
>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'pandas'

It appears that this is in the correct location, as

which python3 

is in the following location:

/opt/local/bin/python3

Executing within python3

 >>> import sys
 >>> print(sys.version)

outputs

'3.4.5 (default, Jun 27 2016, 04:57:21) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]'

Why can't I import pandas?

EDIT: I'm using pip version pip3:

pip --version

outputs

pip 8.1.2 from /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
  • what does `which pip` tell you? – jxramos Jul 19 '16 at 01:30
  • @jxramos `/opt/local/bin/pip` – ShanZhengYang Jul 19 '16 at 01:32
  • Hmm, looks same place as python3. I had issues around this sort of thing while having multiple Python versions installed and pip was installing to a version I didn't intend. Do you have python2 anyplace? Check its installed modules and maybe run a test of adding some entirely new module and see where it winds up. – jxramos Jul 19 '16 at 01:36
  • What is the output of `import sys; print(sys.path)`? – John Gordon Jul 19 '16 at 01:38
  • @JohnGordon The output is: ['', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pydot_ng-1.0.1.dev0-py3.4.egg', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mhcflurry-0.0.6-py3.4.egg', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyVCF-0.6.7-py3.4-macosx-10.11-x86_64.egg', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/distribute-0.7.3-py3.4.egg', – ShanZhengYang Jul 19 '16 at 01:45
  • @JohnGordon '/Users/shanzhengyang/src/bayesrl', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tables-3.2.4.dev0-py3.4-macosx-10.11-x86_64.egg', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4', – ShanZhengYang Jul 19 '16 at 01:47
  • @JohnGordon '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/Users/shanzhengyang/Library/Python/3.4/lib/python/site-packages', '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages'] – ShanZhengYang Jul 19 '16 at 01:47
  • I'm stuck. No idea why this doesn't work. – ShanZhengYang Jul 19 '16 at 03:48
  • google pip3 to install python 3 packages. http://stackoverflow.com/questions/34573159/how-do-install-pip3-on-my-mac – Merlin Jul 19 '16 at 03:59

1 Answers1

3

Looks like your OS uses pip2 by default. This could be checked by typing:

$ pip --version
pip 8.1.2 from /usr/local/lib/python2.7/dist-packages (python 2.7)

Try to use pip3 command like that:

sudo pip3 install pandas --upgrade
frist
  • 1,918
  • 12
  • 25
  • for `pip --version`, I get `pip 8.1.2 from /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)` This isn't the problem, I'm afraid. – ShanZhengYang Jul 19 '16 at 13:06
  • @ShanZhengYang try to do `sys.path.insert(0, '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages')` and then `import pandas`. Or start python3 with PYTHONPATH like that: `PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages:$PYTHONPATH python3` – frist Jul 19 '16 at 17:10