Is it possible to update Pipfile after installing packages using pip install?

Viewed 5051

I just created a pipenv environment using pipenv --python 3.9. I then did pipenv shell and started installing packages with pip install. It turns out this doesn't seem to be the usual way of doing things with pipenv. Is there any command I can run to update the Pipfile with all the packages I installed with pip install? I searched but couldn't find anything.

3 Answers

When you have multiple packages you'd like to install, you usually have whats called a requirements.txt file, that contains all the packages you'd like to use for your project.

You can run

$ pipenv run pip freeze > requirements.txt

To generate the requirements file to the current directory you're in, while the virtual environment is active.

Initially you're going to have to install all your packages manually. But after you can run

$ pipenv install -r path/to/requirements.txt

to import all the packages in requirements.txt from the shell/virtual environment.

Instead of running pipenv shell and then pip install <package>, you should simply run pipenv install <package> (outside the virtual environment, from the same location you ran pipenv --python 3.9).

This will install the package in your virtual environment and will automatically update your Pipefile and Pipfile.lock files.

You may skip the Pipfile.lock update by using --skip-lock flag - pipenv install --skip-lock <package>

You can use pipreqs which generates requirements.txt file based on imports.

pip install pipreqs
pipreqs
pipenv install -r requirements.txt
Related