标签: requirements.txt

Pip需求文件:不安装依赖

我正在使用一些 github django 包的前沿版本,这些版本具有我不想安装的依赖项。

在开发中,在我自己的计算机上,我可以pip install在命令行中使用并使用--no-dependencies标志。但是,我的测试和生产环境需要一个用于部署目的的需求文件。不幸的是,该--no-dependencies标志不能在需求文件中使用,如下所述:https : //pip.pypa.io/en/latest/reference/pip_install.html#requirements-file-format

有没有办法告诉 pip 在使用需求文件时不要安装依赖项?

python pip requirements.txt

2
推荐指数
1
解决办法
2853
查看次数

如何使 pip 运行需求文件中的特定命令?

我想在我的requirements.txt 文件中添加行torchtorchvision以便轻松克隆,并且我将在不久的将来从一台计算机转移到另一台计算机并转移到云。

我想要一个简单的方法pip install -r requirements.txt来完成我的项目。

> pip freeze > requirements.txt
Run Code Online (Sandbox Code Playgroud)

给出类似的东西

...
torch==1.5.0
torchvision==0.6.0
...
Run Code Online (Sandbox Code Playgroud)

然而,pip install -r requirements.txt(事实上pip install torch)不起作用,相反,作为官方火炬网站,明确表示命令应该是:

pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html
Run Code Online (Sandbox Code Playgroud)

如何使需求文件反映这一点?

我的桌面是 Windows 10。


奖金问题:

我的云是基于 Linux 的。
如何使需求文件同时适合桌面和云?

python pip virtualenv requirements.txt pytorch

2
推荐指数
1
解决办法
2222
查看次数

如何从python模块安装requirements.txt文件?

我正在寻找替代方案

pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)

可用于从 python 模块安装包。我用过了

subprocess.check_call([sys.executable, "-m", "pip", "install", package])
Run Code Online (Sandbox Code Playgroud)

但是,对于安装软件包,此命令似乎仅适用于单个软件包。提前致谢。任何帮助表示赞赏。

python installation pip requirements.txt

2
推荐指数
1
解决办法
1994
查看次数

在 conda 虚拟环境中以 pip 兼容格式创建 requirements.txt

我在 Windows 10 PC 上创建了一个 conda 虚拟环境来处理一个项目。要安装所需的包和依赖项,我使用conda install <package>而不是pip install <package>按照https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html# 中提到的最佳实践在环境中使用 pip

为了分发我的软件,我选择分别针对 conda 和非 conda 用户创建一个 environment.yml 和一个 requirements.txt 文件。我能够将当前的虚拟环境导出到 yml 文件中,这样 conda 用户就得到了照顾。但是,为了让非 conda 用户能够复制相同的环境,我需要创建和共享 requirements.txt 文件。可以使用创建此文件,conda list --export > requirements.txt但此格式与 pip 不兼容,其他用户无法pip install -r requirements.txt在其系统上使用。

使用pip freeze > requiremens.txt这里这里提到的解决方案。这意味着非 conda 用户可以简单地pip install -r requirements.txt在虚拟环境中执行,他们可以在没有 conda 的情况下使用 virtualenv 创建该虚拟环境。

但是,如果您生成上述样式的 requiremets.txt 文件,您最终会得到一个带有符号链接的 requirements.txt 文件。这是因为我们尝试为使用conda install而不是pip …

python pip requirements.txt conda

2
推荐指数
1
解决办法
3749
查看次数

如何删除requirements.txt中不需要的路径?

我目前有一个用 pip3 生成的需求文件,如下所示:

pip3 freeze > requirements.txt

通过上述命令,我得到以下requirements.txt文件:

alabaster @ file:///home/ktietz/src/ci/alabaster_1611921544520/work
appdirs==1.4.4
argh==0.26.2
argon2-cffi @ file:///C:/ci/argon2-cffi_1613037869401/work
astroid @ file:///C:/ci/astroid_1623162452381/work
async-generator @ file:///home/ktietz/src/ci/async_generator_1611927993394/work
atomicwrites==1.4.0
attrs @ file:///tmp/build/80754af9/attrs_1620827162558/work
autopep8 @ file:///tmp/build/80754af9/autopep8_1615918855173/work
Babel @ file:///tmp/build/80754af9/babel_1620871417480/work
backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work
bcrypt @ file:///C:/ci/bcrypt_1607022693089/work
beautifulsoup4==4.9.3
black==19.3b0
Run Code Online (Sandbox Code Playgroud)

