我明白在许多情况下,明确说明我们正在使用的依赖版本很重要,因此这也适用于嵌套依赖。
然而,当我们决定删除一个依赖项并且需要使用类似 pideptree 的东西来确定它是否有任何我们也安装的自己的依赖项时,它变得非常混乱,另外还要确保这些嵌套的依赖项没有被我们的其他依赖项使用一级依赖。
假设我们不需要冻结我们的依赖版本,包含嵌套依赖而不是让 pip 为我们处理它有什么好处?
我可以pip list -o
用来获取过时软件包的列表,但我只想获取特定需求文件中列出的过时软件包列表。基本上相当于pip freeze -r requirements.txt
过时的包。
我可以使用,--not-required
但这仍会列出已安装但未在需求文件中列出的已安装软件包。
我对 Python 中的依赖项管理不是很有经验,但似乎所有依赖项requirements.txt
都可以放在字段setup.py
下的文件中install_requires
,如下所示:
setup(
...
install_requires=['numpy=1.2.3', 'pandas=1.2.3']
...
)
Run Code Online (Sandbox Code Playgroud)
由于与 相比,pip install ./
使用setup.py
文件还提供了许多附加功能pip install -r requirements.txt
,那么后者有什么用呢?一个项目是否有正当理由同时使用两者?
我正在尝试创建一个requirements.txt
来使用pytorch
,但希望它能够在 GPU 和非 GPU 平台上工作。
我在我的 Linux GPU 系统上做了类似的事情:
--find-links https://download.pytorch.org/whl/cu113/torch_stable.html
torch==1.10.2+cu113
torchvision==0.11.3+cu113
pytorch-lightning==1.5.10
Run Code Online (Sandbox Code Playgroud)
这工作正常,软件包已安装,我可以使用支持 GPU 的 pytorch。
torch
我想知道如何为 mac 和非 GPU 用户修改此设置以安装和 的非 cuda 软件包torchvision
?我需要维护单独的requirements.txt
文件吗?
我有以下软件包的安装命令:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
Run Code Online (Sandbox Code Playgroud)
并且需要将其添加到我的requirements.txt 文件中。我通过将其添加到文件末尾来完成此操作:
-i https://download.pytorch.org/whl/cu116
torch
torchvision
torchaudio
Run Code Online (Sandbox Code Playgroud)
在满足所有其他要求之后。我现在没有办法测试它,并且需要知道我是否正确地完成了它,因为我以前从未这样做过。
这是将其添加到requirements.txt 文件的正确方法吗?
如果是的话,在这些后面添加其他包,例如numpy,会受到url的影响吗?我是否必须“清除”该网址,或者只是将其添加到它搜索的网址列表中?
任何帮助表示赞赏
这是我的要求.txt
beautifulsoup4==4.11.1
cachetools==5.2.0
certifi==2022.12.7
charset-normalizer==2.1.1
click==8.1.3
colorama==0.4.6
Flask==2.2.2
Flask-SQLAlchemy==3.0.2
google==3.0.0
google-api-core==2.10.2
google-auth==2.14.1
google-cloud-pubsub==2.13.11
googleapis-common-protos==1.57.0
greenlet==2.0.1
grpc-google-iam-v1==0.12.4
grpcio==1.51.1
grpcio-status==1.51.1
idna==3.4
importlib-metadata==5.2.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
NotFound==1.0.2
proto-plus==1.22.1
protobuf==4.21.12
psycopg2==2.9.5
pyasn1==0.4.8
pyasn1-modules==0.2.8
requests==2.28.1
rsa==4.9
six==1.16.0
soupsieve==2.3.2.post1
SQLAlchemy==1.4.45
urllib3==1.26.13
Werkzeug==2.2.2
zipp==3.11.0
Run Code Online (Sandbox Code Playgroud)
这是我的 Dockerfile
FROM python:3.10-slim
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN pip install …
Run Code Online (Sandbox Code Playgroud) 我想使用 SHA256 哈希来安装 pip 包,并且我将所有依赖项固定在requirements.in
这样的位置
apache-beam[gcp]==2.38.0
beautifulsoup4==4.10.0
bleach==4.1.0
certifi==2021.5.30
deepdiff==5.8.1
defusedxml==0.7.1
elasticsearch==7.17.0
firebase-admin==5.2.0
future==0.18.2
googledatastore==7.0.2
google-cloud-storage==2.1.0
google-auth==1.35.0
google-cloud-dataflow-client==0.3.1
google-cloud-logging==3.0.0
google-cloud-ndb==1.11.1
google-cloud-secret-manager==2.12.4
google-cloud-tasks==2.7.2
google-cloud-translate==3.6.1
gunicorn==20.1.0
html5lib==1.1
mailchimp3==3.0.15
mutagen==1.45.1
pillow==9.0.1
pylatexenc==2.10
pytest==6.2.5
PyYAML==6.0
redis==3.5.3
requests==2.26.0
requests-mock==1.9.3
requests-toolbelt==0.9.1
result==0.6.0
rsa==4.7.2
simplejson==3.17.5
six==1.16.0
soupsieve==2.3.1
typing-extensions==3.10.0.2
urllib3==1.26.7
webapp2==3.0.0b1
webencodings==0.5.1
Run Code Online (Sandbox Code Playgroud)
仅供参考,我正在使用 pip 22.1.1、python 3.8.15 和 pip-compile 6.6.2。为了生成哈希,我使用了pip-compile --generate-hashes requirements.in
然后pip install --require-hashes -r requirements.txt
启用哈希验证。但我收到这样的错误:
ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not:
google-api-core[grpc]<3.0.0dev,>=1.22.1 …
Run Code Online (Sandbox Code Playgroud) 我在github上有一个小型应用程序项目,该项目可在Windows上运行,并且需要pythonnet
。
我的requirement.txt
包含:
beautifulsoup4==4.6
pythonnet==2.3
Run Code Online (Sandbox Code Playgroud)
现在我想为它建立一个文档并放上它readthedocs.org
。将文档推送到github,将项目导入之后readthedocs.org
,我尝试构建文档,但是此操作失败,并显示以下信息:
Collecting pythonnet==2.3 (from -r /home/docs/checkouts/readthedocs.org/user_builds/trelloradar/checkouts/latest/requirements.txt (line 2))
Using cached pythonnet-2.3.0.tar.gz
Building wheels for collected packages: pythonnet
Running setup.py bdist_wheel for pythonnet: started
Running setup.py bdist_wheel for pythonnet: finished with status 'error'
Complete output from command /home/docs/checkouts/readthedocs.org/user_builds/trelloradar/envs/latest/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-iU2ADR/pythonnet/setup.py'; f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpnPH_1rpip-wheel- --python-tag cp27:
running bdist_wheel
running build
running build_ext
/bin/sh: 1: mono: not found
Traceback (most recent call …
Run Code Online (Sandbox Code Playgroud) 我有一个包已经上传到test.pypi.
我可以在我的机器上的虚拟环境中安装此软件包,而不会出现任何问题
pip install --index-url https://test.pypi.org/simple/ package_name_here
Run Code Online (Sandbox Code Playgroud)
在'requirements.txt'文件中有一个包的要求列表,这些要求也包含在setup.py中的setup dict中的'install_requires'中.
这在我的机器上工作正常.当我在我的一个组本地服务器上的干净虚拟环境中尝试相同的进程时,我收到以下错误:
Could not find a version that satisfies the requirement widgetsnbextension>=3.2.1 (from package_name_here) (from versions: )
No matching distribution found for widgetsnbextension>=3.2.1 (from package_name_here)
Run Code Online (Sandbox Code Playgroud)
对于requirements.txt文件中的许多要求.
但是当安装失败时,如果我这样做:
pip install widgetsnbextension
Run Code Online (Sandbox Code Playgroud)
pip发现并安装widgetsnbextension-3.2.1没有任何问题.
requirements.txt文件是使用pip冻结制作的,所以我很困惑为什么它可以在没有版本号的情况下工作,但不能使用它.
谁能解释一下我做错了什么?
我来自NodeJS,正在学习Python,想知道如何requirements.txt
在项目的本地文件中正确安装软件包。
对于节点,这是通过在package.json
via中管理和安装软件包来完成的npm install
。但是,Python项目的约定似乎是将软件包添加到名为的目录中lib
。当我这样做时,pip install -r requirements.txt
我认为这会在我的计算机上进行全局安装,类似于节点npm install -g
全局安装。如何将我的requirements.txt文件的依赖项安装在名为lib的文件夹中?
requirements.txt ×10
python ×9
pip ×7
dependencies ×1
docker ×1
dockerfile ×1
packaging ×1
pip-compile ×1
python-2.7 ×1
python-3.8 ×1
python-3.x ×1
pythonnet ×1
setup.py ×1
windows ×1