Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional dependencies in a pip requirements file

How can I specify optional dependencies in a pip requirements file?

According to the pip documentation this is possible, but the documentation doesn't explain how to do it, and I can't find any examples on the web.

like image 274
del Avatar asked Sep 08 '10 03:09

del


People also ask

Does pip check for dependencies?

The pip install <package> command always looks for the latest version of the package and installs it. It also searches for dependencies listed in the package metadata and installs them to ensure that the package has all the requirements that it needs.

What are the requirements to install pip?

Install packages with pip: -r requirements.txt You can name the configuration file whatever you like, but requirements.txt is often used. Put requirements.txt in the directory where the command will be executed. If it is in another directory, specify its path like path/to/requirements.txt .

Can I put pip in requirements txt?

Use the pip install -r requirements. txt command to install all of the Python modules and packages listed in your requirements. txt file. This saves time and effort.


2 Answers

Instead of specifying optional dependencies in the same file as the hard requirements, you can create a optional-requirements.txt and a requirements.txt.

To export your current environment's packages into a text file, you can do this:

pip freeze > requirements.txt 

If necessary, modify the contents of the requirements.txt to accurately represent your project's dependencies. Then, to install all the packages in this file, run:

pip install -U -r requirements.txt 

-U tells pip to upgrade packages to the latest version, and -r tells it to install all packages in requirements.txt.

like image 151
Daniel Naab Avatar answered Sep 22 '22 18:09

Daniel Naab


In 2015 PEP-0508 defined a way to specify optional dependencies in requirements.txt:

requests[security] 

That means that yourpackage needs requests for its security option. You can install it as:

pip install yourpackage[security] 
like image 44
anatoly techtonik Avatar answered Sep 22 '22 18:09

anatoly techtonik