(windows server 2016) (python/Django) Couldn't import Django - python

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)

Related

Cannot run Django with active venv in zsh

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.

Django install and enviroment are no longer recognized

I just went to run my Django development server in the Django project that I'm working on and I got this...
(baseballwebenv) C:\DjangoProjects\BaseballWebsite\baseballweb>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "C:\Users\Nick\Anaconda3\envs\baseballwebenv\lib\site-packages\django\__init__.py", line 1, in <module>
from django.utils.version import get_version
File "C:\Users\Nick\Anaconda3\envs\baseballwebenv\lib\site-packages\django\utils\version.py", line 4, in <module>
import subprocess
File "c:\users\nick\anaconda3\Lib\subprocess.py", line 178, in <module>
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
ImportError: cannot import name 'ABOVE_NORMAL_PRIORITY_CLASS'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 14, 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?
As you can see I am by my runserver command, I am in my virtual environment. I recently upgraded all of my Anaconda packages, thinking everything was protected in the virtual environment. I would suspect this problem is related to that, but I'm not sure. How do I get my project up and running again? If someone wants to see certain files, I can add those as well.

ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activ

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

ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?

i added the python path in environment variable then also it is giving me same error so please anyone can help me
(py1) C:\Users\NIKITA GULHANE\projects\raksh>python manage.py
runserver Traceback (most recent call last): File "manage.py", line
8, in
from django.core.management import execute_from_command_line File
"C:\Users\NIKITA~1\Envs\py1\lib\site-packages\django__init__.py",
line 1, in
from django.utils.version import get_version File "C:\Users\NIKITA~1\Envs\py1\lib\site-packages\django\utils\version.py",
line 1, in
import datetime ModuleNotFoundError: No module named 'datetime'
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?
I found you have to ensure Django is imported in the file wsgi.py.
Hope this answer is useful

Cant find django module . import error

I have installed Django and it is already in the package. But when i run python manage.py runserver.I am getting this error
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: 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 <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?

Categories

Resources