Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-admin.py and virtualenv issue on Windows

In my system there is Django 1.2.3 installed system wide:

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\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. How can I use Django's 1.2.4 django-admin.py automatically when venv is active?

Additional info:

  • virtualenv version: 1.5.1, Python version 2.7
  • command used to create venv: C:\dev\> virtualenv --no-site-packages venv
  • (venv) C:\> echo %PATH%

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

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

Hope you can help, many thanks.

like image 940
Paolo Avatar asked Jan 29 '11 15:01

Paolo


People also ask

Why my Django-admin is not working?

'django-admin' is not recognized as an internal or external command, operable program or batch file. To fix this, first close the terminal window and relaunch it with administrator privileges. Once you launch the elevated terminal window change directory to where you wish to start your Django project.


1 Answers

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.

like image 117
shanyu Avatar answered Oct 26 '22 09:10

shanyu