question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sync Pipfile changes with virtualenv

See original GitHub issue

After modifiying Pipfile/Pipfile.lock (i.e. after a git checkout) I would expect that there is a simple command, that syncs the changes back to the virtual environment. Ideally it is done automaticially when running pipenv shell/pipenv run. At least I would expect pipenv check to warn if Pipfile does not matcb to the environment any more.

But neither did I find a command to sync the files with environment manually nor did run/shell sync them automaticially nor did check return errors.

What I did was:

  • pipenv install <packagename>==<version1>
  • save Pipfile (i.e. by git commit)
  • pipenv install <packagename>==<version2>
  • restore Pipfile (i.e. by git checkout)
  • run any pipenv command => commands are done within an environment that has <version2> installed

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mrh1997commented, Oct 12, 2017

One of the nice things of pipenv is, that every commit has its own virtualenv spec (in Pipfile.lock). My understanding is, that when I checkout a commit pipenv will guarantee that I work with exactly the same virtualenv I worked when I checked out this commit the last time (similarly to git, which guarantees that I work with exactly same codebase).

pipenv update is not appropriate for this, as it does not create a virtualenv as described in ‘Pipfile.lock’, but it does exactly the opposite: it creates a ‘Pipfile.lock’ from a virtualenv (after upgrading the virtualenv to the newest packages).

In the meantime I found a operation which does exactly what I want:

pipenv install --ignore-pipfile

But this as far from intuitive.

Furthermore: pipenv shell or pipenv run guarantees that you have a virtualenv when being run the first time. Why does it not ensure this on every run (=check if the virtualenv is different from Pipfile.lock and restore it if not so)?

1reaction
mimischicommented, Oct 12, 2017

I’m not sure whether it’s clear what you’re exactly trying to do. Your “What I did” example is not very clear.

Were you trying to do this?

git checkout -b newbranch
pipenv install mynewpackage
git commit -am 'Added `mynewpackage` to environment'
git checkout master

Although you now have your old Pipfile (pre-installation of mynewpackage in the branch newbranch), that package is still installed in your current environment. You want to get rid of that, right?

Just use pipenv update. This will compare your environment against your Pipfile, purge all packages and reinstall everything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage of Pipenv - Read the Docs
This causes Pipenv to ignore changes to the Pipfile and (more importantly) prevents it from adding the current environment to Pipfile.lock . This...
Read more >
Basic Usage of Pipenv - Python Packaging Authority
Pipfiles contain information for the dependencies of the project, and supersedes the requirements.txt file used in most Python projects.
Read more >
pipenv Documentation - Read the Docs
Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the. Python...
Read more >
Pipenv & Virtual Environments
virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need. It can be...
Read more >
What's wrong with pipenv? I am genuinely curious. On local
Minor python version changes and the venv is toast? Different ways of structuring ... time pipenv sync Installing dependencies from Pipfile.lock (3f6ae1)…
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found