django-admin.py and virtualenv issue on Windows
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.
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?
@echo offpython %VIRTUAL_ENV%\Scripts\django-admin.py %*
Now you can use django-admin startproject <project_name>
. The necessary PATH
and VIRTUAL_ENV
environment variables should have already been set correctly by virtualenv when you activated the environment.
I had a similar problem on linux when I tried to use an already exisiting django project with a later installed 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?
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 --version1.2.3
because the python
command is on the path of your virtualenv but the django-admin.py
file might not be.
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?).
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.