Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distribute Python applications "with" a venv

Say I have a Python app that will be used as a command line tool. This app has some external dependencies. How would I go about distributing this?

I know it's common to install Python stuff in a virtual environment (virtualenv or pyvenv), but if the app is to be used from the command line I don't want to have me or my users to activate the correct virtual environment every time they want to use my app.

Is there a solution to this? Or should I just put all dependencies in setup.py and leave it up to the user whether they create a virtual environment or not?

like image 727
lunanoko Avatar asked Oct 20 '22 10:10

lunanoko


2 Answers

Use a setup.py and list the dependencies in install_requires.

Now to the part "How to distribute this?"

In our company we run our own pypi server. Every package that gets installed on our servers must be from our pypi server. No software gets downloaded directly from the internet to the server.

If you want to build an open source tool, you should upload it to the official pypi server.

The tool should not care about its environment. It should work in a virtualenv and outside.

Maybe the sampleproject helps you: https://github.com/pypa/sampleproject

like image 148
guettli Avatar answered Oct 22 '22 02:10

guettli


I will mention an alternative solution with a requirements.txt file for pip. See the documentation:

https://pip.pypa.io/en/latest/user_guide.html#requirements-files

The user then knows what dependencies your app has and can easily install them into his/her virtual environment with pip install -r requirements.txt.

The file can easily be created with pip freeze > requirements.txt.

like image 45
geckon Avatar answered Oct 22 '22 01:10

geckon