Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pipenv: why to run pipenv lock when lock file is automatically created wheneven i install a package

Tags:

python

pipenv

Pipenv:

I found at https://realpython.com/pipenv-guide/ that to tranfer the project to development i have to run

pipenv lock 

(to update/create the Pipfile.lock file)

As per my understanding whenever we install any package using

pipenv install django

Pipfile.lock is automatically generated/updated.

So whats the need to do

pipenv lock

isnt the Pipfile.lock always the updated.

of course in case i want to create .lock file at any time (by chance if its delete) i may do pipenv lock

Also if by chance the pipfile is deleted can i recreate it again.

like image 976
Santhosh Avatar asked Oct 08 '18 08:10

Santhosh


People also ask

Does Pipenv install lock?

pipenv install by default does attempt to re-lock unless using the --deploy flag. That distinction seems to be key and shouldn't be hidden in the advanced section. An intuitive command for installing dependencies is pipenv install which was used before.

Is Pipfile lock generated automatically?

When you create a Pipenv environment either for a new or an existing project, the Pipfile is generated automatically. The file is added to the current project, you can see it in the Project tool window.

Is Pipenv dead?

Pipenv is dead.

How long does Pipenv lock take?

Other comments here saying 2-3 minutes per lock are consistent with my general experience. This wasn't for complex pipenv operations either. A simple command: pipenv run python main.py took progressively longer to execute. It takes about 2 minutes (feels like 5!) on my 2016 MBP to install 102 dependencies.


1 Answers

You're right that the Pipfile.lock has already been created when installing the virtual environment or some packages. As far as I understand, the goal would be to update all your dependencies before entering production.

But I think against the documentation you should not update the Pipfile.lock at this stage, unless you're very confident in your CI pipeline and your test framework, because it could potentially deploy in production some untested dependency version Remember that pipenv lock will not install on your development machine the update dependencies, and if you rerun your tests without pipenv sync you will not test the updated dependencies. I prefer locking once and for all the dependencies at a early stage, then keep it until deployment, then after the deployment update the dependencies and begin the next version.

That's also why I am very careful with pip install <package>, because it will also automatically update all your dependencies, while I would prefer that pipenv tries to keep all the other dependency versions unchanged, unless specifically specified or clash between dependency versions.

like image 112
gaFF Avatar answered Oct 01 '22 00:10

gaFF