Issue
I don't know why but I can't run any comands in the vSCode Terminal.
For example, when I try python manage.py createsuperuser
I get an error that can't find Python. So I do py manage.py createsuperuser
and then I get a syntax error saying that manage.py doesn't exist or something like that.
Anyone know why this is and how I could fix it?
UPDATE: I currently have the following error:
Traceback (most recent call last):
File "C:\XXXXX\argon-dashboard-django\manage.py", line 13, 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:\XXXXX\argon-dashboard-django\manage.py", line 23, in <module>
main()
File "C:\XXXXX\argon-dashboard-django\manage.py", line 15, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Here's my manage.py
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
So there seems to be an import error somewhere. And I tried it with my venv activated:
(env) C:\Users\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django>py manage.py createsuperuser
Traceback (most recent call last):
File "C:\Users\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django\manage.py", line 13, 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\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django\manage.py", line 23, in <module>
main()
File "C:\Users\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django\manage.py", line 15, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Solution
When I got the same issue in my windows machine..(probably occurred because I did some C drive repair)
I also can't able to run python manage.py runserver
, I got the same error
ModuleNotFoundError: No module named 'Django'
I did the following steps.. to overcome my error:
- On my main folder terminal Check If you have already a "requiremnts.txt" file skip this step else run this command:
pip freeze > requirements.txt
,if it saves all your packages then only do other steps - Delete Venv folder from the main directory.
- Again install virtual environments and activate Venv.
- then run this command
pip install -r requirements.txt
this will install all your packages back. - Run again
python manage.py runserver
, It will work fine
Answered By - RENJITH V.S Answer Checked By - Robin (WPSolving Admin)