Okay, people. I've been reading about and I totally get it in the context of development. What I don't get is distribution. If I finish building a command line app in python and want to share it, would everyone that wants to use it have to set up a virtualenv on their end to do so? And what about in context of a cron job? Is it normal to script a wrapper that launches it in virtualenv context? What am I missing here?

@tomasino you can pack up a python application and its deps as a single binary

@ckeen okay, that's totally what I need! Can you give me a name or a link to start my learning on that front?

@tomasino If your command line app depends on lots of external dependencies and is very fussy about the precise versions of those dependencies and those dependencies are hard for people to install themselves (e.g. requires compilation), then using virtualenv for distribution might make some sense, but I would consider it a last resort. IMHO the above conditions make software uninteresting and gross.

@tomasino (my two cents from not real developer)

imho in web or/and scientific context virtualenv just good enough. usually its server or environment (jango, or ipython/jupyther) and if you need another server you just reinstall all required libs via pip, like apt in debian. so it's more os or shell, than application.

but software development on python is terra incognita for me, so so I'll watch for other answers too :)

@tomasino there are a few options:

1. If you're deploying/distributing your script as a docker image, you don't need virtualenv as it's the only app in the container.
2. Wrap it in an OS-specific package (.deb, .rpm, Homebrew)
3. Provide a README explaining to users that they need Python and may be a virtual env. "May be", because if it's a standalone script with no dependencies, you don't need it.

@tomasino also, I *think* there are some external solutions (besides Docker) to distributing Python code packed in a binary along with all the dependencies, but I haven't looked into them for ages, can't help :-)

@tomasino just make a PyPI package so people cas install it with "pip install my_app". You can provide binary installation too.

Wheter to use a virtualenv or not should be the user's choice.

People who want/needs it, devs most of the time, can handle it without your README 🙂

@cebash if my pypi package has a dependency on an external library, it's not bundled for me, right? When a user installs it will it update their system lib or mismatch? I could create conflicts for them? Or will it distribute in a semi compiled way that pre built?

@tomasino that's the problem with pip, it will compile the python dependencies but the user must have installed all the libraries, headers and compilers of its dependencies to work. I know some packages provide binaries but I don't know how it works.

@tomasino Interesting question. I don't recall having setup a virtualenv to run an application. Mostly did that to install libraries to use while creating an application. I've never distributed applications using python, mostly use it to create small things here and there, but maybe this might float your boat: packaging.python.org/discussio

@tomasino FWIW when I _use_ standalone python tools, I generally reach for pipsi to install them in isolated virtual environments.

@tomasino Both of your assumptions are correct. Anyone who needs to use your python program would need to set up and activate virtualenv appropriately. There are numerous platform-specific "bundle" solutions that you can use to make this easier for your paying clients. If, however, you don't have direct clients, then you just need to specify all proper dependencies in your requirements.txt and setup.py to make sure that people using your software can fetch all the dependencies automatically.

Sign in to participate in the conversation
Mastodon @ SDF

"I appreciate SDF but it's a general-purpose server and the name doesn't make it obvious that it's about art." - Eugen Rochko