热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

django-admin。py和virtualenv在Windows上发布-django-admin.pyandvirtualenvissueonWindows

InmysystemthereisDjango1.2.3installedsystemwide:在我的系统中有Django1.2.3安装系统:C:\>python-c

In my system there is Django 1.2.3 installed system wide:

在我的系统中有Django 1.2.3安装系统:

C:\>python -c "import django; print django.get_version()"
1.2.3
C:\>django-admin.py --version
1.2.3

Then there is a virtual environment called venv in C:\dev where I installed Django 1.2.4:

然后在C:\dev中有一个名为venv的虚拟环境,我在其中安装了Django 1.2.4:

C:\> dev\venv\Scripts\activate.bat
(venv) C:\> python -c "import django; print django.get_version()"
1.2.4
(venv) C:\> django-admin.py --version
1.2.3

My questions:

我的问题:

  1. Why django-admin.py reports version 1.2.3, if the current Python (virtual) environment has django 1.2.4 installed?
  2. 为什么django-admin。py报告版本1.2.3,如果当前的Python(虚拟)环境已经安装了django 1.2.4 ?
  3. How can I use Django's 1.2.4 django-admin.py automatically when venv is active?
  4. 我如何使用Django的1.2.4 Django -admin。当venv激活时,py自动生效?

Additional info:

额外的信息:

  • virtualenv version: 1.5.1, Python version 2.7
  • virtualenv版本:1.5.1,Python版本2.7
  • command used to create venv: C:\dev\> virtualenv --no-site-packages venv
  • 用于创建venv: C:\dev\> virtualenv——无站点包的venv的命令
  • (venv) C:\> echo %PATH%

    (venv)C:\ % >回声%路径

    C:\dev\venv\Scripts; ...other paths...

    C:\开发\ venv \脚本;…其他路径…

  • shebang of django-admin.py in venv: #!C:\dev\Scripts\python.exe

    django-admin的住所。py venv:# ! C:\开发\ \ python.exe的脚本

Hope you can help, many thanks.

希望你能帮忙,非常感谢。

6 个解决方案

#1


19  

This is because your windows has associated .py extension with the globally installed python.exe. Therefore when you type django-admin.py, even though you're in a virtualenv, the global python is invoked, and it in turn finds your global django installation in its own site-packages. Try python django-admin.py to circumvent the association.

这是因为您的windows将.py扩展与全局安装的python.exe相关联。因此,当您键入django-admin时。py,即使您在一个virtualenv中,也调用全局python,然后它在自己的站点包中找到全局django安装。python django-admin试试。避免联系。

#2


17  

As shanyu already explained, it is because of *.py file associations made to your Python install executable instead of your virtualenv. However, to answer your second question differently, I solved this problem by creating a django-admin.bat in my virtualenv's Scripts directory. Its contents?

正如shanyu已经解释的,这是因为*。使您的Python安装可执行的py文件关联,而不是您的virtualenv。但是,为了以不同的方式回答第二个问题,我通过创建一个django-admin解决了这个问题。bat在我的virtualenv的脚本目录中。它的内容吗?

@echo off
python %VIRTUAL_ENV%\Scripts\django-admin.py %*

Now you can use django-admin startproject . The necessary PATH and VIRTUAL_ENV environment variables should have already been set correctly by virtualenv when you activated the environment.

现在可以使用django-admin startproject 。当您激活环境时,virtualenv应该已经正确地设置了必要的路径和VIRTUAL_ENV环境变量。

#3


1  

I just typed django-admin, without the .py file extension, and worked for me.

我只是输入了django-admin,没有.py文件扩展名,然后为我工作。

#4


1  

I had to point the "global python.exe" to my virtualenv in my project so I created my own activate.cmd

我必须指出“全局python”。在我的项目中创建了我自己的activate.cmd

set THE_PATH=c:\my-envs\my-specific-env\Scripts
ftype Python.File="%THE_PATH%\python.exe" %%1 %%*
%THE_PATH%\activate.bat

It changes the the file type association using windows command 'ftype'.

它使用windows命令“ftype”更改文件类型关联。

#5


0  

I had a similar problem on linux when I tried to use an already exisiting django project with a later installed virtualenv.

我在linux上遇到了类似的问题,当时我试图使用一个已经存在的django项目,该项目后来安装了virtualenv。

Is it possible that django-admin.py of django 1.2.4 is not on your path but that django-admin.py of your django 1.2.3 install is?

有可能是管理员吗?django 1.2.4中的py不在您的路径上,而是django-admin。您的django 1.2.3安装的py ?

That would explain your output from

这可以解释你的输出。

C:\> dev\venv\Scripts\activate.bat
(venv) C:\> python -c "import django; print django.get_version()"
1.2.4
(venv) C:\> django-admin.py --version
1.2.3

because the python command is on the path of your virtualenv but the django-admin.py file might not be.

因为python命令位于virtualenv的路径上,而django-admin。py文件可能不是。

As to your second question (assuming my guess above is correct): sym-link the django-admin.py file into your C:\dev\venv\Scripts directory, although I am not sure how that works on windows (are you using Cygwin?).

关于你的第二个问题(假设我上面的猜测是正确的):和管理员联系。py文件到您的C:\dev\venv\Scripts目录,尽管我不确定在windows上是如何工作的(您使用的是Cygwin吗?)

Of course you can always call it as python C:\path\to\django-admin.py (since the right python version is called) but of course that is a lot of typing.

当然,您可以将它命名为python C:\path\到\django-admin。py(因为调用了正确的python版本),但是当然这需要大量的输入。

#6


0  

i used Philip Nelson's solution but had to add quotes for spaces in my filename:

我使用了Philip Nelson的解决方案,但必须在文件名中添加空格:

python "%VIRTUAL_ENV%\Scripts\django-admin.py" %*

python脚本“% VIRTUAL_ENV % \ \ django-admin。py“% *


推荐阅读
author-avatar
lchakjet
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有