4

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.

asked Dec 5, 2017 at 21:31
2
  • 1
    Hi Kris, did you find a solution? Commented May 23, 2018 at 14:42
  • I'll post my thoughts on this in the next few days Commented May 24, 2018 at 13:55

1 Answer 1

1

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:

  • Launch the app with pipenv run <appname> from the cloned project directory. Make sure you are the same user who created the virtualenv.
  • Retrieve the virtualenv location by running pipenv --venv from the cloned project directory as the same user who created the virtualenv and use it directly for running your app.
  • Set 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.
  • Before running pipenv, manually create a virtualenv then run pipenv from there. Pipenv will automatically use that virtualenv instead of creating a new one. See https://stackoverflow.com/a/49388414/7662112 for a complete workflow.

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.

answered May 30, 2018 at 7:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.