如何修复从requirements.txt 文件安装所有软件包时出现的freetype 错误?

问题描述 投票:0回答:8

我运行了以下命令来安装 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

我在 Google 上搜索并找到了这篇文章:python pip TroubleInstalling fromrequirements.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

然后我尝试做

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.

有没有一种简单的方法来安装这个 python 项目所需的所有依赖项?

python pip requirements.txt freetype
8个回答
106
投票

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

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

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

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

57
投票

pip install -r requirements.txt
对于
python 2.x

pip3 install -r requirements.txt
代表
python 3.x
(如果安装了多个版本)


9
投票
python -m pip install -r requirements.txt

参考:如何根据本地目录中的requirements.txt文件使用pip安装包?


5
投票

Python 3:

pip3 install -r requirements.txt

Python 2:

pip install -r requirements.txt

获取虚拟环境或整个系统的所有依赖项:

pip freeze

将所有依赖项推送到requirements.txt (Linux):

pip freeze > requirements.txt

4
投票

取自我对另一个答案的评论

pip
不会处理系统级依赖关系。在继续之前,您必须
apt-get install libfreetype6-dev
。 (它甚至在你的输出中这么说。下次尝试略过它以查找此类错误,通常构建输出非常详细。)


0
投票

如果您想在需求文件中安装所有依赖项,例如 Node.js 项目上的

npm install

在 python 中运行以下命令:

pip3 install -r  ./requirements.txt

您可以使用

pip
pip3
都可以


0
投票

如果您使用 Linux 作为操作系统,那么您可以按照以下步骤操作:-

首先,从

matplotlib==1.3.1
 中删除 
requirements.txt

之后尝试安装它

sudo apt-get install python-matplotlib

运行

pip install -r requirements.txt
(Python 2)
pip3 install -r requirements.txt
(Python 3)

pip freeze > requirements.txt

如果您使用 Windows 作为操作系统,请执行以下步骤:

python -m pip install -U pip setuptools

python -m pip install matplotlib

查看此在 python 项目页面中安装所有依赖项。


-1
投票

我认为运行这些命令可以解决 Windows 操作系统用户的问题: 如果您使用的是 Linux 操作系统:

python -m pip install -U pip setuptools python -m pip 安装 matplotlib

© www.soinside.com 2019 - 2024. All rights reserved.