2017-01-04 79 views
13

我是python的新手。最近我得到了一个由python编写的项目,它需要一些安装。我运行下面的命令来安装,但有一个错误。如何使用requirements.txt在python项目中安装所有依赖关系

# pip install requirements.txt 
Collecting requirements.txt 
    Could not find a version that satisfies the requirement requirements.txt (from versions:) 
No matching distribution found for requirements.txt 

我搜索谷歌和发现这个链接http://stackoverflow.com/questions/28167987/python-pip-trouble-installing-from-requirements-txt但我不太明白是什么在该职位的解决方案。

下面是我的requirements.txt文件:

# cat requirements.txt 
ordereddict==1.1 
argparse==1.2.1 
python-dateutil==2.2 
matplotlib==1.3.1 
nose==1.3.0 
numpy==1.8.0 
pymongo==3.3.0 
psutil>=2.0 

有没有安装所有需要的依赖在这条巨蟒项目一个简单的方法?

EDIT1

下面是从pip3 install -r requirements.txt输出。

# pip3 install -r requirements.txt 
Requirement already satisfied: ordereddict==1.1 in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 1)) 
Collecting argparse==1.2.1 (from -r requirements.txt (line 2)) 
    Using cached argparse-1.2.1.tar.gz 
Collecting python-dateutil==2.2 (from -r requirements.txt (line 3)) 
    Using cached python-dateutil-2.2.tar.gz 
Collecting matplotlib==1.3.1 (from -r requirements.txt (line 4)) 
    Using cached matplotlib-1.3.1.tar.gz 
    Complete output from command python setup.py egg_info: 
    ============================================================================ 
    Edit setup.cfg to change the build options 

    BUILDING MATPLOTLIB 
       matplotlib: yes [1.3.1] 
        python: yes [3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 
          5.4.0 20160609]] 
        platform: yes [linux] 

    REQUIRED DEPENDENCIES AND EXTENSIONS 
        numpy: yes [version 1.11.3] 
        dateutil: yes [using dateutil version 2.6.0] 
        tornado: yes [tornado was not found. It is required for the 
          WebAgg backend. pip/easy_install may attempt to 
          install it after matplotlib.] 
       pyparsing: yes [using pyparsing version 2.1.10] 
        pycxx: yes [Official versions of PyCXX are not compatible 
          with Python 3.x. Using local copy] 
        libagg: yes [pkg-config information for 'libagg' could not 
          be found. Using local copy.] 
        freetype: no [The C/C++ header for freetype2 (ft2build.h) 
          could not be found. You may need to install the 
          development package.] 
         png: yes [pkg-config information for 'libpng' could not 
          be found. Using unknown version.] 

    OPTIONAL SUBPACKAGES 
       sample_data: yes [installing] 
        toolkits: yes [installing] 
        tests: yes [using nose version 1.3.7] 

    OPTIONAL BACKEND EXTENSIONS 
        macosx: no [Mac OS-X only] 
        qt4agg: no [PyQt4 not found] 
        gtk3agg: no [gtk3agg backend does not work on Python 3] 
       gtk3cairo: no [Requires cairo to be installed.] 
        gtkagg: no [Requires pygtk] 
        tkagg: no [TKAgg requires Tkinter.] 
        wxagg: no [requires wxPython] 
         gtk: no [Requires pygtk] 
         agg: yes [installing] 
        cairo: no [cairo not found] 
       windowing: no [Microsoft Windows only] 

    OPTIONAL LATEX DEPENDENCIES 
        dvipng: no 
       ghostscript: no 
        latex: no 
        pdftops: no 

    ============================================================================ 
          * The following required packages can not be built: 
          * freetype 

    ---------------------------------------- 
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-don4ne_2/matplotlib/ 

我已经安装libfreetype6-dev但PIP命令仍然报告缺少这种依赖性。

# apt-get install libfreetype6-dev 
Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
libfreetype6-dev is already the newest version (2.6.1-0.1ubuntu2). 
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded. 
+8

'PIP安装-r requirements.txt' – MrLeeh

+0

我已经更新了输出到包括与-r标志输出但仍然无法安装。 –

+0

所以现在阅读新的输出并认为 - 不要等我们。输出中的 – furas

回答

8

如果您使用的是Linux操作系统:

  1. requirements.txt
  2. 删除 matplotlib==1.3.1
  3. 尝试用sudo apt-get install python-matplotlib
  4. 运行pip install -r requirements.txt(Python的2),或pip3 install -r requirements.txt(Python 3中)
  5. pip freeze > requirements.txt
  6. 安装

如果您使用的是Windows操作系统:

  1. python -m pip install -U pip setuptools
  2. python -m pip install matplotlib
+3

您好Nilesh,欢迎来到堆栈溢出。将来,请包括解释你在答案中给出的命令,而不是告诉人们运行命令。 – yakatz

4

pip install -r requirements.txtpython 2.x

pip3 install -r requirements.txtpython 3.x(如果安装了多个版本)

+0

我试过但仍然失败。我已经发布了这个命令的输出。 –

+0

我认为安装MATPLOTLIB时缺少必需的依赖'freetype'。尝试安装依赖项并再次运行pip install -r requirements.txt。 –

+0

'pip'不会处理系统级依赖关系。在继续之前,你必须'apt-get install libfreetype6-dev'。 (它甚至在你的输出中说得很对,下次尝试浏览这些错误,通常编译输出非常详细) –

0

(从我的评论两者)

pip不会处理系统级的依赖性。继续之前,您必须先登录apt-get install libfreetype6-dev。 (它甚至说,在你的输出,以正确的尝试下一次一掠而过它这样的错误,通常是建立输出是非常详细。)

+0

我已经安装了libfreetype6-dev。但点子仍然报告这个错误。 –

+0

你有没有看到这个错误? https://github.com/matplotlib/matplotlib/issues/3029/ –

相关问题