django-admin.py and virtualenv issue on Windows

后端 未结 6 2025
青春惊慌失措
青春惊慌失措 2021-02-08 03:28

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         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 04:07

    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 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.

提交回复
热议问题