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
Related
While I was deployed my django app in heroku, I run:
heroku run python3 manage.py migrate
and I get this messahe in my console:
File "manage.py", line 16
) from exc
^
SyntaxError: invalid syntax
my manage.py file is actually:
#!~/.virtualenvs/djangodev/bin/python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myApp3.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()
When I run python => python3, the next message is displayed:
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?
You need to set up a virtual enviorment first. Then install django in the virtual environment. You can do this through a thing called pipenv. you need to add this to your project by doing. python install pipenv. Then install python in that virtual enviorment by doing pipenv install django. when django installs you can then do your migrations.
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.
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.
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