10👍
To fix my problem I used the following line in my .zprofile:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages
I was trying to import Django and it couldn’t be found, and doing the above solved the issue.
31👍
Possible issues that may cause your problem:
-
PYTHONPATH is not well configured, to configure it you should do:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages
-
You forgot the line
#!/usr/bin/env python
at the beginning of manage.py -
If you’re working on virtualenv you forgot to activate the virtual env to execute manage.py commands (You may have installed Django on your system but not on your virtualenv)
source path/to/your/virtualenv/bin/activate
or
workon env_name
-
You have Python 2.7 and Python 3.4 messing with the package
-
You’re using a very old Python 2.4 and you should tell the system to use your Python 2.7 with:
alias python=python2.7
Some times reinstalling/upgrading Django fix some of those issues.
You may want to execute
python -c "import django; print(django.get_version())"
to check if Django is installed on your PC or your virtualenv if you’re using one
You can find some other solutions in other similar questions:
- [Django]-Django is "unable to open database file"
- [Django]-Full text search: Whoosh Vs SOLR
- [Django]-Django-DB-Migrations: cannot ALTER TABLE because it has pending trigger events
4👍
I solved this same error by running the below command:
python3.4 manage.py runserver
And the above command successfully executed for me. So what you can try is, if you are using python 2.7 then just replace 3.4 with 2.7. Hope this helps.
- [Django]-Charts in django Web Applications
- [Django]-How to create admin user in django tests.py
- [Django]-Project design / FS layout for large django projects
3👍
I came across the same issue when I did all the setup and run for django with Python3 but ran the following command:
$ python manage.py migrate
fixed the issue by using a consistent version of Python:
$ python3 manage.py migrate
Operations to perform:
Apply all migrations: sessions, auth, admin, contenttypes
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying sessions.0001_initial... OK
Other commands I ran before this were:
python3 -m pip install django
django-admin startproject learning_site
python3 manage.py runserver 0.0.0.0:8000
- [Django]-How to check if django template variable is defined?
- [Django]-ImproperlyConfigured at / Empty static prefix not permitted – Django
- [Django]-Web application monitoring best practices
2👍
If you use virtualenv
and run manage.py runserver
in windows system, cmd will use system’s python, not the python in virtualenv.
Because If you install python
in system, cmd will automatically use python
that installed in system, not the python in virtualenv
.
So if you use virtualenv
in Windows. you need run
>python .\manage.py runserver
- [Django]-Django prefetch_related with limit
- [Django]-Django multi-level template extends and nested blocks
- [Django]-Django – cannot import name 'config' from 'decouple'
1👍
That error is due to the user environment. Indeed i just add the virtuel environment bin path to PATH and the problem has been solved.
PATH=/bin/of_virtualenvironment/:$PATH
- [Django]-Uncaught TypeError: Cannot read property 'ownerDocument' of undefined
- [Django]-How to redirect to previous page in Django after POST request
- [Django]-Django Admin app or roll my own?
1👍
The direct problem is that django package is missing. For me, as I was running django in virtualenv, this problem occurs after I rename my working directory.
Reinstalling the env worked for me.
- [Django]-Django migrate : doesn't create tables
- [Django]-Django – No module named _sqlite3
- [Django]-After adding django-debug to App, getting "'djdt' is not a registered namespace"
0👍
in where your django file resides, check the first line of django-admin.py:
#!/usr/bin/env python
If you use python 3+, python
here may refers python2 here. So check which python you install django with.
ls -l $(which -a python3)
If you do have python3 installed and not linked as python
, change the first shebang line into
#!/usr/bin/env python3
- [Django]-How to expire session due to inactivity in Django?
- [Django]-Django can' t load Module 'debug_toolbar': No module named 'debug_toolbar'
- [Django]-Django – after login, redirect user to his custom page –> mysite.com/username
0👍
Also, make sure you did not mess up your .bashrc
with alias
es.
You would get this kind of errors if .bashrc
contains something like alias python="/usr/bin/python3"
.
- [Django]-Django – {% csrf_token %} was used in a template, but the context did not provide the value
- [Django]-Django py.test does not find settings module
- [Django]-Are Django SECRET_KEY's per instance or per app?
0👍
I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.
I confirmed that I was using the python interpreter in my virtual environment.
I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.
- [Django]-ReactJS with Django – real usage
- [Django]-Is save() called implicitly when calling create in django?
- [Django]-Django csrf token + Angularjs
0👍
Fixed the same problem in my project using only;
pip install -r requirements.txt
I didn’t have to do anything else. When I ran./manage.py runserver
everything worked!
- [Django]-Filtering dropdown values in django admin
- [Django]-How to have a Python script for a Django app that accesses models without using the manage.py shell?
- [Django]-Understanding Django-LDAP authentication
0👍
Using Pycharm go to Configurations add runserver 8080
to parameters, or I fixed my issue by restarting my computer….strange but worked.
I did not have to change pip or install anything else, first try the first method I listed, if you are fine with running manage.py through PyCharm arrow icon, it will work, if you want to go back to the terminal and type python manage.py runserver:port try restarting your machine.
- [Django]-'function' object has no attribute 'as_view'
- [Django]-How to add Check Constraints for Django Model fields?
- [Django]-Django – what is the difference between render(), render_to_response() and direct_to_template()?
0👍
Trying the solutions here didn’t work for me. Reinstalling Django and upgrading pip removed the error and everything now works as expected when I run python migrate.py runserver
Here are the CLI commands I used:
python -m pip install django
python -m pip install –upgrade pip
- [Django]-Apache + mod_wsgi vs nginx + gunicorn
- [Django]-How to do a multi-step form in Django?
- [Django]-Is it better to use path() or url() in urls.py for django 2.0?
-1👍
i solved this problem by installing django inside the virtual enviromment that i was working on
- [Django]-Initial populating on Django Forms
- [Django]-How to stream an HttpResponse with Django
- [Django]-No Module named django.core