使用 pythonbrew 在不同的 virtualenv 中管理 python 版本 [英] Manage python version in different virtualenv with pythonbrew

查看:64
本文介绍了使用 pythonbrew 在不同的 virtualenv 中管理 python 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主系统python版本是2.7.3.我正在尝试创建一个使用 3.3.0 版的 virtualenv.我安装了 pythonbrew、virtualenv 和 virtualenvwrapper.

My main system python version is 2.7.3. I'm trying to create a virtualenv that uses version 3.3.0. I installed pythonbrew, virtualenv and virtualenvwrapper.

我遵循了本教程:http://technomilk.wordpress.com/2011/07/27/setting-up-our-django-site-environment-with-pythonbrew-and-virtualenv/

本质上运行pythonbrew use 3.3.0,然后创建一个virtualenv.该教程说 virtualenv 将使用 pythonbrew 使用的版本.但事实并非如此.当我启动它时,virtualenv 使用 2.7.3.当我执行 pythonbrew use 3.3.0 时,它会离开 virtualenv 并应用于系统而不是环境.

Which essentially runs pythonbrew use 3.3.0, and then create a virtualenv. The tutorial says that the virtualenv will use the version pythonbrew uses. But it doesn't. The virtualenv uses 2.7.3 when I start it. When I do pythonbrew use 3.3.0, it leaves the virtualenv and it applies to the system instead of the environment.

显然,pythonbrew 有自己的 virtualenv 包装器,它有一个教程:http://suvashthapaliya.com/blog/2012/01/sandboxed-python-virtual-environments/

Apparently, pythonbrew has its own virtualenv wrapper, which has a tutorial at: http://suvashthapaliya.com/blog/2012/01/sandboxed-python-virtual-environments/

我讨厌那样做.是否可以将 virtualenvwrapper 与 pythonbrew(而不是 pythonbrew 的 venv 包装器)一起使用,以便能够为每个 venv 选择使用哪个 python 版本,并将它们与系统 python 版本分开?

I hate doing it like that though. Is it possible to use virtualenvwrapper along with pythonbrew (and not pythonbrew's venv wrapper) to be able to choose which python version to use for each venv, and keep them separate from the system python version?

另外,我不想使用 mkvirtualenv -p 标志,因为这意味着我需要手动安装 python3.3.我宁愿坚持使用包管理器来管理 python 版本.很难相信 python 中的任何东西都等同于 ruby​​ 中的 RVM ......除非我弄错了?

Also, I do not want to use mkvirtualenv -p flag, as this means I need to manually install python3.3. I'd rather stick to using a package manager to manage python versions. It's hard to believe that nothing in python equates to RVM in ruby... Unless I'm mistaken?

推荐答案

也许你应该看看 http://pypi.python.org/pypi/pythonbrew/ 代替.当我这样做时,我使用 pythonbrew 创建了 venv

Maybe you should look http://pypi.python.org/pypi/pythonbrew/ instead. When I did it, I used pythonbrew to create the venv

pythonbrew install 2.7.3
pythonbrew switch 2.7.3
pythonbrew venv create proj

像冠军一样工作.

我已经开始在我的 git 存储库下的 . 文件夹中创建我的虚拟环境,这样我就可以在不弄乱我的代码的情况下处理虚拟环境,如果我愿意的话,我可以重建它.我在使用 jenkins 时遇到了这种技术,它为你做 git clone,然后你必须弄清楚如何围绕它构建一个虚拟环境.

I've taken to creating my virtual environments in a .folder underneath my git repo so that I can dispose of the virtual environment without messing with my code and rebuild it if I so desire. I bumped into this technique while working with jenkins which does the git clone for you, then you have to figure out how to build a virtual environment around it.

Python/proj
    .proj           <---- Virtual environment is in here!
        lib
        site-packages
    settings
    requirements
    apps

我还有一个对我有用的 bash 函数.

I also have a bash function that does workon for me.

function workon() {
     if [ -d ~/Python/$1 ]
     then
            cd ~/Python/$1
            if [ -d .$1 ]
            then
                . .${1}/bin/activate
            else
                . bin/activate
                cd $1
            fi
     fi
}

这对于处理在虚拟环境中完成克隆的旧项目以及虚拟环境在项目中的新项目来说过于复杂.

This one is overly complicated to deal with old projects where the clone was done inside the virtual environment as well as the new ones where the virtual environment is inside the project.

这篇关于使用 pythonbrew 在不同的 virtualenv 中管理 python 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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