简体   繁体   English

如何跟踪 Python 中的依赖关系?

[英]How to keep track of dependencies in Python?

I am new to Python programming.我是 Python 编程的新手。 Recently, I wrote a code which worked well.最近,我写了一个运行良好的代码。 However, I needed to reinstall my Anaconda distribution and install the libraries I needed again.但是,我需要重新安装我的 Anaconda 发行版并再次安装我需要的库。 Then the code started to break.然后代码开始中断。 The version of Python I installed wouldn't support f-strings, although I did not use openpyxl directly, but it seems Pandas needed it, and some other behaviors which I think was due to using a different version of PyQt5.我安装的 Python 的版本不支持 f-strings,虽然我没有直接使用openpyxl ,但似乎 Pandas 需要它,还有一些我认为是由于使用了不同版本的 Z8BDB75FF7B8D6003AFFDZ783 导致的其他一些行为。 How can I have a database of packages that my program uses with dependencies of said packages with their version number?我怎样才能拥有我的程序使用的软件包数据库,以及所述软件包的依赖关系及其版本号? Should I manually keep track of them, or is there some software or service to help?我应该手动跟踪它们,还是有一些软件或服务可以提供帮助?

I would generate a new virtual environment for your project我将为您的项目生成一个新的虚拟环境

python -m venv /path/to/new/virtual/env

Then I would use pip to manage my packages然后我会使用 pip 来管理我的包

pip install <package>

And then I would just generate a requirements.txt file every time I change my dependencies with然后我每次更改依赖项时都会生成一个requirements.txt文件

pip freeze > requirements.txt

At this point, if you have to move your project on another machine or in another environment, I would just re-install all dependencies from the requirements.txt file with此时,如果您必须将项目移动到另一台机器或另一个环境中,我只需重新安装requirements.txt文件中的所有依赖项

pip install -r requirements.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM