I have a requirements.txt file like this:
numpy
matplotlib
When I try pip install -r requirements.txt inside a new virtualvenv, I get this:
REQUIRED DEPENDENCIES
numpy: no
* You must install numpy 1.1 or later to build
* matplotlib.
If I install numpy first and matplotlib after, it works. However I'd like to keep using pip install -r requirements.txt. Is it possible?
Matplotlib and pip don't seem to play together very well. So I don't think it is possible in this case.
pip first downloads a package listed in your requirements file and than runs setup.py, but it doesn't really install it (I'm not quite sure about the internals of pip). After all packages are prepared in this way, they are installed.
The problem is, that matplotlib checks if numpy is installed in its setup.py (the check itself is defined in setupext.py). So at the moment the check is performed, numpy is not installed and the matplotlib setup.py exits with the error message you received (This may not be a bug, as it may require numpy to build).
This was once addressed in pip issue #24 and issue #25. The issues are closed but give some more details.
What I am doing up to now is to first install numpy and than install all packages from my requirements file.
Update 12/2012
There is a new open pip issue which deals with this problem.
Update 04/2013
The issue is closed as WONTFIX
It's a known problem of the library and it's currently being discussed as a Matplotlib enhancement proposal: https://github.com/matplotlib/matplotlib/wiki/MEP11.
Until it's fixed the only solution I can imagine is repackaging the library to remove the numpy check.
Yes. "requirements.txt" is just a flat file from which pip can use to install packages. In that file, you can change the version of the dependencies. For example, it looks like you need at least 1.1, so try changing the line with 'numpy' to be:
numpy==1.1
Or, you can use >= like this:
numpy>=1.1
This may be what's holding you up. But, AFAIK, matplotlib should have a dependency on numpy already. Seems like that may need to be fixed.
See also this How to pip install a package with min and max version range?
and
In setup.py or pip requirements file, how to control order of installing package dependencies?
After playing with pip lately i realized that requirements file should be rearranged manually, preferably while generating it.
In simple case (i.e. just numpy and matplotlib requires ordering), you can just reverse requrements file: pip freeze | sort -r
I've just gotten used to invoking a script to repeatably set up my virtualenv; it involves two requirements file: one with only numpy, and a second one with everything else.
It's not a terrible thing to get used to, since pip will try to do 'all or nothing' when you install via a requirements file. This way, you can stage the installation so dependencies are installed first.
I made it work in virtualenv inside an iPython notebook!
I have
ipython==2.2.0
numpy==1.8.2
matplotlib==1.4.2
It works in an iPython notebook with
%matplotlib inline
from pylab import *
plot([1,2,3])
It does not work in an iPython console, though, but I am perfectly happy to do my graphing in the notebook!
At one point I was able to trick it into working from the console by installing some thing in the virtualenv, but other things only in the global namespace, but I forgot how I did it. I just kept installing and uninstalling things.
Related
After having try many times and after searching a lot, I still don't manage to use opencv-python. Actually, import cv2 works for me, but when I want to make this file working, I got this message
Importing the multiarray numpy extension module failed
Do you have an idea of what is going on ?
In Python, OpenCV images are using the same data representation as Numpy arrays. It's quite frequent to use numpy logic on OpenCV images and vice versa.
So first thing to check is that you have numpy installed.
Assuming you have numpy installed, maybe you mixed pip and conda commands to install opencv and numpy ? It's generally something to avoid unless you really know what you are doing.
You can run pip list and conda list to have a quick overview of installed packages.
Using pip only is good enough in most cases, a lot of prebuild python wheels for Windows are available on pip, including opencv-python and numpy.
After cleaning conda installed packages, try to run :
pip install --upgrade --force-reinstall numpy to make a clean numpy install.
I am trying to install psutil with the command pip install -U psutil and that gives me the error:
Cannot uninstall 'psutil'. 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.
It seems like this is a known issue in pip with versions > 10, and I understand that part (I currently have pip 18). But I just found that I can solve it by directly doing a pip install psutil without using the Upgrade flag. I was wondering if there is a reasoning behind that. My initial sense is that in the first case, where pip tries to upgrade, it first tries to remove the package, which it cannot, but in the latter case it tries to install directly, and hence does not get the error. My question is does it still not have to remove the package first and install (when not using the Upgrade flag), or why specifically is it that pip gives an error with an Upgrade flag but no error without it.
EDIT: So, I tried to run pip install -v psutil as hoefling suggested, and I got a whole bunch of text, as opposed to saying that requirements already met, which means that psutil didn't get installed in the first place. I tried to figure this a bit, and this is what I understand so far: I was running inside a python virtualenv and installing it by means of pip -U -r requirements.txt where requirements.txt contains a bunch of packages including psutil. When I remove the -U flag, it skips installing psutil, and jumps over to other packages. Which raises another question, whether this is how pip is supposed to behave when there is no -U flag. Its interesting that the first time, when its installing the packages with the -U flag, it looks inside the main python installation instead of the virtual environment one, and when the -U flag is removed it doesn't do that and skips entirely.
There are some setups where you have a bunch of packages installed somewhere that isn't the normal install location for setuptools, and comes after the normal install location on sys.path.
Probably the most common of these setups is Apple's pre-installed Python 2.7, so I'll use it as an example. Even if that isn't your setup, it will be hopefully still be instructive.
Apple includes an Extras directory (at /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python), with a bunch of third-party packages that either Apple's own tools need, or that Apple thought you might want (back when Apple cared about providing the best Python experience of any platform).
For example, on macOS 10.13, that directory will include NumPy 1.8.0.
These packages are all installed as distribute-style eggs.
(Some linux distros do, or at least used to do, similar things, with Python packages built as RPM/DEB/etc. packages, which go into adistutils directory, unlike things you install via pip or manually, which go into a setuptools directory. The details are a bit different, but the effects, and the workaround, end up being the same.)
If you install pip, and then try to pip install -U numpy or pip uninstall numpy, pip will see the distribute-style numpy-1.8.0rc1-py2.7.egg-info file and refuse to touch it for fear of breaking everything.
If you just pip install numpy, however, it will look only in the standard site-packages installation location used by setuptools, /Library/Python/2.7/site-packages, see nothing there, and happily install a modern version of NumPy for you.
And, because /Library/Python/2.7/site-packages comes before /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python on your sys,path, the new NumPy will hide the ancient NumPy, and everything will just work as intended.
There can be a few problems with this. Most notably, if you try to install something which isn't included in Extras itself, but which has a dependency that is included in Extras, it may fail with mysterious and hard-to-debug errors. For example, on macOS 10.12, pip install pandas will throw a bunch of errors at you about not being able to upgrade dateutil, which you didn't even know you were trying to do. The only thing you can do is look at the dependencies for pandas, see which ones are pre-installed in Extras, and manually pip install shadowing versions of all of them.
But, for the most part, it works.
We have set up a local python package server for your internal python packages and serve also some packages which are hard to compile on windows. As numpy is one of these packages, there exist now two versions of numpy on our server:
numpy-1.13.0-cp35-none-win32.whl
numpy-1.13.0+mkl-cp35-cp35m-win32.whl
How can I instruct pip to install a specific version of these two? Running pip install numpy will pick the package with "mkl", but for some projects I want numpy without "mkl".
Edit:
The only way which works is the full URL to the package, which seems a little bit verbose.
From what I can remember, it's just a matter of writing the package's entire name.
If you need a guide:
https://pip.pypa.io/en/stable/reference/pip_install/#examples
What's the difference between
pip install numpy
and
pip install --upgrade numpy.
When I tried to use the first one to install the NumPy module in Python 3.5.2, it wasn't recognised, but when I used the second, there were no problems.
Well, the first expression is used to install a new package, numpy in this case, at the last available version (if not specified)
If you want install a particular version, for example the 1.12.0b1, you can use the following command:
pip install numpy==1.12.0b1
Finally, the --upgrade or -U param, upgrades all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.
upgrade-strategy is another parameter that you can find in the relative doc.
Since you don't have added information about errors, is difficult understand what is the real problem. I mean, the expression it wasn't recognised and there were no problems are not very clear. I suggest you to edit you question with some information.
Anyway, I suppose that you have already installed numpy on your pc, maybe in some past attempt. To verify this run the command:
pip freeze
and check if there is numpy in the installed package list.
If yes, I think that this is the reason because pip install numpy doesn't work and instead pip install --upgrade numpy yes. Basically you are not installing numpy but upgrading it, because is already installed.
Let me know.
First expression just verify if module installed. The installation will stop if module has outdated version.
Second expression will install last released or upgrade already installed package to last released version.
More info you can get from the docs
I'm using pip to install modules from a requirements file produced with pip freeze. However the problem sometimes it's unable to install or download one module and then everything fails and doesn't install anything. Is there a way to make it install the modules that satisfy the requirements?
With pip only, I would say no. pip and Python packages generally are designed to work in such a way that you might need dependencies installed in order to install the package itself. Thus, they don't have an option to try despite of failures.
However, pip install -r requirements.txt simply goes through the file line-by-line. You can iterate the every single item yourself and call pip install for it, without caring the result (was the installation successfully or not). With shell scripting this could be done e.g.:
cat requirements.txt|xargs pip install
The example does not understand comments, spaces, etc. so you might need to how something more complex in place for a real-life scenario.
Alternative you can simply run pip in loop until it gives a successful return value.
But as a real solution I would recommend you to set up your own Python package mirror server, or a local cache - which would be another question.