如何制作适用于另一个平台的 Python virtualenv? [英] How can I make a Python virtualenv meant for another platform?

查看:31
本文介绍了如何制作适用于另一个平台的 Python virtualenv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行带有 x86-64 处理器的 Ubuntu 的计算机上编写程序,该程序需要在运行带有 x86 处理器的 OS X 的计算机上运行.我可能无法进行任何类型的库安装,因此 venv 几乎是我所知道的唯一选择.

I'm writing a program on a computer running Ubuntu with an x86-64 processor that needs to run on a computer running OS X with an x86 processor. I'm probably not going to be able to do any kind of library installation, so a venv is pretty much the only option I know of.

我如何才能针对该平台制作一个?

How can I make one targeted for that platform?

如果我不能,有没有更好的方法来随程序一起发送库?

If I can't, is there a better way to ship the libraries with the program?

推荐答案

Virtualenvs 不是一种打包机制.virtualenv 没有理由离开创建它的计算机.它不起作用,virtualenv 100% 特定于您的操作系统、CPU 架构、Python 版本等.

Virtualenvs are not a packaging mechanism. There is no reason a virtualenv should ever leave the computer it was created on. It won't work, the virtualenv is 100% specific to your OS, CPU architecture, Python version, etc.

有多种包装解决方案.旧的和当前的方法是在 setup.py 中指定依赖项,并在目标机器上运行 setup.py install.请注意,这可以发生在 virtualenv 中,您只需要创建 virtualenv 并在其中运行 setup.py.virtualenv 和 3.3 中的标准库 venv 都提供了在创建 virtualenv 后自动执行此操作的方法.

There are a number of solutions for packaging. The old and still current way is specifying dependencies in setup.py, and running setup.py install on the target machine. Note that this can happen inside a virtualenv, you just have to create the virtualenv and run setup.py in there. Both virtualenv and the standard library venv in 3.3 provide ways of doing this automatically after virtualenv creation.

如果您绝对必须创建二进制分发版(例如,因为您需要一个扩展模块而最终用户没有编译器),则您需要一个鸡蛋或一个轮子或其中一个 .py 到二进制转换器(py2exe、PyInstaller、cx_Freeze 等).您将需要访问 OS X 机器来创建它.至少轮子和鸡蛋通常无论如何都会安装,因此使用它们不会为您省去任何麻烦.这是因为它们是二进制分发的格式,它们的主要目的是将构建步骤从最终用户推向开发人员,而不是删除安装步骤.

If you absolutely must create a binary distribution (e.g. because you need an extension module and the end user doesn't have a compiler), you need an egg or a wheel or one of the .py-to-binary converters (py2exe, PyInstaller, cx_Freeze, etc.). You will need access to an OS X machine to create that. And at least the wheel and the egg are usually installed anyway, so using them doesn't save you any of this hassle. That's because they are formats for binary distribution, their primary purpose is pushing the build step from the end user to the developers, not to remove the installation step.

总而言之:只需创建一个脚本来创建 virtualenv 并安装您的应用程序以及所需的库.

In summary: Just create a script which creates a virtualenv and installs your application as well as the required libraries.

这篇关于如何制作适用于另一个平台的 Python virtualenv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