20
Edit your manage.py
file as given below:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DEGNet.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?"
)
execute_from_command_line(sys.argv)
Note that from exc
is removed from the file. It is not required in the manage.py
file.
- [Django]-How to format time in django-rest-framework's serializer?
- [Django]-Annotate a queryset with the average date difference? (django)
- [Django]-How to produce a 303 Http Response in Django?
7
- Make sure that your virtualenv is activated. Suppose the name of your virtualenv is pythonpy, then run these commands:
virtualenv pythonpy
workon pythonpy #After running these command, you should see something like this but your file path may be different: โ(pythonpy) C:\Users\ MyDjangoProject \ - Then go to the project folder which contains manage.py
(pythonpy) C:\Users\ MyDjangoProject \ #Same path as above - Then simple run the server:
python manage.py runserver #This will give you the project path to the localhost. Copy and paste the URL in the browser and should work.
- [Django]-Using django-rest-interface
- [Django]-Passing STATIC_URL to file javascript with django
- [Django]-How to test "render to template" functions in django? (TDD)
3
Try (from command line):
python3 manage.py runserver
If I used this (no python3) instead:
python manage.py runserver
the error persisted. This method allows you to not have to alter manage.py (so you can keep โfrom excโ).
- [Django]-How to test auto_now_add in django
- [Django]-Django Admin Form for Many to many relationship
- [Django]-Python (and Django) best import practices
3
You just forgot to activate the virtual environment , do it like that :
source /home/adel/Dev/Python/DjangoProjects/myproject/venv/bin/activate
And than you can run the server :
python manage.py runserver
- [Django]-Django-Forms with json fields
- [Django]-Django related_name for field clashes
- [Django]-Why won't Django use IPython?
2
iโve also got this error but solve it by installing pipenv first,
try run this first
pipenv shell django==2.1
then you should be able to run
python3 manage.py runserver
- [Django]-How to format time in django-rest-framework's serializer?
- [Django]-What is the difference render() and redirect() in Django?
- [Django]-Django: Open uploaded file while still in memory; In the Form Clean method?
2
Ensure youโre running the app from virtualenv i.e if youโve created a virtualenv for your project, then activate the venv first.
me@debian:~/Desktop/webapp$source venv/bin/activate
(venv) me@debian:~/Desktop/webapp$python manage.py runserver
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
- [Django]-Check if celery beat is up and running
- [Django]-Switching to PostgreSQL fails loading datadump
1
Whatโs happening is that the wrong version of python is being used, which may not have all the dependencies in your virtualenv. I get this error when using sudo manage.py
: using sudo
changes the version of python which is being used to /usr/bin/python
.
The problem is solved by specifying which version of python to use when using sudo
:
sudo /path/to/my/env/bin/python manage.py makemigrations
- [Django]-Django models.py Circular Foreign Key
- [Django]-Django get objects not referenced by foreign key
- [Django]-Pytest.mark.parametrize with django.test.SimpleTestCase
1
I have met the same problem, and I find it strange because I have activated the virtualenvironment and set the python3, however, I meet this problem when I use this statement โpython manage.py runserverโ.I use this statement often but I meet this only once, and I restart my virtualenvironment and it runs, hope you wil,too.
- [Django]-How to understand lazy function in Django utils functional module
- [Django]-Get count of related model efficiently in Django
- [Django]-How do you dynamically hide form fields in Django?
1
I was facing the same issue.
Activated venv & ran python manage.py runserver
wasnโt working.
I could see the venv was activated but still it wasnโt working. Then tried python3 manage.py runserver
which got rid of exc
issue but now it wasnt detecting my installed libraries.
The change I made that broke it was renaming the base folder ( kind of same situation like OP base folder location was different now).
But wait, how does this impact anything?
A variable that stores a full path to
venv
insidevenv/bin/activate
is
now no longer valid.
Resolution:
- deactivate venv if already running
- open venv/bin/activate
- search for
VIRTUAL_ENV
variable and rename as per the new folder changes made. - activate venv
source venv/bin/activate
- run
python manage.py runserver
Tada, everything is back to normal and we can happily enjoy our lemonade.
- [Django]-Django: remove a filter condition from a queryset
- [Django]-Substring in a django template?
- [Django]-Django multiple template inheritance โ is this the right style?
0
Iโve got also the same issue with Python 3.4.4 and Django 2.0. I tried the last solution, nothing works (no need to delete that: from exc
on the line 14).
Just run your server with:
python manage.py runserver
Instead of:
./manage.py runserver #or '.\manage.py runserver' for Windows
- [Django]-Django: Example of generic relations using the contenttypes framework?
- [Django]-Pytest.mark.parametrize with django.test.SimpleTestCase
- [Django]-Are sessions needed for python-social-auth
0
I have no problem running this way๏ผ
sudo ./**(your path)**/bin/python manage.py runserver
- [Django]-Celery discover tasks in files with other filenames
- [Django]-Django: For Loop to Iterate Form Fields
- [Django]-How to get getting base_url in django template
0
i had the same problem. I solved it by simply specifying the python
version i.e type python3 manage.py runserver
instead of python manage.py runserver
- [Django]-Malformed Packet: Django admin nested form can't submit, connection was reset
- [Django]-Substring in a django template?
- [Django]-Disable session creation in Django
0
i re installed the v env
virtualenv venv --python=python3.7
i insttalled django
it worked
- [Django]-Django: guidelines for speeding up template rendering performance
- [Django]-Filtering using viewsets in django rest framework
- [Django]-Remove Labels in a Django Crispy Forms
- [Django]-Django: remove a filter condition from a queryset
- [Django]-Django admin default filter
- [Django]-What does 'many = True' do in Django Rest FrameWork?
0
Do this first on your command line where your Env folder is found:
source Env/bin/activate
Then now navigate to your project directory and do:
python manage.py runserver
It works!!
- [Django]-Django related_name for field clashes
- [Django]-Remove Labels in a Django Crispy Forms
- [Django]-In django, how do I sort a model on a field and then get the last item?
- [Django]-Using django-rest-interface
- [Django]-Paginate relationship in Django REST Framework?
- [Django]-How to add superuser in Django from fixture