#31716: django-admin runserver mostly does not work on Windows
-----------------------------------+--------------------------------------
     Reporter:  Christian Ullrich  |                    Owner:  nobody
         Type:  Uncategorized      |                   Status:  new
    Component:  Uncategorized      |                  Version:  3.0
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Changes (by Christian Ullrich):

 * status:  closed => new
 * resolution:  worksforme =>


Comment:

 Here you go.

 {{{
 C:\Daten>py -m venv test

 C:\Daten>test\Scripts\activate

 (test) C:\Daten>python -c "import sys; print(sys.version)"
 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit
 (AMD64)]

 (test) C:\Daten>python -m pip install -U pip setuptools Django
 Looking in indexes: https://nexus/repository/PyPI-mirror/simple
 Collecting pip
   Downloading https://nexus/repository/PyPI-
 mirror/packages/pip/20.1.1.post1/pip-20.1.1.post1-py2.py3-none-any.whl
 (1.6MB)
      |████████████████████████████████| 1.6MB 656kB/s
 Collecting setuptools
   Downloading https://nexus/repository/PyPI-
 mirror/packages/setuptools/47.3.1/setuptools-47.3.1-py3-none-any.whl
 (582kB)
      |████████████████████████████████| 583kB 726kB/s
 Collecting Django
   Downloading https://nexus/repository/PyPI-
 mirror/packages/django/3.0.7/Django-3.0.7-py3-none-any.whl (7.5MB)
      |████████████████████████████████| 7.5MB 726kB/s
 Collecting asgiref~=3.2 (from Django)
   Downloading https://nexus/repository/PyPI-
 mirror/packages/asgiref/3.2.9/asgiref-3.2.9-py3-none-any.whl
 Collecting pytz (from Django)
   Downloading https://nexus/repository/PyPI-
 mirror/packages/pytz/2020.1/pytz-2020.1-py2.py3-none-any.whl (510kB)
      |████████████████████████████████| 512kB 726kB/s
 Collecting sqlparse>=0.2.2 (from Django)
   Downloading https://nexus/repository/PyPI-
 mirror/packages/sqlparse/0.3.1/sqlparse-0.3.1-py2.py3-none-any.whl (40kB)
      |████████████████████████████████| 40kB 871kB/s
 Installing collected packages: pip, setuptools, asgiref, pytz, sqlparse,
 Django
   Found existing installation: pip 19.2.3
     Uninstalling pip-19.2.3:
       Successfully uninstalled pip-19.2.3
   Found existing installation: setuptools 41.2.0
     Uninstalling setuptools-41.2.0:
       Successfully uninstalled setuptools-41.2.0
 Successfully installed Django-3.0.7 asgiref-3.2.9 pip-20.1.1.post1
 pytz-2020.1 setuptools-47.3.1 sqlparse-0.3.1

 (test) C:\Daten\dtest>pip list
 Package    Version
 ---------- ------------
 asgiref    3.2.9
 Django     3.0.7
 pip        20.1.1.post1
 pytz       2020.1
 setuptools 47.3.1
 sqlparse   0.3.1
 }}}

 pip 20.1.1.post1 is 20.1.1 minus the information disclosure. For our
 purposes it's the same.

 {{{
 (test) C:\Daten>openssl.exe sha256 test\Scripts\django-admin.exe
 SHA256(test\Scripts\django-admin.exe)=
 24a24fefaaa27e069474985353cceacc9cb4128a35f50e99af487768d4255c90
 }}}

 No idea if they are identical between different installations.

 {{{
 (test) C:\Daten>django-admin startproject dtest

 (test) C:\Daten>set PYTHONPATH=C:\Daten\dtest

 (test) C:\Daten>set DJANGO_SETTINGS_MODULE=dtest.settings

 (test) C:\Daten>django-admin

 Type 'django-admin help <subcommand>' for help on a specific subcommand.

 Available subcommands:

 [django]
     check
     compilemessages
     createcachetable
     dbshell
     diffsettings
     dumpdata
     flush
     inspectdb
     loaddata
     makemessages
     makemigrations
     migrate
     runserver
     sendtestemail
     shell
     showmigrations
     sqlflush
     sqlmigrate
     sqlsequencereset
     squashmigrations
     startapp
     startproject
     test
     testserver
 Note that only Django core commands are listed as settings are not
 properly configured (error: No module named 'dtest').

 (test) C:\Daten>cd dtest

 (test) C:\Daten\dtest>django-admin runserver
 C:\Program Files\Python38\python.exe: can't open file
 'C:\Daten\test\Scripts\django-admin': [Errno 2] No such file or directory
 }}}

 Note the missing extension.

 {{{
 (test) C:\Daten\dtest>django-admin runserver --noreload
 Performing system checks...

 System check identified no issues (0 silenced).

 You have 17 unapplied migration(s). Your project may not work properly
 until you apply the migrations for app(s): admin, auth, contenttypes,
 sessions.
 Run 'python manage.py migrate' to apply them.
 June 17, 2020 - 08:58:46
 Django version 3.0.7, using settings 'dtest.settings'
 Starting development server at http://127.0.0.1:8000/
 Quit the server with CTRL-BREAK.
 ^C
 }}}

 Works with --noreload.

 Now let's see what it is actually trying to execute.

 {{{
 (test) C:\Daten\dtest>vi ..\test\Lib\site-
 packages\django\utils\autoreload.py
 }}}

 Before line 230 (the subprocess.run call in restart_with_reloader()),
 insert "print(args)".

 {{{
 (test) C:\Daten\dtest>django-admin runserver
 ['c:\\daten\\test\\scripts\\python.exe', 'C:\\Daten\\test\\Scripts
 \\django-admin', 'runserver']
 C:\Program Files\Python38\python.exe: can't open file
 'C:\Daten\test\Scripts\django-admin': [Errno 2] No such file or directory
 }}}

 This cannot possibly work.

 {{{
 (test) C:\Daten\dtest>dir ..\test\scripts
  Volume in drive C is Windows
  Volume Serial Number is 8EC9-7F66

  Directory of C:\Daten\test\scripts

 2020-06-17  08:54    <DIR>          .
 2020-06-17  08:54    <DIR>          ..
 2020-06-17  08:53             2.273 activate
 2020-06-17  08:53               950 activate.bat
 2020-06-17  08:53            18.454 Activate.ps1
 2020-06-17  08:53               368 deactivate.bat
 2020-06-17  08:54           106.388 django-admin.exe
 2020-06-17  08:54               142 django-admin.py
 2020-06-17  08:54           106.355 easy_install-3.8.exe
 2020-06-17  08:54           106.355 easy_install.exe
 2020-06-17  08:54           106.346 pip.exe
 2020-06-17  08:54           106.346 pip3.8.exe
 2020-06-17  08:54           106.346 pip3.exe
 2020-06-17  08:53           532.040 python.exe
 2020-06-17  08:53           531.016 pythonw.exe
 2020-06-17  08:54           106.341 sqlformat.exe
 2020-06-17  08:54    <DIR>          __pycache__
               14 File(s)      1.829.720 bytes
                3 Dir(s)  [...] bytes free

 (test) C:\Daten\dtest>vi -b ..\test\scripts\django-admin.exe
 }}}

 Edit the Python block at the end to not match and remove .exe anymore. I
 replaced "\.exe" with "\.rxe" in the regex.

 {{{
 (test) C:\Daten\dtest>django-admin runserver
 ['c:\\daten\\test\\scripts\\python.exe', 'C:\\Daten\\test\\Scripts
 \\django-admin.exe', 'runserver']
 Watching for file changes with StatReloader
 Performing system checks...

 System check identified no issues (0 silenced).

 You have 17 unapplied migration(s). Your project may not work properly
 until you apply the migrations for app(s): admin, auth, contenttypes,
 sessions.
 Run 'python manage.py migrate' to apply them.
 June 17, 2020 - 09:07:47
 Django version 3.0.7, using settings 'dtest.settings'
 Starting development server at http://127.0.0.1:8000/
 Quit the server with CTRL-BREAK.
 ^C
 }}}

 With the extension left alone, this works now, too.

     The .exe. generally isn't needed.

 Not if it is the command name. Here it is an argument on python's command
 line, though, and python does not guess about missing extensions.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31716#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.456ae8f670777cf44dafef08f39a8f31%40djangoproject.com.

Reply via email to