Numpy deprecation error while installing Pymatgen on OS X

Like recommended in the Materials Project API tutorial, I’m installing Pymatgen. I am using OS X El Capitan 10.11.4, in which Python 2.7.10 is embedded. I’m following the Pymatgen documentation, have all of the prerequisite programs, but get this error after running “python pmg_install.py” in Bash:


Installing collected packages: numpy, atomicfile, scipy
Found existing installation: numpy 1.8.0rc1
DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling numpy-1.8.0rc1:
Exception:
Traceback (most recent call last):
File “/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py”, line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-RXVPjE-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info’
Error installing pymatgen

It looks like the installation process is trying to uninstall the legacy Numpy program embedded in OS X, then maybe replace it with an updated version. I read that OS X prevents any modification of this directory where Python 2.7.10 and Numpy are located though, for fear that modification to its files will break the operating system. Therefore, installing Pymatgen as the root user or invoking the sudo command does not solve the error. I have the latest, stable version of Python 3.x installed, but the system still defaults to the 2.7.10 version during installation.

Is there a way to install Pymatgen while leaving alone OS X’s existing Python-related files?

1 Like

I recommend working in a Python virtual environment (virtualenv) and using the pip package manager for Python to install pymatgen. From your command line:

# `pip` should come installed with Python 2.7.10+
pip install virtualenv
# creates a folder `mp` in the current directory
# to store this environment's packages. To delete
# the environment, just delete the folder.
virtualenv mp
# activate the virtual environment
# (your command prompt should look different after this)
source mp/bin/activate
# install numpy into the environment (sometimes pymatgen
# installation complains if numpy isn't already installed)
pip install numpy
# install pymatgen using pip
pip install pymatgen

If you are working and can’t import pymatgen, ensure your virtual environment is activated using the source command above. Use the deactivate command (just that one word) to exit the virtual environment and use your system Python. Virtual environments are great for working on various projects with different package requirements without disturbing the system Python or using root/sudo.

1 Like

Running now, thank you!

1 Like