-1

I was working on a django project served as a backend for a small personal site, the built-in localhost server by django runs smoothly until I accidentally removed the app execution alias of python in windows 10(It just happened after done that, might not be the culprit). the situation is that when I use manage.py, it always results in a no module named "django"

(venv) C:\Users\hongl\PycharmProjects\fluentdesign>manage.py runserver
Traceback (most recent call last):
  File "C:\Users\hongl\PycharmProjects\fluentdesign\manage.py", line 11, in main
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\hongl\PycharmProjects\fluentdesign\manage.py", line 22, in <module>
    main()
  File "C:\Users\hongl\PycharmProjects\fluentdesign\manage.py", line 13, in main
    raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHO
NPATH environment variable? Did you forget to activate a virtual environment?

I tried to resolve it a bit and was only baffled to find the terminal, with which the venv had already been activated, was always being attached to the system-wise python when running which has no django installed in it. The following is python console from venv:

(venv) C:\Users\hongl\PycharmProjects\fluentdesign>python
Python 3.8.9 (tags/v3.8.9:a743f81, Apr  6 2021, 14:02:34) [MSC v.1928 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(*sys.path, sep='\n')

C:\Users\hongl\PycharmProjects\fluentdesign\venv\Scripts
C:\Users\hongl\PycharmProjects\fluentdesign
C:\Users\hongl\AppData\Local\Programs\Python\Python38\python38.zip
C:\Users\hongl\AppData\Local\Programs\Python\Python38\DLLs
C:\Users\hongl\AppData\Local\Programs\Python\Python38\lib
C:\Users\hongl\AppData\Local\Programs\Python\Python38
C:\Users\hongl\PycharmProjects\fluentdesign\venv
C:\Users\hongl\PycharmProjects\fluentdesign\venv\lib\site-packages

I just want to know what happened to the django built-in server by manage.py, why can't i run it with the python in venv which has every necessary packages installed instead of system-wise python?

Hongleigiy
  • 11
  • 4
  • I just tried ```python manage.py runserver``` which works, but I am still curious why I can run ```manage.py runserver``` without ```python``` prefix before the situation and now I have to type in python – Hongleigiy Apr 13 '21 at 03:01

1 Answers1

0

I'm unable to comment, but I'll post as an answer though I'm not sure this will fix your problem.

Are you positive that Django is install on your venv? try pip list or pip3 list (depending on system) if django doesn't pop up in that list you may need to install it.

If you're using pycharm you can use a visual interface to modify your venv see here

Ryan Rau
  • 153
  • 1
  • 7