python - 如何使用 requirements.txt 在 python 项目中安装所有依赖项

标签 python pip requirements.txt

我是 python 新手。最近我有一个用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

有没有一种简单的方法可以在这个 python 项目中安装所有必需的依赖项?

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.

最佳答案

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

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

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

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

关于python - 如何使用 requirements.txt 在 python 项目中安装所有依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41457612/

相关文章:

python - 使用 Wing IDE 调试多线程 Python

python - 将点插入到 SQL Server 中?

python - 如何仅列出(卡住)我的项目导入/需要的 Python 模块

python - 在运行时向 docker 镜像添加 pip 要求

python - 使用 Cloud Source 存储库设置 Google Cloud Function 时出现 ModuleNotFoundError

python - 从 QAction 触发器访问委托(delegate)类

python - 从包含 dict 的 pandas 列中提取有用的信息

python - 在 venv 上安装 pip 之后出现 ModuleNotFoundError

python - 如何在 GIT 中处理 python 模块

php - 逐行比较sql表和txt文件,如果变量不存在则插入它