13π
As known this was a path issue.
the base of my custom packages shared a name with a directory set in a /etc/profile. The packages were in a different location however for the webserver. So I removed the offending entries from my $PYTHONPATH and was good to go!
Thanks for the help.
175π
If, like me, you are running your django in a virtualenv, and getting this error, look at your manage.py
.
The first line should define the python executable used to run the script.
This should be the path to your virtualenvβs python, but it is something wrong like /usr/bin/python, which is not the same path and will use the global python environment (and packages will be missing).
Just change the path into the path to the python executable in your virtualenv.
You can also replace your shebang line with #!/usr/bin/env python
. This should use the proper python environment and interpreter provided that you activate your virtualenv first (I assume you know how to do this).
- [Django]-Django CMS fails to synch db or migrate
- [Django]-Warning: Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
- [Django]-How to run a celery worker with Django app scalable by AWS Elastic Beanstalk?
42π
If you are in a virtualenv you need to activate it before you can run ./manage.py βcommandβ
source path/to/your/virtualenv/bin/activate
if you config workon in .bash_profile or .bashrc
workon yourvirtualenvname
*please dont edit your manage.py file maybe works by isnt the correct way and could give you future errors
- [Django]-Add rich text format functionality to django TextField
- [Django]-Allowing RabbitMQ-Server Connections
- [Django]-How do Django models work?
32π
I had the same problem because I was installing Django as a super user, thus not in my virtualenv. You should not do sudo pip install Django
Instead, install it this way:
$ source ./bin/activate
$ pip install Django
- [Django]-Filtering using viewsets in django rest framework
- [Django]-CORS error while consuming calling REST API with React
- [Django]-POST jQuery array to Django
19π
Please, reinstall django with pip:
sudo pip install --upgrade django==1.3
(Replace 1.3 to your django version)
- [Django]-How can I list urlpatterns (endpoints) on Django?
- [Django]-Cannot set Django to work with smtp.gmail.com
- [Django]-Embed YouTube video β Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
9π
Another possible reason for this problem is that your OS runs python3 by default.
Either you have to explicitly do: python2 manage.py
or you need to edit the shebang of manage.py
, like so:
#!/usr/bin/env python2
or if you are using python3:
#!/usr/bin/env python3
- [Django]-How to express a One-To-Many relationship in Django?
- [Django]-Strings won't be translated in Django using format function available in Python 2.7
- [Django]-How to get the name of current app within a template?
7π
You are probably using virtualenvwrapper. Donβt forget to select your enviroment by running:
$ workon env_name
- [Django]-__init__() got an unexpected keyword argument 'mimetype'
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-What's the difference between CharField and TextField in Django?
7π
I had this error while trying to run an embedded system (using django of course) on a Raspberry Pi 2 (and not a VM)
Running this:
sudo pip install Django
Made the trick!
- just in case a fellow using Raspbian/Jessie gets this
- [Django]-How about having a SingletonModel in Django?
- [Django]-Django: using more than one database with inspectdb?
- [Django]-How to 'bulk update' with Django?
- [Django]-What is a django.utils.functional.__proxy__ object and what it helps with?
- [Django]-What is the difference render() and redirect() in Django?
- [Django]-Django β Website Home Page
4π
For me, my server was using Python 2.4. I simply looked up Python 2.7, which was installed on my server, and created an alias.
alias python=python2.7
If you need to know more, I found the solution here
- [Django]-OneToOneField() vs ForeignKey() in Django
- [Django]-Django: remove a filter condition from a queryset
- [Django]-How can I create a deep clone of a DB object in Django?
4π
I was getting the same problem while I trying to create a new app. If you write python manage.py startapp myapp
, then it looks for usr/bin/python. But you need this βpythonβ which is located in /bin directory of your virtual env path. I solved this by mentioning the virtualenvβs python path just like this:
<env path>/bin/python manage.py startapp myapp
- [Django]-Handling race condition in model.save()
- [Django]-How to pass information using an HTTP redirect (in Django)
- [Django]-Django count RawQuerySet
4π
Solved it!!!
After searching for ages and trying all these other suggestions which didnβt work, I finally found the solution for my setup.
My setup/scenario:
- Windows, Python27
- My django project is checked out via svn
- when running python manage.py runserver in the new folder, I got the import error
- python manage.py runserver used to work in the original folder (which I would commit changes from) until I deleted it
Solution
Remove any the folder named django in the same directory of manage.py
Thats rightβ¦as soon as I removed the folder βdjangoβ which only contained a __init__.py fileβ¦I could run the server again!
Have no idea why though
- [Django]-Django migration strategy for renaming a model and relationship fields
- [Django]-Where to put business logic in django
- [Django]-Django β how to visualize signals and save overrides?
3π
Try change your first line of manage.py.
Change
#!/usr/bin/python
by
#!/usr/bin/env python
- [Django]-VueJS + Django Channels
- [Django]-Are sessions needed for python-social-auth
- [Django]-Where does pip install its packages?
3π
==================================SOLUTION=========================================
First goto: virtualenv
by running the command:
source bin/activate
and install django because you are getting the error related to βimport djangoβ:
pip install django
Then run:
python manage.py runserver
(Note: please change βrunserverβ to the program name you want to run)
For the same issue, it worked in my case.
==================================Synopsis=========================================
ERROR:
(Development) Rakeshs-MacBook-Pro:src rakesh$ 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
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?
(Development) Rakeshs-MacBook-Pro:src rakesh$
(Development) Rakeshs-MacBook-Pro:src rakesh$
(Development) Rakeshs-MacBook-Pro:src rakesh$ python -Wall manage.py test
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?
AFTER INSTALLATION of django:
(Development) MacBook-Pro:src rakesh$ pip install django
Collecting django
Downloading https://files.pythonhosted.org/packages/51/1a/e0ac7886c7123a03814178d7517dc822af0fe51a72e1a6bff26153103322/Django-2.1-py3-none-any.whl (7.3MB)
100% |ββββββββββββββββββββββββββββββββ| 7.3MB 1.1MB/s
Collecting pytz (from django)
Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl (510kB)
100% |ββββββββββββββββββββββββββββββββ| 512kB 4.7MB/s
Installing collected packages: pytz, django
AFTER RESOLVING:
(Development) MacBook-Pro:src rakesh$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 05, 2018 - 04:39:02
Django version 2.1, using settings 'trydjango.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[05/Aug/2018 04:39:15] "GET / HTTP/1.1" 200 16348
[05/Aug/2018 04:39:15] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[05/Aug/2018 04:39:15] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
[05/Aug/2018 04:39:15] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
[05/Aug/2018 04:39:15] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
Not Found: /favicon.ico
[05/Aug/2018 04:39:16] "GET /favicon.ico HTTP/1.1" 404 1976
Good luck!!
- [Django]-Django simple_tag and setting context variables
- [Django]-Django. A good tutorial for Class Based Views
- [Django]-How can I filter a date of a DateTimeField in Django?
2π
For those of you using Django 1.6 or newer, note that execute_manager was removed. There is a solution posted in the second SO answer here.
- [Django]-Django content-type : how do I get an object?
- [Django]-Itertools.groupby in a django template
- [Django]-Convert Django Model object to dict with all of the fields intact
2π
Store the python python path in a variable and execute.This would include the otherwise missing packages.
python_path= `which python`
$python_path manage.py runserver
- [Django]-You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
- [Django]-How to get GET request values in Django?
- [Django]-How to access request body when using Django Rest Framework and avoid getting RawPostDataException
2π
environment: Python 3.9.6
, Django 3.2.6
, VS Code
Just disable Pylance
extension and reload your VS Code.
- [Django]-Django simple_tag and setting context variables
- [Django]-Django proxy model and ForeignKey
- [Django]-Pytest.mark.parametrize with django.test.SimpleTestCase
1π
I had a similar problem. PyCharm couldnβt run the server but I could run it from the command line. I tried which python and then made sure that PyCharm was same interpreter and then everything worked OK.
- [Django]-Django index page best/most common practice
- [Django]-How to update an existing Conda environment with a .yml file
- [Django]-How do I raise a Response Forbidden in django
1π
This error usually occurs when django is not installed.
If you have already installed django but still getting the same error, then you must be working in separate virtual environment. You need to install django in your virtual environmnent as well. When you are in shell of virtual machine simply do this:
pip install django
It is because virtual machine has separate file system, it doesnβt recognize django even if it is installed on your system.
- [Django]-Django: show the count of related objects in admin list_display
- [Django]-Django-social-auth django-registration and django-profiles β together
- [Django]-Where to put business logic in django
1π
I fixed this problem by changing #PATH=β$VIRTUAL_ENV/bin:$PATHβ to PATH=β$PATH:$VIRTUAL_ENV/binβ
For reasons not obvious to me the python executable in the virtualenv dir does not see django but the normally installed python does.
- [Django]-How can I get tox and poetry to work together to support testing multiple versions of a Python dependency?
- [Django]-How to submit form without refreshing page using Django, Ajax, jQuery?
- [Django]-Django return file over HttpResponse β file is not served correctly
1π
Just a single mistake
This happened with me as well. My mistake was that Iβve created Django project before creating virtual env, later activated the env and was trying to start the server. Just install Django after activating env it will work
- [Django]-Django 1.5b1: executing django-admin.py causes "No module named settings" error
- [Django]-Heroku, postgreSQL, django, comments, tastypie: No operator matches the given name and argument type(s). You might need to add explicit type casts
- [Django]-Convert Django Model object to dict with all of the fields intact
1π
Thatβs an interpreter error.
If you are using vscode then just follow these steps:
- View
- Command palette
- Search for
python
- Select interpreter
- Select windows store and your problem will get solved, after few seconds the errors have gone.
This problem occurs due to path changed.
- [Django]-How do I install psycopg2 for Python 3.x?
- [Django]-Disabled field is not passed through β workaround needed
- [Django]-Programmatically saving image to Django ImageField
0π
your project is created using an old version of django-admin.py, older than django1.3
to fix this create another django project and copy its manage.py and paste it in the old one
- [Django]-How do I filter ForeignKey choices in a Django ModelForm?
- [Django]-Django project models.py versus app models.py
- [Django]-Django FileField upload is not working for me
0π
Agreed completely that this is a path issue but fwiw, I had this same error. It was due to the mistake of using a relative path for my Python executable when setting up my virtual environment. I had done this:
virtualenv -p ~/python_runtimes/2.7.3/bin/python venv2.7.3 --distribute
Instead I had to give the full path to the Python executable.
HTH,
Harlin
- [Django]-Django Template Language: Using a for loop with else
- [Django]-What's the difference between CharField and TextField in Django?
- [Django]-What is actually assertEquals in Python?
0π
source ~/blog-venv/bin/activate
pick your virtualenv to replace βblog-venvβ here.
- [Django]-Django auto_now and auto_now_add
- [Django]-Choose test database?
- [Django]-Django Model() vs Model.objects.create()
0π
Be sure youβre running the right instance of Python with the right directories on the path. In my case, this error resulted from running the python
executable by accident β I had actually installed Django under the python2.7
framework & libraries. The same could happen as a result of virtualenv as well.
- [Django]-How do I run tests against a Django data migration?
- [Django]-FileUploadParser doesn't get the file name
- [Django]-Django content-type : how do I get an object?
0π
Okay so it goes like this:
You have created a virtual environment and django module belongs to that environment only.Since virtualenv isolates itself from everything else,hence you are seeing this.
go through this for further assistance:
1.You can switch to the directory where your virtual environment is stored and then run the django module.
2.Alternatively you can install django globally to your python->site-packages by either running pip or easy_install
Command using pip: pip install django
then do this:
import django
print (django.get_version()) (depending on which version of python you use.This for python 3+ series)
and then you can run this:
python manage.py runserver
and check on your web browser by typing :localhost:8000
and you should see django powered page.
Hope this helps.
- [Django]-Are sessions needed for python-social-auth
- [Django]-How to run own daemon processes with Django?
- [Django]-How to test auto_now_add in django
0π
I included the name of the new App to the INSTALLED_APPS list in the settings.py βbeforeβ I issued the startapp command. Once I removed the list entry, I could create the app.
- [Django]-What's the purpose of Django setting βSECRET_KEYβ?
- [Django]-TransactionManagementError "You can't execute queries until the end of the 'atomic' block" while using signals, but only during Unit Testing
- [Django]-Django: How can I create a multiple select form?
0π
I solved this problem by using βdjango-adminβ command as following instead:
django-admin startproject _project_name
just remove the β.pyβ attached to βdjango-adminβ
- [Django]-How to understand lazy function in Django utils functional module
- [Django]-Django: How to format a DateField's date representation?
- [Django]-Pytest.mark.parametrize with django.test.SimpleTestCase
0π
Having an application called site
can reproduce this issue either.
- [Django]-What is "load url from future" in Django
- [Django]-How to get an ImageField URL within a template?
- [Django]-Django Sitemaps and "normal" views
0π
I got this due to forgetting that I installed Django using pip -U
, so it was only available to the user running my Django app. To run manage.py I had to do
sudo su -s /bin/bash MY_DJANGO_USER
/PATH/TO/MY/APP/manage.py
- [Django]-How to server HTTP/2 Protocol with django
- [Django]-When saving, how can you check if a field has changed?
- [Django]-Django β how to unit test a post request using request.FILES
-1π
all of you guys didnβt mention a case where someone βlike meβ would install django befor installing virtualenvβ¦so for all the people of my kind ther if you did thatβ¦reinstall django after activating the virtualenv..i hope this helps
- [Django]-Django: How to check if the user left all fields blank (or to initial values)?
- [Django]-TypeError: data.forEach is not a function
- [Django]-Is there a way to filter a queryset in the django admin?