0

I need to deploy a python script that requires a mix of public (pip installable) and "local" (pip install path/to/local/package) packages. The computer I'm deploying to will not have internet access or access to the local packages, but likely will have python. Both preparation and deployment will be done in windows.

My solution so far is to create a venv:

  • python -m venv myvenv
  • activate myvenv
  • pip install [packages available from pip]
  • pip install [local packages]

Then I have two options:

1) Ship the venv directory

  • ship the venv directory with my python script (so someone could call the script with something like myvenv\Scripts\python myscript.py

2) Ship the downloaded dependencies

  • From myvenv create requirements.txt (pip freeze > requirements.txt), which captures any packages I downloaded and any dependencies pip downloaded for them
  • Download the whl/zip files for the dependencies
    • pip download -r requirements.txt -d local_package_files --find-links=path/to/local/package/zip
  • Ship the local_package_files directory with myscript.py, then on the computer I'm deploying to do something like:
    • python -m venv deployedenv
    • activate deployedenv
    • pip install -r requirements.txt --no-index --find-links=local_package_files

I can't put my finger on it, but something feels a bit fragile with these solutions. If I do (1) I think it works so long as I'm always transferring between like OS's (eg: from windows to windows). With (2), I'm not sure it is stable if the destination computer has a different python version than the one downloading everything.

I've tried looking through other SO posts but they were usually missing one element (eg: packages dependencies but still needs internet connectivity, or packages dependencies from pip but doesn't handle local packages, etc...).

Suggestions on how to improve/streamline, or where this will break are appreciated.

Andrew
  • 459
  • 5
  • 15
  • 1
    PyInstaller might be what you need. It allows you to package a python script (or a collection thereof) into a windows executable. As an added bonus, you wouldn't even need Python to be installed on the target system. – Stephen Aug 30 '19 at 21:24
  • 1
    Possible duplicate of [How to make a Python script standalone executable to run without ANY dependency?](https://stackoverflow.com/questions/5458048/how-to-make-a-python-script-standalone-executable-to-run-without-any-dependency) – phd Aug 30 '19 at 22:05
  • 1
    https://stackoverflow.com/search?q=%5Bpip%5D+standalone+executable – phd Aug 30 '19 at 22:05
  • Great points, I didn’t think about just compiling into an executable. I’ll check that out. I also considered docker, but then I’ve got the problem of getting docker on the target machine instead of getting python packages there. – Andrew Aug 31 '19 at 11:55

0 Answers0