简体   繁体   English

Matplotlib要求与virtualenv中的pip安装

[英]Matplotlib requirements with pip install in virtualenv

I have a requirements.txt file like this: 我有一个这样的requirements.txt文件:

numpy
matplotlib

When I try pip install -r requirements.txt inside a new virtualvenv, I get this: 当我在新的virtualvenv中尝试pip install -r requirements.txt ,我得到了这个:

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. 如果我先安装numpy和matplotlib,它就可以了。 However I'd like to keep using pip install -r requirements.txt . 但是我想继续使用pip install -r requirements.txt Is it possible? 可能吗?

Matplotlib and pip don't seem to play together very well. Matplotlib和pip似乎并没有很好地结合在一起。 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 ). pip首先下载你的需求文件中列出的一个包,然后运行setup.py ,但它并没有真正安装它(我不太确定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 ). 问题是, matplotlib检查是否在其setup.py安装了numpy (检查本身在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). 所以在执行检查的那一刻,没有安装numpy并且matplotlib setup.py退出并收到您收到的错误消息(这可能不是一个错误,因为它可能需要numpy来构建)。

This was once addressed in pip issue #24 and issue #25 . 这曾经在pip 问题#24问题#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. 我现在要做的是首先安装numpy,然后安装我的需求文件中的所有包。

Update 12/2012 2012年12月更新

There is a new open pip issue which deals with this problem. 有一个新的开放式点子问题可以解决这个问题。

Update 04/2013 更新04/2013

The issue is closed as WONTFIX 该问题已关闭为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 . 这是库的一个已知问题,它目前正作为Matplotlib增强提议进行讨论: 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. 在它修复之前,我能想象的唯一解决方案是重新打包库以删除numpy检查。

Yes. 是。 "requirements.txt" is just a flat file from which pip can use to install packages. “requirements.txt”只是一个平面文件,pip可以用来安装包。 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: 例如,看起来你需要至少1.1,所以尝试用“numpy”改变行:

numpy==1.1 numpy的== 1.1

Or, you can use >= like this: 或者,您可以使用> =这样:

numpy>=1.1 numpy的> = 1.1

This may be what's holding you up. 这可能是什么阻碍了你。 But, AFAIK, matplotlib should have a dependency on numpy already. 但是,AFAIK,matplotlib应该已经依赖于numpy了。 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? 在setup.py或pip requirements文件中,如何控制安装包依赖项的顺序?

After playing with pip lately i realized that requirements file should be rearranged manually, preferably while generating it. 在最近玩了pip后,我意识到需要手动重新安排需求文件,最好是在生成它时。

In simple case (ie just numpy and matplotlib requires ordering), you can just reverse requrements file: pip freeze | sort -r 在简单的情况下(即只是numpymatplotlib需要订购),你可以只需要反转requrements文件: pip freeze | sort -r pip freeze | sort -r

I've just gotten used to invoking a script to repeatably set up my virtualenv; 我已经习惯了调用脚本来重复设置我的virtualenv; it involves two requirements file: one with only numpy, and a second one with everything else. 它涉及两个需求文件:一个只有numpy,另一个只有其他一切。

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. 习惯这不是一件可怕的事情,因为当您通过需求文件安装时,pip会尝试“全有或全无”。 This way, you can stage the installation so dependencies are installed first. 这样,您可以暂存安装,以便首先安装依赖项。

I made it work in virtualenv inside an iPython notebook! 我在iPython笔记本中的virtualenv中工作了!

I have 我有

ipython==2.2.0
numpy==1.8.2
matplotlib==1.4.2

It works in an iPython notebook with 它可以在iPython笔记本中使用

%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! 但它在iPython控制台中不起作用,但我非常高兴能在笔记本中绘制图形!

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. 有一次,我能够通过在virtualenv中安装一些东西来欺骗它从控制台工作,但其他东西只在全局命名空间中,但我忘了我是怎么做到的。 I just kept installing and uninstalling things. 我只是不停地安装和卸载东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM