Simple dependency management for a Python project

I came from Java and brand new in Python.

Now I have a small project with several Python files that contain several imports. I know that the imported dependencies are not installed on my computer, so I try to find out the necessary dependencies and run pip to install them.

I would like to do it differently. I would prefer the dependencies to be listed in a single file and installed automatically during the build process.

Does this make sense? If so, I have a few questions:

  • How to list the project dependencies needed to install pip ?
  • How to run pip to install dependencies from a list?
+9
python pip dependency-management
source share
1 answer

A common dependency management method for a python project is a file in the root of the project called "requirements.txt". A simple way to do this:

 1. Setup a python virtualenv for your project 2. Manually install the required modules via pip 3. Execute `pip freeze > requirements.txt` to generate the requirements file 

Then you can install all the dependencies elsewhere using pip install -r requirements.txt .

If you want the dependencies to be installed automatically when other people pip install your package, you can use install_requires() in your setup.py .

+11
source share

All Articles