Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 910
Caleb Syring Avatar asked Sep 04 '18 17:09

Caleb Syring


People also ask

Does Pipenv install use Pipfile or Pipfile lock?

$ pipenv lock is used to create a Pipfile. lock , which declares all dependencies (and sub-dependencies) of your project, their latest available versions, and the current hashes for the downloaded files.

Does pip support Pipfile?

pip will grow a new command line option, -p / --pipfile to install the versions as specified in a Pipfile , similar to its existing -r / --requirement argument for installing requirements. txt files. To manually update the Pipfile.

How do I install a package in Pipenv?

Open a console in your project directory and type pipenv install <package_name> to install a package for the project. To specify that the package is for development, use the -d flag. You can use pip syntax to denote a specific version of a package (e.g., black==13.0b1 ).


2 Answers

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.

like image 106
Randy Syring Avatar answered Sep 29 '22 21:09

Randy Syring


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.

like image 29
Soumithri Chilakamarri Avatar answered Sep 29 '22 20:09

Soumithri Chilakamarri