[python] Installing Pandas on Mac OSX

I'm having trouble installing the Python Pandas library on my Mac OSX computer.

I type the following in Terminal:

$ sudo easy_install pandas

But then I get the following:

Searching for pandas
Reading http://pypi.python.org/simple/pandas/
Reading http://pandas.pydata.org
Reading http://pandas.sourceforge.net
Best match: pandas 0.9.0
Downloading http://pypi.python.org/packages/source/p/pandas/pandas-
0.9.0.zip#md5=04b1d8e11cc0fc30ae777499d89003ec
Processing pandas-0.9.0.zip
Writing /tmp/easy_install-ixjbQO/pandas-0.9.0/setup.cfg
Running pandas-0.9.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ixjbQO/pandas-
0.9.0/egg-dist-tmp-EGREoT
warning: no files found matching 'setupegg.py'
no previously-included directories found matching 'doc/build'
warning: no previously-included files matching '*.so' found anywhere in distribution
warning: no previously-included files matching '*.pyd' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files matching '.git*' found anywhere in distribution
warning: no previously-included files matching '.DS_Store' found anywhere in distribution
warning: no previously-included files matching '*.png' found anywhere in distribution
unable to execute gcc: No such file or directory
error: Setup script exited with error: command 'gcc' failed with exit status 1

I do have Xcode and gcc installed, however, gcc is only found when I type:

$ gcc
-bash: gcc: command not found

$ gcc-4.2
i686-apple-darwin11-gcc-4.2.1: no input files

What should I do?

This question is related to python pandas

The answer is


Install pip.

Then install pandas with pip:

pip install pandas

pip install pandas works fine with pip 18.0 on macOS 10.13.6. In addition, to work with Xlsx files, you will need xlrd installed.


You need to install XCode AND you need to make sure you install the command line tools for XCode so you can get gcc.


In Mac terminal (we can launch Mac Terminal by searching in spotlight search Command + space) Now, use the command:

pip3 install pandas

As I'm using Python Version 3 I need to use pip3 install pandas.

If you are using python version 2 than use Command:

pip install pandas

Make sure pip is already installed in the device


I believe you need a sim link

$ ln -s gcc gcc-4.2

This should tell your terminal to call gcc-4.2 when you run $ gcc.


I would recoment using macport or fink to install pandas:

  1. Install XCode from App Store, this will install 3 compilers, clang, gcc ("apple") and gcc ("normal")
  2. Install macports (www.macports.org) or fink (www.finkproject.org)
  3. Never use your mac python again, and install all python modules trough the fink/macport and enjoy it taking care dependencies for you.

Installing pandas in macports is as simple as: sudo port install py27-pandas

you usualy install macport in /opt/local and fink in /sw, I would advice (though this may be bad advice) you to symlink your fink/mac ports python to your system python as follows such that: /usr/bin/python -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7


You can install python with homebrew:

brew install python

Make sure that OSX uses the correct path:

which python

Then you can use the pip tool to install pandas:

pip install pandas

Make sure that all dependencies are installed. I followed this tutorial: http://penandpants.com/2013/04/04/install-scientific-python-on-mac-os-x/

Works fine on my machine.


Write down this and try to import pandas again!

import sys
!{sys.executable} -m pip install pandas

It worked for me, hope will work for you too.


Not an innovative way but below two steps might save a ton of time and energy.

  1. Updating (Installing Command Line Tool) Code.

This can be done by openinig XCode -> Menu -> Preference -> Components -> Command Line Tool

  1. Removing all but Python 2.7

I did installed different instances of python at different time and removing all but 2.7 was helpful in my case. Note : You may have to install modules after doing it. So get ready with pip/easy_install/ports.

Uninstall can be done with super easy steps mentioned in following link.

How to uninstall Python 2.7 on a Mac OS X 10.6.4?


pip install worked for me, and it failed with a permission issue, which was resolved when I used

sudo pip install pandas

I see that the best sudo workaround is from /tmp: Is it acceptable and safe to run pip install under sudo?


Try

pip3 install pandas 

from terminal. Maybe your original pip install pandas is referencing anaconda distribution


You need to install newest version of xCode from appStore. It contains the compiler for C(gcc) and C++(g++) for mac. Then you can install pandas without any problem. Use the following commands in terminal:

  1. xcode-select --install

  2. pip3 install pandas

It might take some time as it installs other packages too. Please be patient.