59

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"

11 Answers 11

114

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

pipenv lock -r > requirements.txt
1
84

As of v2022.8.13 of pipenv, the "old" lock -r functionality has been removed.

Going forward, this should be accomplished with:

pipenv requirements > requirements.txt
1
29

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.

18

Recent pipenv versions (e.g. version 2022.6.7) are using the requirements subcommand and pipenv lock -r is deprecated.

To freeze default dependencies

pipenv requirements > requirements.txt

to freeze development dependencies as well

pipenv requirements --dev > dev-requirements.txt
0
12

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

$ pipenv run pip freeze  > requirements.txt 
1
  • It gave FileNotFoundError: [Errno 2] No such file or directory trying to look for pip file in the .venv directory for the respective project. Instead following worked for me : pipenv run python -m pip freeze > requirements.txt
    – Dhwanit
    Dec 3, 2022 at 15:26
1

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

3
  • 2
    Is there a way to do this through pipenv? Or do I have to open up the pipfile myself?
    – arshbot
    Aug 14, 2018 at 20:33
  • 1
    That's weird, it's an == sign
    – arshbot
    Aug 14, 2018 at 20:43
  • 9
    This answer did not work for me (regarding the Pipfile. What worked for me was django = "==2.1". Sep 28, 2018 at 6:56
1

Use this as -r flag is deprecated

pipenv requirements > requirements.txt
0

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

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

pipenv lock --requirements
1
  • tried this but didn't work Error: No such option: --requirements Did you mean --quiet?
    – Dhwanit
    Dec 3, 2022 at 15:19
0
pipenv run python -m pip freeze > requirements.txt
-4

You can create a requirements.txt using this command :

pip3 freeze > requirements.txt

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.