如何将完整的Python虚拟环境从一台机器移动到另一台机器?

发布于 2025-02-07 09:37:46 字数 406 浏览 2 评论 0原文

我有一个在Python虚拟环境中在开发机(Linux)上运行的Python烧瓶服务器。是否有一种直接的方法可以将这个虚拟环境和所有已安装的软件包完全移动到另一台机器进行部署? (也是Linux)

我不想在部署计算机上使用PIP安装,因为它已嵌入,并且似乎在PIP上遇到了一些问题。我想知道是否有办法干净地移动整个虚拟环境并将其在另一台机器上工作。

我尝试过的事情是:

  • 我尝试在目标机器上启动新的虚拟环境,并
pip3 install -r requirements.txt

出于任何原因而执行此操作。它安装了一堆软件包,然后挂起,我必须重新启动机器。

  • 我还尝试复制整个虚拟环境,然后按照本文中的第二个答案的建议编辑激活文件。

I have a python flask server that runs on a development machine (Linux) in a python virtual environment. Is there a straightforward way to completely move this virtual environment and all the installed packages to another machine for deployment? (Also Linux)

I do not want to have to use pip install on the deployment machine as it is embedded and seems to be having some issues with pip. I am wondering if there is way to move the entire virtual environment cleanly and get it to work on another machine.

Things I have tried:

  • I have tried starting a new virtual environment on the target machine and doing
pip3 install -r requirements.txt

For whatever reason this isn't working. It installs a bunch of packages then just hangs and I have to restart the machine.

  • I also tried copying the entire virtual environment then editing the activate file as recommended by the second answer in this post.
    "venv activate" doesn't not change my Python path
    It didn't seem to work cause when I ran the server I got a bunch of import errors (it was still searching the wrong path).

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

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

发布评论

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

评论(1

弥繁 2025-02-14 09:37:46

在开发机上进行PIP冻结。这将为您提供当前在计算机上安装的所有软件包的列表。
从pypi.org下载所有这些软件包的轮子文件,也可以使用这些

将车轮文件复制到文件夹中的目标机说wheels。在此文件夹中的所有文件中编写一个bash脚本以列出以列出的所有文件,并在每个项目上运行pip install package_name.wheel命令以安装这些软件包。您可以为此使用:find/path/to/wheels/wheels/folder -name“*.whl” -exec pip install {} \;>

Do pip freeze on your dev machine. This will give you list of all packages which you have currently installed on your machine.
Download wheel files for all of these packages from pypi.org one by one or you can use these scripts.

Copy wheel files to your target machine in a folder say wheels. Write a bash script to list through all files in this folder and run pip install package_name.wheel command on every item to install those packages. You can use find for this: find /path/to/wheels/folder -name "*.whl" -exec pip install {} \;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文