Reputation: 1438
I have a flask app with a Pipfile and run pipenv run python setup.py sdist
to create a package. I copy the package to another system.
Usually I would install it with pip and all requirements declared in install_requires in setup.py would be installed automatically.
How can I install the package and its requirements and make use of the Pipfile.lock?
If I install the package with pip, I could run pipenv install --deploy
in the directory it was installed, but how can I reliably retrieve the directory my package was installed in? Is this a good way to do this?
I'm looking for the best way to install a python app with setuptools and pipenv.
Upvotes: 4
Views: 3543
Reputation: 1438
I'll share my thoughts on this.
First, the abstract dependencies of your project are to be listed in setup.py's install_requires. They should not be pinned if possible and reading dependencies in setup.py from somewhere else is not recommended.
Thus, if you install a package created with python setup.py sdist
, that project's Pipfile.lock will not be used. Instead the user of the package is reponsible for locking the dependencies and installing the package into a virtualenv.
To use our Pipfile.lock we need a different approach to deployment. I've collected a few.
1) git clone
the repository on target machine or rsync -r
it to target machine. Run pipenv install --deploy
in cloned project directory. There are several ways of using the virtualenv:
pipenv run <appname>
from the cloned project directory. Make sure you are the same user who created the virtualenv.pipenv --venv
from the cloned project directory as the same user who created the virtualenv and use it directly for running your app.PIPENV_VENV_IN_PROJECT=1
environment variable before running pipenv install --deploy
to get a consistent virtualenv location that you can then use directly for running your app.2) Use pipenv install --system --deploy
to set up the virtualenv from your Pipfile.lock in docker. Then just use the docker image for deployment.
3) Dump Pipfile.lock into a requirements.txt with pipenv lock --requirements > requirements.txt
and build a deb package using dh-virtualenv
.
Upvotes: 1