将Python virtualenv移植到另一个系统 [英] Port Python virtualenv to another system

查看:357
本文介绍了将Python virtualenv移植到另一个系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机上的日常工作中使用了许多python软件包,例如numpy,瓶颈,h5py等.由于我是该计算机的超级用户,因此安装这些软件包没有问题.但是,我也想在只有普通用户帐户的服务器计算机上使用不同软件包的环境".因此,我考虑过通过在计算机上安装所有必需的软件包来在计算机上创建虚拟环境(使用virtualenv).然后,我只是将整个文件夹复制到服务器,并可以运行其中的所有内容?

I am using many python packages like numpy, bottleneck, h5py, ... for my daily work on my computer. Since I am root on this machine it is no problem to install these packages. However I would like to use my "environment" of different packages also on a server machine where I only have a normal user account. So I thought about creating a virtual environment (with virtualenv) on my machine by installing all needed packages in there. Then I just copy the whole folder to the server and can run everything from it?

我的机器使用Fedora 19,而服务器使用Ubuntu.这有问题吗?我找不到有关如何将这样的虚拟环境移至另一个系统的任何信息.我想首先在机器上创建虚拟环境的原因是服务器上缺少诸如python-dev之类的很多工具,因此我无法编译numpy.

My machine uses Fedora 19 whereas the server uses Ubuntu. Is this a problem? I could not find any information on how to move such a virtual environment to another system. The reason I would like to create the virtual environment on my machine first is that there are a lot of tools missing on the server like python-dev, so I can't compile numpy for instance.

我研究了Anaconda和Enthought Python发行版,但其中不包含我需要的几个软件包.另外,对于这个问题应该有一种完全开放"的方式吗?

I looked into Anaconda and Enthought Python distributions, but they don't include a couple of packages I need. Also, there should be a completely "open" way for this problem?

将虚拟环境移动到服务器失败,因为在导入软件包时它抱怨某些丢失的文件.这可能不足为奇...

Moving the virtual environment to the server failed, since it is complaining about some missing files when I import the packages. This is not surprising probably...

推荐答案

您不应该移动您的virtualenv,因为它实际上已链接到系统python,并且二进制文件在其他计算机上也无法使用.

You shouldn't move your virtualenv since it is essentially linked to your system python and the binary won't work on other machines.

但是...您可以导出已安装软件包的列表,并通过requirements.txt文件将它们安装在另一个virtualenv中.

However... you can export a list of installed packages and install them in another virtualenv through a requirements.txt file.

基本上,我通常会处理大多数项目:

Basically, what I usually do with most of my projects:

# Generate a requirements file:
pip freeze > requirements.txt

在新计算机上:

# This uses virtualenvwrapper, but you can do it without as well
mkproject my_project_name
git clone git://..../ .
pip install -r requirements.txt

这篇关于将Python virtualenv移植到另一个系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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