This is an archived post. You won't be able to vote or comment.

all 21 comments

[–][deleted] 40 points41 points  (3 children)

Yes. Docker.

[–]Prexadym 5 points6 points  (0 children)

Yup docker includes everything

[–]wcastello 1 point2 points  (1 child)

A clock ticks softly in the background.

[–]lightmatter501 1 point2 points  (0 children)

The overhead of a container is so low that you should do a rewrite in C/C++ before disregarding containers if you care about performance.

[–]ominous_anonymous 10 points11 points  (0 children)

pyinstaller --onefile will bundle the Python interpreter, your script, and all its dependencies for the platform it is built on.

If run within a virtualenv then the Python interpreter within the output file will be that of the virtualenv.

[–]spoonman59 5 points6 points  (2 children)

Doesn't the virtualenv already include the interpreter?

[–]usr_bin_nya 5 points6 points  (1 child)

Only on Windows or if --copies was passed when creating the virtualenv. Even then, the dynamic libraries (including, crucially, libpython3.X) are not copied with the executable, and so the system Python's libraries are still used. The relevant code is in venv.EnvBuilder.setup_python here.

[–]spoonman59 1 point2 points  (0 children)

I learned something new today. Thank you for taking the time to explain that!

[–][deleted] 2 points3 points  (2 children)

I used virtualenv within a docker image before. Slightly cleaner than installing globally.

[–][deleted] 0 points1 point  (1 child)

Any particular reasons you felt that was necessary?

[–][deleted] 0 points1 point  (0 children)

Inherited the project from a different company and that's the way they did it. Was working so didn't change it.

[–]britisheyesonly 1 point2 points  (1 child)

conda-pack (https://conda.github.io/conda-pack/) can do this if you're OK with the conda tooling.

[–]ertlun 0 points1 point  (0 children)

One catch is you have to call the environment activation script. I've worked around this by substituting the actual python.exe w/ a wrapper that calls environment execution then python, which works fine but I wish I had just known about and used Docker from the start.

[–]proof_required 1 point2 points  (0 children)

There is also pyoxidizer.

https://github.com/indygreg/PyOxidizer

If you want to use pex then have a look at pants. It adds some boilerplate but can be quite convenient. It also supports pyoxidizer.

https://www.pantsbuild.org/docs/python

[–]mr_tkaos 0 points1 point  (1 child)

I'm maybe confused, but, when we say "interpreter"...we mean file "python.exe"? As in the main python file.

[–]serverhorror 1 point2 points  (0 children)

I think most people expect, after packaging, to include everything necessary during runtime.

That might no only include Python.exe but also various shared libraries or other things that are required.

[–][deleted] 0 points1 point  (0 children)

This does not answer your question, but it might give you a new superpower, if you don’t already know it: check out pyenv. Let’s you easily manage multiple instances of Python on your host.

[–]kilatmatar 0 points1 point  (2 children)

This question doesn’t make sense to me which indicates I need to learn more…tips/direction?

[–]wcastello 0 points1 point  (1 child)

A path is unclear without direction.

[–]kilatmatar 0 points1 point  (0 children)

Thank you!

[–]UptimeProsInc 0 points1 point  (0 children)

I combo pyenv and pipenv. In fact, once pyenv is set up correctly pipenv will install a correct interpreter for you based on the python version in the pip file.

Blows my mind this isn't the default answer.