django-admin.py and virtualenv issue on Windows

后端 未结 6 2019
青春惊慌失措
青春惊慌失措 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 used Philip Nelson's solution but had to add quotes for spaces in my filename:

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

    0 讨论(0)
  • 2021-02-08 03:52

    I had to point the "global python.exe" to my virtualenv in my project so I created my own 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'.

    0 讨论(0)
  • 2021-02-08 04:02

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

    0 讨论(0)
  • 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 <project_name>. The necessary PATH and VIRTUAL_ENV environment variables should have already been set correctly by virtualenv when you activated the environment.

    0 讨论(0)
  • 2021-02-08 04:07

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

    0 讨论(0)
  • 2021-02-08 04:13

    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.

    0 讨论(0)
提交回复
热议问题