Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pipenv sync and pipenv install --system --ignore-pipfile in docker environment

According to pipenv official documentation:

sync

pipenv sync [OPTIONS]

Installs all packages specified in Pipfile.lock.

install

pipenv install [OPTIONS] [PACKAGES]...

Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile.

--ignore-pipfile Ignore Pipfile when installing, using the Pipfile.lock.

Is it safe to assume pipenv sync and pipenv install --ignore-pipfile are identical without any hidden drawbacks?

More background: I was using --system flag to install the python packages to the system since I don't care about isolated environments in a docker container. However --system flag is unavailable for pipenv sync (See github issue), so I figured pipenv install --system --ignore-pipfile might be a viable hack.

like image 469
Victor Wong Avatar asked Oct 22 '18 05:10

Victor Wong


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.

What does -- ignore Pipfile do?

You might also want to add --ignore-pipfile to pipenv install , as to not accidentally modify the lock-file on each test run. This causes Pipenv to ignore changes to the Pipfile and (more importantly) prevents it from adding the current environment to Pipfile.

What does Pipenv sync do?

pipenv sync will install the exact versions specified in Pipfile. lock. I would say sync is better for getting your environment to match what is checked in, and install is for when you want to get the latest versions, or are adding new dependencies that aren't in the lock file yet.

Is Pipfile lock necessary?

That file is impossible for human to deal with, you can only deal with Pipfile . But Pipfile is not strict enough to reproduce a totally same environment. So that's why we also need a Pipfile. lock .


3 Answers

you can see the notes in Advanced usage of pipenv

pipenv install --ignore-pipfile is nearly equivalent to pipenv sync, but pipenv sync will never attempt to re-lock your dependencies as it is considered an atomic operation. pipenv install by default does attempt to re-lock unless using the --deploy flag.

so maybe pipenv install --ignore-pipfile --deploy equal to pipenv sync

like image 188
En Ouyang Avatar answered Oct 17 '22 03:10

En Ouyang


Not really an answer (I'd be interested in confirmation as well) but for what it's worth, we've been using

pipenv install --system --deploy --ignore-pipfile

in our Dockerfile with good results.

like image 28
sas Avatar answered Oct 17 '22 04:10

sas


Not sure whether it was added after you posted this question, but the documentation does address this very question (although, to be fair, it's kinda of a "uh?" type of explanation for me...)

FWIW, I believe that sync should have the --system flag too (I'm trying to address the very same issue as you, of building a container, and do not want to maintain two separate files: requirements.txt for the container's system Python, and Pipfile for my dev virtual env).

Your "hack" seems to me currently the only viable option.

like image 33
Marco Massenzio Avatar answered Oct 17 '22 03:10

Marco Massenzio