9

I've been trying to install astropy and at the end of the installation I get this message:

Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I have tried: pip uninstall numpy and then I get the same message. I have Python 2.7.10 in a macOS High Sierra version 13.10.5

wovano
  • 4,543
  • 5
  • 22
  • 49
  • Possible duplicate of [How to correctly uninstall numpy on MacOSX?](https://stackoverflow.com/questions/39187374/how-to-correctly-uninstall-numpy-on-macosx) – sandes Jun 21 '18 at 23:25
  • Take a look: https://github.com/pypa/pip/issues/5247 : `Try removing package manually from "site-packages". This works perfect! ` – rafaelc Jun 21 '18 at 23:25
  • 1
    @RafaelC That's linux-specific. Apple's pre-installed packages are not in site-packages, they're in a special `Extras` directory. Also, you really don't want to delete them, because they're part of the OS, and may even get reinstalled next time you run a macOS upgrade. What you need to do is trick `pip` into installing another `numpy` in front of the `Extras` one. There are multiple questions here about how to do that. (I think I even wrote the answer for the 10.11 version, but I'm not sure if it's still valid in 10.13.) – abarnert Jun 21 '18 at 23:52
  • @RafaelC At any rate, it's almost always better to not use Apple's Python at all. That wasn't true from around 10.6-10.8 or 10.9, but they've fallen farther behind, non-Apple Python packaging has gotten better, and nowadays you don't usually want Python 2.7 anyway. – abarnert Jun 21 '18 at 23:54

3 Answers3

8

This doesn't directly answer your question, but that's because you're asking the wrong question.

Astropy requires Python 3.5 or 3.6. Trying to get it working with Apple's pre-installed Python 2.7 is a waste of time. You might be able to get an old version working this way, but not by using the installation instructions on astropy.org, and it won't be supported even if you do.


The easy solution is to just Install the latest Anaconda 5.x with Python 3.6, because it comes with Astropy built in.


The almost-as-easy solution is to install Python 3.6 from either a python.org binary installer, or Homebrew, and then use pip3 or, better, python3 -m pip to install everything, as explained on the Astropy install page.


Either way, before doing anything else, you want to get back to a clean slate. In particular, you do not want pip, or any other scripts, attached to Apple's Python 2.7; they will only cause confusion. Assuming you can't reinstall macOS from scratch, the best way to do this is:

  • Look in /Library/Python/2.7/site-packages and delete everything there except for README and Extras.pth.
  • Look in /usr/local/bin for symlinks to anything in that site-packages. (If you don't know much about using Unix, try this command: ls -l /usr/local/bin | grep 2.7.) You'll probably have pip and pip2.7 here, and probably nothing else. But whatever you have here, delete it.

Now, when you install Python 3.6, the only thing named pip anywhere will be that Python 3.6's pip. You still want to use pip3 or python3 -m pip, but if you screw up and type pip by accident, it won't break anything.


Also, you should strongly consider using a virtual environment. See the Python Packaging Authority's User Guide (or the Anaconda docs, if you went that way) for more on this.

abarnert
  • 354,177
  • 51
  • 601
  • 671
6

One simple solution I found:

sudo -H pip install astropy --ignore-installed numpy
Wuzhou Zhang
  • 137
  • 2
  • 3
1

I also had this issue and couldn't get around it in a clean way, but this is what I did:

Inside the Lib folder search "numpy" for an egg_info file (eg. numpy-1.11.0.dev0_2329eae.egg-info).

In my case, this is what Pip was looking at to determine if a current version already exists. I deleted it, then ran normal

pip install numpy

and installed the newest version.

I don't recommend this because I don't understand what it's doing under the hood and it doesn't properly uninstall the old version which could be a recipe for trouble down the line, but if you're desperate like I was then maybe this is a solution for you.