简体   繁体   English

virtualenv的跨平台界面

[英]Cross platform interface for virtualenv

I have developed my entire project (Django, Python) on Windows and all the PaaS out there use Linux. 我在Windows上开发了我的整个项目(Django,Python),并且那里的所有PaaS都使用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

As virtualenv is a lot different in windows & Linux. 因为virtualenv在Windows和Linux中有很多不同。 How shall I need to use my windows virtualenv on the PaaS? 我如何在PaaS上使用我的windows virtualenv?

Edit: 编辑:

If I am on windows, I need to run call virtualenv_dir/scripts/activate.bat to get into it. 如果我在Windows上,我需要运行call virtualenv_dir/scripts/activate.bat进入它。 Where as in Linux, its something source virtualenv_dir/bin/activate . 在Linux中,它的source virtualenv_dir/bin/activate

Now, my repo holds a virtualenv generated using Windows (which uses .bat). 现在,我的repo拥有一个使用Windows生成的virtualenv(使用.bat)。 When I push the repo to a Linux system, how should I be able to run that? 当我将repo推送到Linux系统时,我应该如何运行它? (bat files would not work!) (bat文件不起作用!)

I am using OpenShift PaaS where I would like to put a virtualenv on Git repo. 我正在使用OpenShift PaaS,我想在Git repo上添加一个virtualenv。 How can I activate it? 我该怎么激活它?

What's the best solution 什么是最好的解决方案

Unless you use some Windows specific libraries; 除非你使用一些Windows特定的库; or an alternate Python implementation (like IronPython), there is nothing to worry about. 或者替代Python实现(如IronPython),没有什么可担心的。

Many people (including myself) use Windows for development and deploy on Linux for production and use virtualenv for this purpose. 许多人(包括我自己)使用Windows进行开发并在Linux上部署以进行生产,并为此目的使用virtualenv。 It is designed to make your environment portable. 它旨在使您的环境可移植。

You don't push the entire virtualenv to Linux. 你没有将整个virtualenv推向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

In your target operating system; 在您的目标操作系统中; create an empty virtual environment: 创建一个空的虚拟环境:

virtualenv --no-site-packages prod_env

In recent versions of virtualenv , --no-site-packages is the default. virtualenv最新版本中, --no-site-packages是默认的。

Next, populate the environment with your requirements file from development: 接下来,使用开发中的需求文件填充环境:

source prod_env/bin/activate
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. 当您更改需求时,只需重新生成requirements.txt文件并在生产环境中运行pip install -r requirements.txt

In some situations, your production systems don't have access to the Internet to download packages so the pip install trick doesn't work. 在某些情况下,您的生产系统无法访问Internet以下载软件包,因此pip install技巧不起作用。 For these scenarios you can create your own private pypi server and push your packages there. 对于这些场景,您可以创建自己的私人pypi服务器并将包推送到那里。 Added bonus going via this route is that you can create and push private packages and install them using the normal setuptools utilities. 通过此路由添加的奖励是您可以创建并推送私有包并使用常规setuptools实用程序安装它们。

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). 有些人更喜欢单独的发布工程流程(使用发布经理 - 这是一个人,而不是一个程序)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM