Python requirements.txt

陌路散爱 提交于 2020-02-02 09:44:33

Python requirements.txt

1. Requirements Files

Requirements Files are files containing a list of items to be installed using pip install like so:
Requirements Files 是包含要使用 pip install 安装的项目列表文件,如下所示:

pip install -r requirements.txt
pip install -i https://pypi.doubanio.com/simple/ -r requirements.txt

pip3 install -r requirements.txt
pip3 install -i https://pypi.doubanio.com/simple/ -r requirements.txt

Logically, a Requirements File is just a list of pip install arguments placed in a file. Note that you should not rely on the items in the file being installed by pip in any particular order.
从逻辑上讲,Requirements File 只是放置在文件中的 pip install 参数的列表。请注意,您不应依赖于 pip 以任何特定顺序安装的文件中的项目。

Requirements Files are used to hold the result from pip freeze for the purpose of achieving repeatable installations. In this case, your Requirements Files contains a pinned version of everything that was installed when pip freeze was run.
Requirements Files 用于保存 pip freeze 的结果,以实现可重复的安装。在这种情况下,您的Requirements Files 包含运行 pip freeze 时安装的所有内容的固定版本。

pip freeze > requirements.txt
pip install -r requirements.txt

pip3 freeze > requirements.txt
pip3 install -r requirements.txt
strong@foreverstrong:~/Desktop/upload$ pip freeze > requirements.txt
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
strong@foreverstrong:~/Desktop/upload$
absl-py==0.7.1
adium-theme-ubuntu==0.3.4
attrs==15.2.0
autobahn==0.10.3
backports-abc==0.5
backports.functools-lru-cache==1.4
backports.shutil-get-terminal-size==1.0.0
backports.weakref==1.0rc1
bleach==1.5.0
certifi==2019.9.11
chardet==3.0.4
cloudpickle==1.2.1
colour==0.1.5
configparser==3.5.0
cryptography==1.2.3
cycler==0.10.0
Cython==0.28.2
decorator==4.1.2
descartes==1.1.0
entrypoints==0.2.3
enum34==1.1.6
funcsigs==1.0.2
functools32==3.2.3.post2
futures==3.2.0
goto==1.0
grpcio==1.22.0
heatmap==2.2.1
hmmlearn==0.2.0
html5lib==0.9999999
idna==2.8
imutils==0.4.6
ipaddress==1.0.16
ipykernel==4.8.2
ipython==5.7.0
ipython-genutils==0.2.0
ipywidgets==7.2.1
Jinja2==2.10
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-core==4.4.0
lxml==4.2.3
lz4==0.7.0
Markdown==2.6.9
MarkupSafe==1.0
matplotlib==2.1.1
meld==3.14.2
mistune==0.8.3
mock==2.0.0
mpi4py==1.3.1
msgpack-python==0.4.6
mvnc==2.5.0.2
Naked==0.1.31
nbconvert==5.3.1
nbformat==4.4.0
networkx==2.0
notebook==5.5.0
numpy==1.16.3
olefile==0.44
opencv-python==3.4.1.15
PAM==0.4.2
pandas==0.23.4
pandocfilters==1.4.2
pathlib2==2.3.2
pbr==3.1.1
pexpect==4.6.0
pickleshare==0.7.4
Pillow==4.3.0
poster==0.8.1
progress==1.5
prompt-toolkit==1.0.15
protobuf==3.9.0
psutil==5.4.0
ptyprocess==0.5.2
pyasn1==0.1.9
pyasn1-modules==0.0.7
pycrypto==2.6.1
Pygments==2.2.0
pygobject==3.20.0
pyOpenSSL==0.15.1
pyparsing==2.2.0
pyserial==3.0.1
Pyste==0.9.10
python-dateutil==2.6.1
python-snappy==0.5
pytz==2017.3
PyWavelets==0.5.2
PyYAML==5.1.2
pyzmq==17.0.0
qtconsole==4.3.1
requests==2.22.0
runcython==0.2.5
scandir==1.7
scikit-image==0.14.3
scikit-learn==0.19.1
scipy==1.0.0
Send2Trash==1.5.0
service-identity==16.0.0
Shapely==1.6.4.post1
shellescape==3.4.1
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.11.0
subprocess32==3.2.7
tensorflow-gpu==1.4.0
tensorflow-tensorboard==0.4.0
terminado==0.8.1
testpath==0.3.1
tornado==5.0.2
traitlets==4.3.2
trollius==2.0.1
Twisted==16.0.0
txaio==1.0.0
unity-lens-photos==1.0
urllib3==1.25.6
virtualenv==15.1.0
wcwidth==0.1.7
Werkzeug==0.12.2
widgetsnbextension==3.2.1
zope.interface==4.1.3
strong@foreverstrong:~/Desktop/upload$ pip3 freeze > requirements.txt
You are using pip version 8.1.1, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~/Desktop/upload$ 
absl-py==0.6.1
apturl==0.5.2
astor==0.7.1
beautifulsoup4==4.4.1
bleach==1.5.0
blinker==1.3
Brlapi==0.6.4
chardet==2.3.0
checkbox-support==0.22
click==6.7
command-not-found==0.3
cryptography==1.2.3
cycler==0.10.0
Cython==0.26
decorator==4.3.0
defer==1.0.6
enum34==1.1.6
feedparser==5.1.3
Flask==0.12.2
Flask-Login==0.4.1
gast==0.2.0
graphviz==0.8
grpcio==1.16.1
guacamole==0.9.2
h5py==2.7.0
html5lib==0.9999999
httplib2==0.9.1
idna==2.0
itsdangerous==0.24
Jinja2==2.10
joblib==0.14.1
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
language-selector==0.1
louis==2.6.4
lxml==3.5.0
Mako==1.0.3
Markdown==2.6.8
MarkupSafe==1.0
matplotlib==2.0.2
memory-profiler==0.55.0
mock==3.0.5
mvnc==2.5.0.2
networkx==2.1
nose==1.3.7
numpy==1.13.3
oauthlib==1.0.3
objgraph==3.4.1
onboard==1.2.0
opencv-contrib-python==3.3.1.11
opencv-python==3.3.1.11
padme==1.1.1
pandas==0.24.2
pexpect==4.0.1
Pillow==3.1.2
plainbox==0.25
progress==1.5
protobuf==3.9.0
psutil==5.6.3
ptyprocess==0.5
pyasn1==0.1.9
pycups==1.9.73
pycurl==7.43.0
pygobject==3.20.0
pygraphviz==1.5
PyJWT==1.3.0
PyMySQL==0.7.11
pyparsing==2.0.3
PyQt5==5.12
PyQt5-sip==4.19.15
python-apt==1.1.0b1+ubuntu0.16.4.5
python-dateutil==2.6.1
python-debian==0.1.27
python-systemd==231
python-xlib==0.14
pytz==2017.3
PyWavelets==0.5.2
pyxdg==0.25
PyYAML==3.11
reportlab==3.3.0
requests==2.9.1
runcython3==0.2.7
scikit-image==0.13.0
scikit-learn==0.21.3
scipy==0.17.0
sessioninstaller==0.0.0
Shapely==1.7.0
six==1.10.0
sklearn==0.0
ssh-import-id==5.5
system-service==0.3
tensorboard==1.12.2
termcolor==1.1.0
ubuntu-drivers-common==0.0.0
ufw==0.35
unattended-upgrades==0.1
unity-scope-calculator==0.1
unity-scope-chromiumbookmarks==0.1
unity-scope-colourlovers==0.1
unity-scope-devhelp==0.1
unity-scope-firefoxbookmarks==0.1
unity-scope-gdrive==0.7
unity-scope-manpages==0.1
unity-scope-openclipart==0.1
unity-scope-texdoc==0.1
unity-scope-tomboy==0.1
unity-scope-virtualbox==0.1
unity-scope-yelp==0.1
unity-scope-zotero==0.1
urllib3==1.13.1
usb-creator==0.3.0
virtualenv==16.6.2
Werkzeug==0.14.1
xdiagnose==3.8.4.1
xkit==0.0.0
XlsxWriter==0.7.3

