Milos
Milos

Reputation: 11

Python fails to run from shell despite being installed and py command running

I am trying to follow the tutorial of setting up an app for Django, but cannot progress past this part;
"python manage.py runserver" from https://docs.djangoproject.com/en/2.2/intro/tutorial01/

PS C:\Users\Elias\Documents\WebApp\mysite> ls


    Directory: C:\Users\Elias\Documents\WebApp\mysite


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2019-11-11   4:32 PM                mysite
-a----       2019-11-11   4:32 PM            647 manage.py


PS C:\Users\Elias\Documents\WebApp\mysite> py manage.py runserver
PS C:\Users\Elias\Documents\WebApp\mysite> python manage.py runserver
Program 'python' failed to run: No application is associated with the specified file for this operationAt line:1 char:1
+ python manage.py runserver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:1
+ python manage.py runserver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

PS C:\Users\Elias\Documents\WebApp\mysite> py -m manage.py runserver
PS C:\Users\Elias\Documents\WebApp\mysite> python ./manage.py runserver
Program 'python' failed to run: No application is associated with the specified file for this operationAt line:1 char:1
+ python ./manage.py runserver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:1
+ python ./manage.py runserver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

PS C:\Users\Elias\Documents\WebApp\mysite> ./manage.py runserver
PS C:\Users\Elias\Documents\WebApp\mysite> python -V
Program 'python' failed to run: No application is associated with the specified file for this operationAt line:1 char:1
+ python -V
+ ~~~~~~~~~.
At line:1 char:1
+ python -V
+ ~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

PS C:\Users\Elias\Documents\WebApp\mysite> py -V
Python 3.8.0
PS C:\Users\Elias\Documents\WebApp\mysite> python -m django --version
Program 'python' failed to run: No application is associated with the specified file for this operationAt line:1 char:1
+ python -m django --version
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:1
+ python -m django --version
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

PS C:\Users\Elias\Documents\WebApp\mysite> py -m django --version
2.2.7
PS C:\Users\Elias\Documents\WebApp\mysite> py ./manage.py runserver
PS C:\Users\Elias\Documents\WebApp\mysite> py ./manage.py runserver 8080

As you can see, Django is installed (but you can only see the version using 'py' and not 'python' for whatever bizarre reason). Even still, 'py ./manage.py runserver' was unable to run a server on either 127.0.0.1 from port 8000 or 8080. All environment variables are setup in
LOCALAPPDATA%\Programs\Python\Python38-32;\%LOCALAPPDATA%\Programs\Python\Python38-32\Lib\site-packages;%LOCALAPPDATA%\Programs\Python\Python38-32\Scripts.

Upvotes: 1

Views: 1680

Answers (2)

Milos
Milos

Reputation: 11

I fixed it by reinstalling python and clicking the option to disable the MAX_PATH character limit on installation.

Upvotes: 0

Sammy J
Sammy J

Reputation: 1066

In your environment variables, you must set up path to the \Python38-32\ only instead of site-packages, the reason is there is apython.exe file there which helps you run thepython manage.py runserver command.

Also make sure you have Django installed, the recommended way is to use a virtualenv, but if you are a beginner it's fine

Upvotes: 1

Related Questions