鉴于上述情况,我需要做什么才能使其看起来像下面的示例?

appdirs==1.4.4
argh==0.26.2
atomicwrites==1.4.0
beautifulsoup4==4.9.3
black==19.3b0
Run Code Online (Sandbox Code Playgroud)

python requirements.txt anaconda

2
推荐指数
1
解决办法
2665
查看次数

如何在Heroku上需要不同的包到本地盒子?

我正在编写一个Python Flask应用程序来部署在Heroku上.它将使用数据库.对于本地开发,我想使用Sqlite,但是当部署到Heroku时我想使用Postgresql.我怎样才能做到这一点?

我被困了,因为我不知道如何在我的盒子和Heroku服务器之间需要一套不同的包.


这是一个Ruby应用程序,我会写在我的 Gemfile

gem "pg", :group => :production
gem "sqlite3", :group => :development
Run Code Online (Sandbox Code Playgroud)

然后Bundler将在开发和生产中安装适当的包.但我不知道Python的pip有任何类似的工作流程

python pip heroku requirements.txt

1
推荐指数
1
解决办法
516
查看次数

没有名为yaml的模块(再次破坏了我的python)

homebrew再次第三次破坏了python。我现在遇到使依赖项再次起作用的问题。此时,我无法安装yaml

Collecting yaml Could not find a version that satisfies the requirement yaml (from versions: ) No matching distribution found for yaml

有人说过尝试其他建议pyaml,但又再次尝试导入但yaml失败了。 Traceback (most recent call last): File "script.py", line 13, in <module> import pyaml File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module> import os, sys, io, yaml ImportError: No module named yaml

任何人都有一个想法如何解决这个问题?

python homebrew python-2.7 requirements.txt

1
推荐指数
1
解决办法
3928
查看次数

减少需求.txt

有没有办法减少我的requirements.txt 我一年前改用Python,那时我还没有完全理解事情是如何工作的。所以当我需要创建 requirements.txt 时,我只是做了一个 pip freeze 并复制通过了所有的要求。今天我知道我不需要它们都只是顶级的导入其他要求有没有办法实现它?

python requirements.txt

1
推荐指数
1
解决办法
1156
查看次数

`pip install -U pip -rrequirements.txt` 是否在安装需求之前升级 pip?

使用以下某些变体来设置 Python 虚拟环境似乎是常见的做法:

python -m venv venv && source ./venv/bin/activate
python -m pip install -U pip -r requirements.txt
Run Code Online (Sandbox Code Playgroud)

我希望上述命令的作用是:

  1. 升级pip
  2. 运行软件包的安装requirements.txt

然而,实际发生的情况似乎是:

  1. 收集所有包,包括最新版本pip
  2. 将它们全部安装在一起
    • 原始/过时版本pip是实际运行安装的版本
    • 并且直到执行此命令之后pip使用新版本

问题)

  1. 是否可以通过一个命令让 pip 自行升级,然后安装需求文件?
    • 这会带来什么特别的好处吗?
  2. 我应该切换到以下内容吗?
python -m venv venv && source ./venv/bin/activate
python -m pip install -U pip
python -m pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
  1. 安装需求文件的最佳方法是什么?
    • 我有时会看到人们安装/wheel升级setuptools

python pip requirements.txt python-venv

1
推荐指数
1
解决办法
3992
查看次数

将一个条目添加到requirements.txt,其中包含哈希值

我习惯于看到requirements.txt有库可选地具有关联的[最低]版本。

pandas==1.0.4
Run Code Online (Sandbox Code Playgroud)

在我现在正在处理的现有项目中,我们有这样的库条目:

argcomplete==1.12.3 \
    --hash=sha256:291f0beca7fd49ce285d2f10e4c1c77e9460cf823eef2de54df0c0fec88b0d81 \
    --hash=sha256:2c7dbffd8c045ea534921e63b0be6fe65e88599990d8dc408ac8c542b72a5445
