用于virtualenv的跨平台界面 [英] Cross platform interface for virtualenv

查看:139
本文介绍了用于virtualenv的跨平台界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Windows上开发了整个项目(Django,Python),并且所有的PaaS都使用Linux。

I have developed my entire project (Django, Python) on Windows and all the PaaS out there use Linux.

VirtualEnv on Linux:

VirtualEnv_dir /
                 bin/ activate, activate_this.py
                 include /
                 lib /
                 local /

VirtualEnv of Windows:

VitualEnv_dir /
                Include/
                Lib /
                Scripts/ activate.bat, activate_this.py

由于virtualenv在窗户和Linux。我应该如何在PaaS上使用Windows virtualenv?

As virtualenv is a lot different in windows & Linux. How shall I need to use my windows virtualenv on the PaaS?

编辑:

如果我在Windows上,则需要运行调用virtualenv_dir / scripts / activate.bat 进入。就像在Linux中一样,它是 source virtualenv_dir / bin / activate 的来源。

If I am on windows, I need to run call virtualenv_dir/scripts/activate.bat to get into it. Where as in Linux, its something source virtualenv_dir/bin/activate.

现在,我的存储库中包含生成的virtualenv使用Windows(使用.bat)。将存储库推送到Linux系统时,应该如何运行它? (bat文件不起作用!)

Now, my repo holds a virtualenv generated using Windows (which uses .bat). When I push the repo to a Linux system, how should I be able to run that? (bat files would not work!)

我正在使用OpenShift PaaS,我想在Git存储库上放置virtualenv。我该如何激活它?

I am using OpenShift PaaS where I would like to put a virtualenv on Git repo. How can I activate it?

最好的解决方案是

推荐答案

除非您使用某些Windows特定的库,否则;或其他Python实现(例如IronPython),无需担心。

Unless you use some Windows specific libraries; or an alternate Python implementation (like IronPython), there is nothing to worry about.

许多人(包括我自己)使用Windows进行开发,并在Linux上进行生产和使用为此,virtualenv。

Many people (including myself) use Windows for development and deploy on Linux for production and use virtualenv for this purpose. It is designed to make your environment portable.

您不会将整个virtualenv推送到Linux。

You don't push the entire virtualenv to Linux.

准备好虚拟环境并运行代码后,应冻结对应用程序的要求:

Once you have your virtual environment ready and your code is working, you should freeze the requirements for your application:

pip freeze > requirements.txt

在目标操作系统中;创建一个 empty 虚拟环境:

In your target operating system; create an empty virtual environment:

virtualenv --no-site-packages prod_env

在最新版本的 virtualenv --no-site-packages 是默认设置。

In recent versions of virtualenv, --no-site-packages is the default.

接下来,使用开发中的需求文件填充环境:

Next, populate the environment with your requirements file from development:

source prod_env/bin/activate
pip install -r requirements.txt

更改需求后,只需重新生成 requirements.txt 文件并运行 pip install -r requirements.txt 投入生产。

When you have a requirements change, simply regenerate the requirements.txt file and run pip install -r requirements.txt in production.

在某些情况下,您的生产系统无法访问Internet来下载软件包因此 pip安装技巧不起作用。对于这些情况,您可以创建自己的私有pypi服务器,然后将软件包推送到那里。通过此途径获得的额外好处是,您可以创建和推送私有软件包,并使用常规的setuptools实用程序进行安装。

In some situations, your production systems don't have access to the Internet to download packages so the pip install trick doesn't work. For these scenarios you can create your own private pypi server and push your packages there. Added bonus going via this route is that you can create and push private packages and install them using the normal setuptools utilities.

一旦确定了适合您的流程,然后在部署脚本中将其自动化;通常与您的源代码管理系统挂钩。有些人喜欢单独的发布工程流程(使用发布管理器-是一个人,而不是一个程序)。

Once you have decided on which process works for you - you then automate it in your deployment scripts; generally with hooks into your source code management system. Some people prefer a separate release engineering process (with a release manager - that is a person, not a program).

这篇关于用于virtualenv的跨平台界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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