How to install dependencies from a copied pipfile inside a virtual environment?

PythonPipVirtualenvPipenv

Python Problem Overview


The problem originates when I start by cloning a git project that uses pipenv, so it has a Pipfile + Pipfile.lock. I want to use a virtual environment with the project so I run pipenv shell. I now have a virtual environment created and I am inside the virtual environment. The project obviously has a lot of dependencies (listed in the Pipfile). I don't want to have to go through the list in the Pipfile one by one and install them using pipenv install <package_name>. Is there a pipenv/pip command that installs all the packages from a Pipfile I already have? Or maybe I need to set up the environment differently than running pipenv shell?

Python Solutions


Solution 1 - Python

The proper answer to this question is that pipenv install or pipenv install --dev (if there are dev dependencies) should be ran. That will install all the dependencies in the Pipefile. Putting the dependencies into a requirements.txt and then using pip will work but is not really necessary. The whole point of using pipenv for most people is to avoid the need to manage a requirements.txt or to use pip.

EDIT: if the virtualenv is already activated, you can also use pipenv sync or pipenv sync --dev for the same effect.

Solution 2 - Python

Ideally, you are encouraged to have a requirements.txt file which contains all the packages required for installation via pip. You can create this file by doing:

pip freeze > requirements.txt

You can convert a Pipfile and Pipfile.lock into a requirements.txt. Take a look into this

pipenv lock -r

After that, you can install all your modules in your python virtual environment by doing the following:

pip install -r requirements.txt

Hopefully, I anwered your question.

Solution 3 - Python

I had a similar issue. For me, I exited the virtualenv and ran

pipenv --three sync

and it worked.

From what I can understand the idea is to create a new virtual environment using python 3 in my case. If you're using python 2 the above command would be edited to read

pipenv --two

The sync command copies all dependencies from the Pipfile.lock over to the new virtualenv.

Solution 4 - Python

use pipenv sync to install all packages specified in Pipfile.lock.

Solution 5 - Python

use pipenv sync in file Pipfiel


this code refrsh lib in file type .lock

pipenv sync

use this run virtualenv Pipfile

pipenv shell

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCaleb SyringView Question on Stackoverflow
Solution 1 - PythonRandy SyringView Answer on Stackoverflow
Solution 2 - PythonSoumithri ChilakamarriView Answer on Stackoverflow
Solution 3 - PythonmiriadView Answer on Stackoverflow
Solution 4 - PythonFatemeh KarimiView Answer on Stackoverflow
Solution 5 - PythonAmmar Abdul WadoodView Answer on Stackoverflow