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.
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
apologies if this question has been asked a ton, I'm sure it has, and I've been trying for days to figure this out, but I can't wrap my head around it. I've been developing in Python for over 1.5 years, so I'm not a complete beginner.
I can't get Django to work in my command prompt. An example is, when I try to use py .\manage.py makemigrations this is what I get:
Traceback (most recent call last):
File ".\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 ".\manage.py", line 22, in <module>
main()
File ".\manage.py", line 13, 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?
Now, I can see what the error says. The thing is my virtual environment is activated and it has Django installed, as seen here. Moreover, even if I executed outside my venv, it still doesn't work, even though I have all necessary Python directories in my PATH, as seen here.
I have verified that django-admin is installed on both my venv and my system, as well as Django itself, since I can import it on my Python Console. The version is 3.1.7. I have also tried reinstalling Django and it didn't work.
Another error I get, when I attempt to run Django console through PyCharm is this:
Traceback (most recent call last):
File "<input>", line 6, in <module>
File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\django\conf\__init__.py", line 82, in __getattr__
self._setup(name)
File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\django\conf\__init__.py", line 63, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I hope this helps you come up with any idea. Could anyone please share any insight on why I'm getting this? I would greatly appreciate it.
Edit: I have installed Django through PIP:
py -m pip install django
py -m pip install djangorestframework
py -m pip install django-admin
Also, Django is imported correctly from the Python Console within the venv:
>>> import django
>>> django
<module 'django' from 'C:\\Users\\user\\AppData\\Roaming\\Python\\Python39\\site-packages\\django\\__init__.py'>
in cmd to create a virtualenv
python -m venv virtualenv_name
to enable virtualenv
virtualenv_name\scripts\activate.bat
then
pip install django
and to create a project
django-admin startproject projectname
to run the project
cd projectname
python manage.py runserver
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.
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