简体   繁体   English

如何将 Python 程序部署到离线的计算机?

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

I have a small python app I've developed for file validation.我有一个为文件验证而开发的小型 python 应用程序。 I need to deploy it to a server that has no outside internet access.我需要将其部署到没有外部 Internet 访问权限的服务器上。 It utilizes a number of libraries (pandas, glob, os, datetime, pyodbc and numpy).它利用了许多库(pandas、glob、os、datetime、pyodbc 和 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.我能够在服务器上安装 Python 3.8.5 并且我尝试使用 Pyinstaller 将包括库在内的所有内容包装成一个可以在服务器上运行的好 exe,但它不起作用。 I am trying that again using the --onefile flag.我正在使用 --onefile 标志再次尝试。 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.服务器完全离线 - 我不能简单地使用 PIP 来安装缺少的库。 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.此外,我的工作计算机非常锁定,所以我也不能简单地下载 WHL 文件或类似文件并手动将它们安装在服务器上。 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.我刚刚在可以访问 Internet 的机器上运行 pip 下载我需要的模块,将 whl 文件捆绑到 tar.gz 文件中,将其传输到有问题的服务器,但在尝试运行 pip install tar 时仍然无法安装。 gz 更新:我解压缩了 tar.gz 文件并尝试手动安装一些 WHL 文件,它卡在 pandas 上,试图下载某些东西或连接到 pypi.org,但显然不能。

Any help would be appreciated.任何帮助,将不胜感激。

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).一个很好的方法是通过像 pip-compile(pip-tools 的一部分)这样的工具,您可以在其中声明您的直接需求在 requirements.in 文件中,并让它找出完整的依赖项和版本列表(写在到 requirements.txt,通常)。 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.它不适用于 your.tar.gz 文件的原因是 pip 期望 .tar.gz 文件成为单个 package 的源代码分发,而不是许多软件包的一堆不同轮子文件的 tarball。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM