0

I need to deploy my python code on tens of thousands of machines (all linux but with different kernel).

To save time an resolve the dependence issues on different machine I thought two ways as below:

One idea is to use docker which is not possible in my situation.

Another thoughts is to use virtual env. Plan to create virtual env on my laptop, install dependency and my code, then tar the who directory and copy it to target machines.

Is it a good practice? What could be the problem of doing this?

Kramer Li
  • 2,284
  • 5
  • 27
  • 55
  • Why can't you use docker? – pykam Apr 21 '21 at 02:19
  • 1
    It's very not advisable to move an already-created virtualenv folder. Docker or any kind of containerization is recommended. – TYZ Apr 21 '21 at 02:20
  • 2
    If you want to use virtual environment to resolve dependencies, use pipenv and piplock instead of venv. – pykam Apr 21 '21 at 02:20
  • https://www.digitalocean.com/community/tutorials/how-to-package-and-distribute-python-applications – drum Apr 21 '21 at 02:20
  • 1
    One doesn't need to use Docker to have a self-contained userspace environment. Folks were distributing chroots decades before Docker existed (before Python existed as well, for that matter). – Charles Duffy Apr 21 '21 at 02:21
  • 1
    That said, "best practice" questions are typically considered too fuzzy (opinion-based, broad, etc) to be on-topic here. See [Why is asking a question on best practice a bad thing?](https://meta.stackexchange.com/a/142354/144918) on [meta]. – Charles Duffy Apr 21 '21 at 02:22
  • 1
    https://github.com/pantsbuild/pex, this is a choice – Terran Apr 21 '21 at 02:24
  • 1
    _Personally_ I strongly prefer [Nix](https://nixos.org/nix/) (which gives you virtualenv-type capabilities not just for Python but for _all_ software including compiled tooling, with far stronger reproducibility than Docker -- plus the ability to natively build Docker images for that matter), but if you're being told you can't use Docker, I wouldn't consider Nix likely to fly either with whomever created that constraint. – Charles Duffy Apr 21 '21 at 02:24
  • No. See https://stackoverflow.com/a/12657803/7976758 and other answers. – phd Apr 21 '21 at 09:32

1 Answers1

0

No. I have tested before, and moving virtualenv is no good. It will never work. You can use maybe PyInstaller to make an executable. I believe it can make Linux scripts, or you can use a shell script. Put these in same directory.

start.sh

#!/bin/sh
python3 myprogram.py

myprogram.py

print('Test')

Then run start.sh. In answer to the original question, it is not good practice to distribute a virtualenv.