I've got a properly activated venv in zsh, because I can see (venv) at the beginning of the prompt, but when I try to run Django with the command python manage.py runserver I've the error
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
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?
If I run which which python I can see python: aliased to /usr/local/bin/python3.7 that it seems wrong, because I expect something like /Users/myuser/Python-Projects/test/venv/bin/python. In fact if I disable the venv the result of which python is the same.
I tried to the same steps with bash and everything works fine, so I guess I've got something wrong with zsh, but I don't know what.
As a workaround to run Django I must run the command venv/bin/python manage.py runserver, so it's like the root python in some way is broken. I tried to update zsh to latest version, but problem is still there.
Any ideas?
Problem found. It was an alias for python in .zshrc.
Related
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?
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
trying to start a project with django. I downloaded django and virtualenv package and everything went well ( I followed the installing instructions ) but, when I trued ti run in the command line :
python manage.py runserver
it displays an error and says that django does not exist and something about PYHONPATH.
does anybody know a wat to get it installed and start a project easily? some how no matter what I do nothing works.
thanks
the error:
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\shirl\my_flights\manage.py", line 14, in
import django
ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\shirl\my_flights\manage.py", line 16, in
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?
You need to activate the virtual environment first.
python manage.py runserver not working in pycharm and giving this error even I have put manage.py in settings of Django in Language & Framework Django Tab.. what it could be?
(venv) C:\Users\ionezation\PycharmProjects\ecomesite\ecs>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, 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 "manage.py", line 21, in <module>
main()
File "manage.py", line 16, in main
) from exc
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?
seems you need to specify python interpreter
File -> Settings -> Project -> Project Interpreter -> icon gear wheel -> Add ->
Existing environment
The full error message:
Traceback (most recent call last):
File "manage.py", line 9, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django.core'; 'django' is not a package
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
) from exc
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?
I have tried adding django directly to the PYTHONPATH, no dice
I have created a virtual environment and installed django in it, still nothing
According to pip freeze I got Django 2.1.2 installed
I'm pretty sure I'm using python 3.7.0
Apparently I can import django just fine (by just typing "import django" in an empty test.py file), but when I try to import django.core it gives me the following error:
Traceback (most recent call last):
File "test.py", line 7, in
import django.core
ModuleNotFoundError: No module named 'django.core'; 'django' is not a package
(stackoverflow won't let me format it as code for some reason)
I made a python virtual environment using virtualenv, then installed django.
If I input 'django-admin --version' command, it outputs 1.11.13 when using virtualenv.
However, when I input ' python3.6 manage.py createsuperuser', it output below:
Traceback (most recent call last):
File "manage.py", line 8, in
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 "manage.py", line 14, in
) from exc
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?
Thanks in advance to any suggestions!
more information here:
In a console of 'python3.6':
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
>>> import sys
>>> sys.path
['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
when you use virtualenv you don't need to type ver. of python. I think python3.6 is /usr/bin/python3.6
just type:
python manage.py createsuperuser