Kimmo Hintikka
Kimmo Hintikka

Reputation: 15430

How to use pip freeze >> requirement.txt properly with multiple environments

I would like to understand how to use pip with multiple environments, I have generic flask web project where my production environment needs to pip install

pip install flask psycop2 Flask-SQLAlchemy

My dev&test environment needs these and some extra stuff

pip install flask psycop2 Flask-SQLAlchemy factory-boy flake8 WebTest 

I know I could run pip freeze >> requirements/dev.txt then make file called prod.txt on the same folder cut and copy all common requirements in it and added -r prod.txt to my dev.txt for it to install prod requirements as well.

My question is, is how to pip freeze package to specific requirement.txt file while installing it let's say next I need flake8-debugger this will clearly need to go to dev.txt so how to make it happen without constant freezing to a single file and package copy pasting?

Should I just go and add flake8-debugger without a version to dev.txt and run pip install -r requirements/dev.txt or is a there more elegant workflow for this?

Upvotes: 3

Views: 2532

Answers (1)

Kimmo Hintikka
Kimmo Hintikka

Reputation: 15430

Turns out that this will never be fixed on requirements.txt system but the answer is here.

https://github.com/pypa/pipfile

With new Pipfile we can soon managed requirements similarily to ruby Gemfile or npm package.json

Pipfile

Warning: this project is under active development.

A Pipfile is a new (and much better!) way to declare dependencies for your Python environment (e.g. deployment of a web application). It will be a full replacement for the well-pervasive requirements.txt files, currently installable with $ pip install -r.

This is a concept project that will eventually be built into pip itself, once the API (including the form of a Pipfile itself) has been built out and finalized.

Remember, the important part here is Pipfile.lock. It allows deterministic builds. Today's requirements.txt can do this, and should, but often doesn't, when version specifiers aren't provided. This efforts will provide a much more pleasant user experience.

The Concept

A Pipfile will be superior to a requirements.txt file in a number of ways:

Expressive Python syntax for declaring all types of Python dependencies. Grouping of sub-dependency groups (e.g. a testing group). Use of a single file only will be extremely encouraged. Pipfile.lock Example Pipfile

Note: There will be a default source, and context manager can also be used.

source('https://pypi.org/', verify_ssl=True)

package('requests')
package('Django', '==1.6')
package('pinax', git='git://github.com/pinax/pinax.git', ref='1.4', editable=True)
dev_package('nose')

Upvotes: 2

Related Questions