MOON
MOON

Reputation: 2801

How to keep track of dependencies in Python?

I am new to Python programming. Recently, I wrote a code which worked well. However, I needed to reinstall my Anaconda distribution and install the libraries I needed again. 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. 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?

Upvotes: 2

Views: 1018

Answers (1)

Marco Abrate
Marco Abrate

Reputation: 81

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 install <package>

And then I would just generate a requirements.txt file every time I change my dependencies with

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

pip install -r requirements.txt

Upvotes: 5

Related Questions