将Python venv移动到另一台没有互联网的机器上

发布于 2025-01-13 23:55:39 字数 212 浏览 2 评论 0原文

我正在尝试将 Python 项目部署到没有互联网的机器上。因为它没有互联网,所以我无法使用 requirements.txt 文件安装任何软件包。我想知道是否可以将包含所有已安装软件包的现有环境移动到另一台预安装了所有软件包的计算机中。

我还可以尝试使用 Docker 进行此安装。我是否能够在 Docker 容器中预安装所有软件包,然后将所有文件复制到另一个虚拟机上?

I am trying to deploy a Python project to a machine with no internet. Because it has no internet, I cannot pip install any packages with a requirements.txt file. I am wondering if it is possible to move my existing environment with all installed packages into another machine with all packages pre-installed.

I can also use attempt to use Docker for this installation. Would I be able to pre-install all the packages within a Docker container and then copy all the files onto another VM?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埖埖迣鎅 2025-01-20 23:55:39

在本地计算机上(如果您使用的是 Windows,请调整说明)

  1. 创建 requirements.txt 文件
(venv) [...]$ mkdir pkgs
(venv) [...]$ cd pkgs
(venv) [...]$ pip freeze > requirements.txt
(venv) [...]$ pip download -r requirements.txt
  1. 此处

  2. 复制pkgs 文件夹到远程计算机

在远程计算机上:

  1. 从存档安装 pip
(venv) [...]$ cd pkgs
# --- unarchive pip.tar.gz ---
(venv) [...]$ python setup.py install
  1. 安装软件包
(venv) [...]$ pip install --no-index --find-links . -r requirements.txt

On you local machine (adapt the instructions if you are on Windows)

  1. Create your requirements.txt file
(venv) [...]$ mkdir pkgs
(venv) [...]$ cd pkgs
(venv) [...]$ pip freeze > requirements.txt
(venv) [...]$ pip download -r requirements.txt
  1. Download pip archive from here

  2. Copy pkgs folder to the remote machine

On the remote machine:

  1. Install pip from archive
(venv) [...]$ cd pkgs
# --- unarchive pip.tar.gz ---
(venv) [...]$ python setup.py install
  1. Install packages
(venv) [...]$ pip install --no-index --find-links . -r requirements.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文