Requirements Files are used to force pip to properly resolve dependencies. As it is now, pip doesn’t have true dependency resolution, but instead simply uses the first specification it finds for a project. E.g. if pkg1 requires pkg3>=1.0 and pkg2 requires pkg3>=1.0,<=2.0, and if pkg1 is resolved first, pip will only use pkg3>=1.0, and could easily end up installing a version of pkg3 that conflicts with the needs of pkg2. To solve this problem, you can place pkg3>=1.0,<=2.0 (i.e. the correct specification) into your requirements file directly along with the other top level requirements. Like so:
Requirements Files 用于强制 pip 正确解决依赖关系。到目前为止,pip 尚无真正的依赖关系解决方案,而只是使用它为项目找到的第一个规范。例如,如果 pkg1 要求 pkg3 >= 1.0,而 pkg2 要求 pkg3 >= 1.0,<= 2.0,并且如果先解析 pkg1,则 pip 将仅使用 pkg3 >= 1.0,并且很容易最终安装与 pkg2 需求冲突的 pkg3 版本。要解决此问题,您可以将 pkg3>=1.0,<=2.0 (即正确的规范) 直接与其他顶级需求一起放入您的需求文件中。像这样:

pkg1
pkg2
pkg3>=1.0,<=2.0

Requirements Files are used to force pip to install an alternate version of a sub-dependency. For example, suppose ProjectA in your requirements file requires ProjectB, but the latest version (v1.3) has a bug, you can force pip to accept earlier versions like so:
Requirements Files 用于强制 pip 安装子依赖项的备用版本。例如,假设您的需求文件中的 ProjectA 需要 ProjectB,但是最新版本 (v1.3) 有一个错误,您可以强制 pip 接受早期版本,如下所示:

ProjectA
ProjectB<1.3

Requirements Files are used to override a dependency with a local patch that lives in version control.
Requirements Files 用于使用版本控制中存在的本地补丁覆盖依赖性。

It’s important to be clear that pip determines package dependencies using install_requires metadata, not by discovering requirements.txt files embedded in projects.
请务必注意,pip 使用 install_requires 元数据来确定软件包的依赖关系,而不是通过发现项目中嵌入的 requirements.txt 文件来确定。

References

https://pip.pypa.io/en/stable/reference/pip_freeze/
https://pip.pypa.io/en/stable/user_guide/
https://pip.pypa.io/en/stable/reference/pip_install/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!