Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing `pip` to recompile a previously installed package (numpy) after switching to a different Python binary

This question is as much a question about my particular problem (which I sort of found a work-around, so it's not a burning issue) as it is about the general process I am using.


Setup (the part that works):

I have Python 2.7.9 installed locally on my Ubuntu 14.04, and I have a virtualenv in which I am running it. Everything is very much separated from the "system" Python, which I am not touching.


The part I did:

It all started well enough, with my Python installed and all libraries running. For example, I also pip installed numpy 1.10.1, it compiled for a while, then it worked just fine.

The problem:

The problem is that for reasons beyond my control, I had to rebuild the python with ucs4 enabled, that is I installed it using

./configure --enable-unicode=ucs4

After doing this, I also uninstalled all libraries and reinstalled them using pip. However, it seems that the numpy library was not properly uninstalled because it installed instantly this time, and when I tried to import numpy into my new Python, I got an error message indicating that the numpy was compiled with the ucs2-enabled Python.

This hypothesis is pretty solid, since I tried then to pip install numpy==1.9.3. The installation once again took a long time, and it produced a numpy version that works on the new ucs4 enabled Python.

Now, my question:

How can I get the numpy uninstallation process to delete all traces of the old numpy?


Edit:

I also tried to manually remove numpy by deleting it from my virtualenv site-packages directory. After deleting, import numpy returned an ImportError as expected. I then reinstalled it (pip install numpy) and it came back with the same ucs2-related error.

Edit 2:

The full sys.path seen by my virtualenv Python is

['',
 '/home/jkralj/.virtualenvs/work/lib/python27.zip',
 '/home/jkralj/.virtualenvs/work/lib/python2.7',
 '/home/jkralj/.virtualenvs/work/lib/python2.7/plat-linux2',
 '/home/jkralj/.virtualenvs/work/lib/python2.7/lib-tk',
 '/home/jkralj/.virtualenvs/work/lib/python2.7/lib-old',
 '/home/jkralj/.virtualenvs/work/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7.9/lib/python2.7',
 '/usr/local/lib/python2.7.9/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7.9/lib/python2.7/lib-tk',
 '/home/jkralj/.virtualenvs/work/lib/python2.7/site-packages']

Also, it might be important to mention that the /usr/local/lib/python2.7.9/ installation of python does not have numpy installed.

like image 401
5xum Avatar asked Nov 12 '15 10:11

5xum


People also ask

How do I clear a cached package in Python?

If you want to force pip to clear out its download cache and use the specific version you can do by using --no-cache-dir command. If you are using an older version of pip than upgrade it with pip install -U pip. This will help you clear pip cache.

Can I install two versions of a Python package on the same computer?

With maven or gradle you can install two versions of the same package, with pip you cant. Still you cant use two versions of the same package in the same program.

Can I delete Appdata local pip cache?

If you use an older version of pip and have no access to the pip cache command, you can clear the pip cache by manually removing the cache directory.


2 Answers

You can use --no-binary and --ignore-installed to rebuild a package as follows

pip install --user --force-reinstall --ignore-installed --no-binary :all: PackageName
like image 63
Frank Breitling Avatar answered Oct 12 '22 18:10

Frank Breitling


The problem is solved by pip uninstalling numpy (or any other troublesome package), then running

pip install numpy --no-cache-dir

to prevent pip from simply taking the cached installation and repeating it.

like image 25
5xum Avatar answered Oct 12 '22 19:10

5xum