I am using centos linux.
I had python 2.6 with django and now i upgraded to python 2.7.
Python 2.6 is located in /usr/lib/python2.6.
Python 2.7 is located in /usr/local/lib/python2.7.
They both have site-packages directory and they both contain django 1.2.If i run python i get the 2.7 version.
My problem is that if try to import django i getImportError: No module named django
I am not sure where is my PYTHONPATH defined and if this is what i need to change. anyone ?
i ended up making a symbolic link to the 2.6 site-packages directory.
score:19
To check your path, you can use the following code:
import sys
print(sys.path)
If you already know where django is installed, it should be easy to test if the desired directory is in your path with directory in sys.path
.
Regarding where your PYTHONPATH
is defined, note that it's an environment variable, so you can check its value (if defined) with: echo $PYTHONPATH
Similar question
- django import error - No module named core.management
- Django import error - no module named django.conf.urls.defaults
- Django storages: Import Error - no module named storages
- django celery: Import error - no module named task
- heroku django import error no module named _collections
- Django import error in views - no module named 'x'
- Django import error 'no module named django'
- Django Import Error at / No module named urls
- "No module named simple" error in Django
- Import Error: No module named django
score:1
If you are using a environment use:
$ <environment_location>/<environment_name>/bin/python manage.py runserver
score:1
python3 -m django --version1
for me it was that^
Some more answer related to the same question
- Django Import Error: No module named apps
- Django 1.5b1: executing django-admin.py causes "No module named settings" error
- No module named settings_vars error in django debug toolbar
- Widget tweaks error ModuleNotFoundError: No module named 'widget_tweaks' with Django forms
- django - import error: no module named views
- Django - Import Error: No module named *.urls
- No module named django error when running any manage.py command in docker with docker-compose
- Django import error: No module named models
- Django "No Module Named URLs" error
- Django AWS Elastic Beanstalk error ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
score:3
django went missing with an upgrade to python 3.7
pip3 install django
fixed the problem.
score:11
Try printing sys.path
to see what's in your path. Django need to be in one of the dirs listed. Example on Windows:
>>> import sys
>>> for p in sys.path: print p
C:\Python27\Lib\idlelib
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
>>>
score:13
try
pip freeze
this command show which packages are installed in your system then run with root privilege
pip install django
then create a new project with command
django-admin.py startproject mysite
then start your project
cd path/to/mysite
./manage.py runserver
in file wsgi.py add this lines
import os
import sys
DJANGO_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)
score:16
Under linux, you can set the PYTHONPATH environment variable in your .profile or .bashrc. You can either edit it directly from the terminal by changing to your home directory (cd ~), and then edit the file (nano .bashrc), or by opening the file with gtkedit or vim or whatever, and add:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:/another/path/etc
If you want to test this before editing your profile, you can export this from the terminal as:
export PYTHONPATH=/local/lib/python2.7/site-packages
I'm assuming you're running this straight from the command line. If you're running it as a wsgi module in apache, you can add this to your syspath from your wsgi file as:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
score:47
I had the same error, and this fix my issue
python -m pip install django
:) Done!
Credit To: stackoverflow.com
Related Query
- ImportError: Could not import settings (Is it on sys.path? Is there an import error in the settings file?): No module named setting
- Django + uwsgi + nginx . Import error: No module named py
- Django on AWS Elastic Beanstalk - No module named MySQLdb Error
- 'No module named 'encodings'' error when deploying django app on apache with mod_wsgi
- Using Django with virtualenv, get error ImportError: No module named 'django.core.servers.fastcgi'
- Django Channels No module named 'asgiref.sync' error
- django - Error loading MySQLdb module: No module named MySQLdb
- Django error - no module named
- Import Error: No module named django - for specific project
- No module named http_client error when trying to run django with django rest framework
More Query from same tag
- Identify which submit button was clicked in Django form submit
- Unable to set auth_user model primary key as foreign key in my app models.py
- Error Using CheckConstraint in Model.Meta along with Django GenericForeignKey - Joined field references are not permitted in this query
- How can I programmatically add content to a Wagtail StreamField?
- How to add 'id' to the fields in HyperlinkedModelSerializer in DRF
- How do I delete an object if not referenced by another object
- How to access the Azure AD Groups and user details using python?
- Calling Django View from Ajax
- How to process HTTP POST request in Django without CSRF token
- How to read/make sense of a PHP serialised data string in python
- How to manage writable nested serializers with multiple serializers in an unique field?
- Django: save() vs update() to update the database?
- Getting dynamic argument values in inherited class - django
- Increasing Django login security and password strengths
- MySQL + Django: No obj.id after save()