Quantcast
Viewing latest article 12
Browse Latest Browse All 49

Answer by David Z for How to pip install packages written in Pipfile without creating virtualenv?

Eventually pip should be able to do this itself, at least that's what they say. Currently, that is not yet implemented.

For now, a Pipfile is a TOML file, so you can use a TOML parser to extract the package constraints and emit them in a format that will be recognized by pip. For example, if your Pipfile contains only simple string version specifiers, this little script will write out a requirements.txt file that you can then pass to pip install -r:

import sysimport tomlwith open(sys.argv[1]) as f:    result = toml.load(f)for package, constraint in result['packages'].items():    if constraint == '*':        print(package)    else:        print(f'{package} {constraint}')

If your Pipfile contains more complicated constructs, you'll have to edit this code to account for them.


An alternative that you might consider, which is suitable for a Docker container, is to use pipenv to install the packages into the system Python installation and just remove the generated virtual environment afterwards.

pipenv install --systempipenv --rm

However, strictly speaking that doesn't achieve your stated goal of doing this without creating a virtualenv.


Viewing latest article 12
Browse Latest Browse All 49

Trending Articles