2

I am a major Python noob, and I made the mistake of manually deleting my Pipfile and Pipfile.lock, thinking that they would eventually regenerate.

How can I re-create these files?

Brent Heigold
  • 1,213
  • 5
  • 24
  • 50

3 Answers3

1

There is a simple fix to this:

First you need to install pipenv if you haven't already:

pip install pipenv

Then change directory to the folder containing your Python project and initiate Pipenv (replace my_project with the name of your project folder):

cd my_project
pipenv install

This will create two new files, Pipfile and Pipfile.lock, in your project directory, and a new virtual environment for your project if it doesn’t exist already.

Bluebot
  • 166
  • 15
1

For regular pip:

pip freeze > requirements.txt

For pipenv:

pipenv run pip freeze > requirements.txt

And to install:

pip install requirements.txt

DUDANF
  • 2,618
  • 1
  • 12
  • 42
1

Situation: you have deleted Pipfile and Pipfile.lock, but your pipenv environment is still there. By this I mean pipenv shell puts you in your environment with a python that has all your packages right there.

# Create a new Pipfile
pipenv install

# Get a list of your packages + version from the would-be "reqiurements.txt", then install them one by one.
pipenv run pip freeze|sed 's/^/pipenv install /'|source /dev/stdin

Note that this is not a perfect solution, as it will specify the versions in the production target environment as you would get from pip freeze i.e. requirements.txt. However this has saved me more than once, so I hope it helps you.

Robino
  • 4,530
  • 3
  • 37
  • 40
  • Note: you need run the commands from the directory where the Pipfiles were. – Robino Sep 07 '22 at 17:13
  • Ah, have just realised that this is almost identical to the answer from @DUDANF, with the only benefit that you don't need to create the requirements.txt file. NVM – Robino Sep 07 '22 at 17:14