当前位置: 首页 > 面试题库 >

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

姜志
2023-03-14
问题内容

我是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

我在Google上搜索并找到了此链接,但我不太了解该帖子中的解决方案。

以下是我的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项目中安装所有必需的依赖项?

编辑1

以下是的输出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 OS:

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

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

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


 类似资料:
  • 我正在试用AWS Codestar。我的目标是部署一个非平凡的lambdaendpoint,即处理程序具有依赖关系的地方。理想情况下,我希望能够在文件,但这似乎不是那么简单。具体地说,我想部署一个依赖于nltk的lambda处理程序,其中nltk标记器“punkt”的文件作为代码构建过程的一部分下载,并为lambda打包。 如何通过和?下面,我试图将依赖项安装到子目录,并将其包含在zip工件中。

  • 问题内容: 我有一个Web应用程序: fooapp 。我有根。我想将所有依赖项安装在特定的中。我该怎么做呢? 我想要的是 可以说我有两个依赖项。我想以这样的目录结构结束: 我得到什么 当我跑步时, 我得到以下信息: npm在node_modules目录中复制我的应用程序目录,并将软件包安装在 另一个 node_modules目录中。 我了解这对于安装软件包很有意义。但是我不在其他地方使用Web应用

  • 安装包时(通过使用python setup.py install),依赖项从python包索引(pypi.python.org)获取。但我的目标主机无法访问internet。我已将依赖项放在本地目录下,如下所示。 通过运行?

  • 问题内容: 我已经建立了两个RPM套件 取决于存在的文件,它在RPM软件包中正确反映,如下所示: 由于缺少依赖项,安装失败。 如何确保在安装过程中自动安装? 我确实按照此处所述尝试了该选项,但对我而言不起作用。 还有其他办法吗? 谢谢你的帮助。 问题答案: 创建一个(本地)存储库,并使用它来为您解决依赖关系。 CentOS Wiki有一个漂亮的页面,提供有关此操作方法的信息。CentOS Wiki

  • 问题内容: 我正在创建 setup.py 来分发我的应用程序。该应用程序具有许多可通过pip安装的依赖项,还具有一些无法从PyPI安装的自定义依赖项。 因此,我创建了一个将包含在发行版中的,并且必须在 setup.py 从安装了所有内容之后作为依赖项进行安装。 想象以下应用程序结构: 我怎么做? 问题答案: 可能但不确定应使用哪个setuptools版本。脚步: 在setup.py中 重要的是您的

  • 我是maven的新手。(我已经搜索了几个小时的答案,但没有运气。mvn依赖:复制依赖不能解决我的问题)我需要复制项目的所有依赖项(以jar的形式),如果我的一个jar依赖于另一个工件,也复制该工件。 示例project1 pom。xml: “project1”依赖于project2。人工制品罐子当我使用“mvn依赖项:复制依赖项”时,我得到了project2。人工制品但我没有得到project3。