23
votes

For example we have some pipfile (below) and I'd like to freeze the django version. We don't have a requirements.txt and we only use pipenv. How can I freeze the django version?

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "*"

[dev-packages]
black = "*"

[requires]
python_version = "3.6"
7

7 Answers

82
votes

Pipenv do natively implement freezing requirements.txt. It is as simple as:

pipenv lock -r > requirements.txt
18
votes

Assuming you have your virtual environment activated, you have three simple approaches. I will list them from less verbose to more verbose.

pip

$ pip freeze > requirements.txt

pip3

$ pip3 freeze > requirements.txt

If a virtual environment is active, pip is most certainly equivalent to pip3.

pipenv run

$ pipenv run pip freeze > requirements.txt
$ pipenv run pip3 freeze > requirements.txt

pipenv run spawns a command installed into the virtual environment, so these commands are equivalent to the ones run without pipenv run. Once again, it is assumed that your virtual environment is active.

6
votes

By using run You can run given command from virtualenv, with any arguments forwarded

$ pipenv run pip freeze  > requirements.txt 
2
votes

It's as simple as changing django = "*" to django = "your-preferred-version". So if you wanted to freeze it to 2.1, the latest release at the time of this writing, you could do this:

[packages]
django="2.1"

The pipfile Git repo has some good examples of different ways to specify version strings: https://github.com/pypa/pipfile#pipfile

Note that when you generate a lockfile from your pipfile, that lockfile is actually the file that's supposed to "freeze" your dependency to a specific version. That way, you don't have to concern yourself with which version works with your code, since by distributing the lockfile everyone else must use the same dependency versions as you. The developers of pipenv intended for developers to use it like this

0
votes

first, you ensure that your virtual environment is active then you open the terminal and run the command pip3 freeze > reqirements.txt (pip3) pip3 freeze > reqirements.txt (pip3)

0
votes

This is the way that I was prompted by pipenv to generate a requirements.txt file from the project's Pipfile:

pipenv lock --requirements
-2
votes

You can create a requirements.txt using this command :

pip3 freeze > requirements.txt