asgiref==3.4.1; python_version >= "3.6" \
    --hash=sha256:ffc141aa908e6f175673e7b1b3b7af4fdb0ecb738fc5c8b88f69f055c2415214 \
    --hash=sha256:4ef1ab46b484e3c706329cedeff284a5d40824200638503f5768edb6de7d58e9
certifi==2021.5.30; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.6" \
    --hash=sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8 \
    --hash=sha256:2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee
cffi==1.14.6; python_version >= "3.6" \
    --hash=sha256:22b9c3c320171c108e903d61a3723b51e37aaa8c81255b5e7ce102775bd01e2c \
    --hash=sha256:f0c5d1acbfca6ebdd6b1e3eded8d261affb6ddcf2186205518f1428b8569bb99 \
    --hash=sha256:99f27fefe34c37ba9875f224a8f36e31d744d8083e00f520f133cab79ad5e819 \
    --hash=sha256:55af55e32ae468e9946f741a5d51f9896da6b9bf0bbdd326843fec05c730eb20 \
Run Code Online (Sandbox Code Playgroud)

该项目确实使用poetry- 哪个可能是文件的生成器?它是如何生成这个文件的以及如何添加我的新依赖项 - 这是pytest 7.0.0

requirements.txt python-poetry

1
推荐指数
1
解决办法
4884
查看次数

Python 在其他需求文件中引用需求

我有一个包含存储库的 pip 安装要求的文件(requirements.txt)。为了进行测试,我有另一个文件(requirements_tests.txt),它应该包含相同的要求和更多内容。我可以从requirements_tests.txt中引用requirements.txt吗?

python pip requirements.txt

0
推荐指数
1
解决办法
1329
查看次数

由于requirements.txt 中的问题,Heroku 中的部署失败

我正在尝试在 heroku 上部署我的 Flask 应用程序。我使用的是 Conda,并使用命令“pip freeze>requirements.txt”来生成requirements.txt 文件。但是当我将代码推送到heroku git时,它不断显示requirements.txt错误。我还注意到我的requirements.txt 有点奇怪。请帮助我解决这个问题。

这是我的Requirements.txt 文件:

argon2-cffi @ file:///D:/bld/argon2-cffi_1596630042503/work
attrs==19.3.0
backcall @ file:///home/conda/feedstock_root/build_artifacts/backcall_1592338393461/work
backports.functools-lru-cache==1.6.1
bleach @ file:///home/conda/feedstock_root/build_artifacts/bleach_1588608214987/work
brotlipy==0.7.0
certifi==2020.6.20
cffi @ file:///D:/bld/cffi_1595805794566/work
chardet==3.0.4
chart-studio==1.1.0
click==7.1.2
colorama==0.4.3
colorlover==0.3.0
cryptography @ file:///D:/bld/cryptography_1595349005639/work
cufflinks==0.17.3
dash @ file:///home/conda/feedstock_root/build_artifacts/dash_1596870105808/work
dash-core-components @ file:///home/conda/feedstock_root/build_artifacts/dash-core-components_1596203643601/work
dash-html-components==1.0.3
dash-renderer @ file:///home/conda/feedstock_root/build_artifacts/dash-renderer_1596203647496/work
dash-table @ file:///home/conda/feedstock_root/build_artifacts/dash-table_1596867885662/work
decorator==4.4.2
defusedxml==0.6.0
entrypoints==0.3
Flask==1.1.2
Flask-Compress==1.5.0
future==0.18.2
gunicorn==20.0.4
idna @ file:///home/conda/feedstock_root/build_artifacts/idna_1593328102638/work
importlib-metadata @ file:///D:/bld/importlib-metadata_1593211580034/work
ipykernel @ file:///D:/bld/ipykernel_1595447084845/work/dist/ipykernel-5.3.4-py3-none-any.whl
ipython @ file:///D:/bld/ipython_1596256504166/work
ipython-genutils==0.2.0
ipywidgets==7.5.1
itsdangerous==1.1.0
jedi==0.15.2
Jinja2==2.11.2
jsonschema==3.2.0
jupyter-client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1594732094290/work
jupyter-core==4.6.3
MarkupSafe==1.1.1 …
Run Code Online (Sandbox Code Playgroud)

python pip heroku requirements.txt anaconda

-3
推荐指数
1
解决办法
1707
查看次数