cardinalsfan
cardinalsfan

Reputation: 87

How to deploy a Python program to a computer that's offline?

I have a small python app I've developed for file validation. I need to deploy it to a server that has no outside internet access. It utilizes a number of libraries (pandas, glob, os, datetime, pyodbc and numpy).

I was able to install Python 3.8.5 on the server and I attempted to use Pyinstaller to wrap everything including the libraries into a nice exe that could run on the server but it did not work. I am trying that again using the --onefile flag. Error message below:

Traceback (most recent call last):
  File "BDWtoStuckyValidation.py", line 2, in <module>
    import pandas as pd
  File "C:\Program Files\Python38\lib\site-packages\pandas\__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
dateutil: No module named 'dateutil'

The server is completely offline - I cannot simply use PIP to install the libraries that are missing. Additionally, my work computer is VERY locked down so I also cannot simply download WHL files or similar and manually install them on the server. Anything that has to be transferred to the server would need to be downloaded on my personal laptop, transferred to my work laptop via bluetooth and then to the server via the network. I did just run pip download for my needed modules on a machine with internet access, bundled the whl files into a tar.gz file, transferred that to the server in question and it still wouldn't install when attempting to run pip install tar.gz Update: I unzipped the tar.gz file and attempted to install some WHL files manually, it got stuck on pandas, attempting to download something or connect to pypi.org, which it obviously can't.

Any help would be appreciated.

Upvotes: 1

Views: 770

Answers (1)

Drew Hall
Drew Hall

Reputation: 29045

The process you described should work, but you need to ensure that you get all of the indirect dependencies (the things that your direct dependencies depend on). A good way to do that is via a tool like pip-compile (part of pip-tools), where you can declare your direct requirements in a requirements.in file and have it figure out the complete list of dependencies and versions (written in to requirements.txt, generally). Once you have that list, you can download all the appropriate wheel files and proceed just as you described.

The reason that it would not work with your .tar.gz file is that pip expects a .tar.gz file to be a source distribution for a single package, rather than a tarball of a bunch of different wheel files for many packages.

Upvotes: 1

Related Questions