Windows 上的 virtualenv:不覆盖已安装的软件包 [英] virtualenv on Windows: not over-riding installed package

查看:27
本文介绍了Windows 上的 virtualenv:不覆盖已安装的软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的设置是 Windows 上的 Python 2.5/Django 1.1.1.我想在某些项目中开始使用 Django 1.2,但不能将其用于所有项目.这正是我拥有 virtualenv 的那种东西.但是,我遇到了一个我从未遇到过的问题,而且 Google 很难找到:将 Django 1.2 安装到 virtualenv 中对我没有任何影响.如果我然后激活环境并执行

My current setup is Python 2.5/ Django 1.1.1 on Windows. I want to start using Django 1.2 on some projects, but can't use it for everything. Which is just the sort of thing I've got virtualenv for. However, I'm running into a problem I've never encountered and it's hard to Google for: installing Django 1.2 into a virtualenv has no effect for me. If I then activate the environment and do

  • 蟒蛇
  • 导入 django
  • django.VERSION

我得到1.1.1 Final".Django安装在我环境的site-packages目录下,root下的init文件显示是1.2.但是环境回退到 1.1.1,即使我使用 --no-site-packages 标志创建环境.我在搞什么鬼?

I get "1.1.1 Final". Django is installed in the site-packages directory of my environment and the init file in the root shows that it is 1.2. But the environment falls back to 1.1.1, even if I create the environment with the --no-site-packages flag. What am I screwing up?

推荐答案

根据您在 bitbucket 提交的错误,您似乎正在使用 PYTHONPATH 环境变量指向包含一些包(包括 Django 1.1)的目录.1.按照设计,PYTHONPATH 始终在您的 sys.path 中排在第一位,即使您激活了 virtualenv(因为 PYTHONPATH 在您的直接和即时控制之下,人们使用它进行本地覆盖).

Based on the bug you filed at bitbucket, it looks like you're using the PYTHONPATH environment variable to point to a directory with some packages, including Django 1.1.1. By design, PYTHONPATH always comes first in your sys.path, even when you have a virtualenv activated (because PYTHONPATH is under your direct and immediate control, and people use it for local overrides).

在这种情况下,如果您不想在激活 virtualenv 时使用 PYTHONPATH,则需要自己处理;也许通过创建一个自定义批处理文件来调用 virtualenv 的 activate.bat 并修改 PYTHONPATH.

In this case, if you don't want that PYTHONPATH when this virtualenv is activated, you'll need to take care of that yourself; perhaps by creating a custom batch file that both calls the virtualenv's activate.bat and also modifies PYTHONPATH.

这篇关于Windows 上的 virtualenv:不覆盖已安装的软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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