I know that many have posted similar question however I tried most solution without success.
I’m trying to host a webpage with apache2 and django in python3.
In the error log I found ImportError: No module named 'django'
when accessing the wsgi.py
file, where I also added import sys
, sys.version
to confirm which python version is used and from the error log I can see that I’m running following python version 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
.
When I run python3.5
I see that I uses the same python version and here I can run import django
without any error!
EDIT: I checked django.__file__
and saw that it was located in /home/USERNAME/.local/lib/python3.5/site-packages/django/init.py
and that path /home/USERNAME/.local/lib/python3.5/site-packages
wasn’t in the sys.path
that tried to run django. But adding it with sys.path.append(path)
didn’t help 🙁
Any thoughts what I might have messed up?
3
Answers
I finally understood how to solve it! first I had to run
pip3 uninstall django
then runsudo pip3 install django
.If you have Setup the whole configuration in VirtualEnv then , i suggest you to activate it by,
or
pip install django=version id
if you want to pass version id then its good or it will install the latest django from your repo.
Now test Django Version there.
Hope you will no get the error.
Location – means the path where env will be located in project directory, if you have followed the standard installation process of django or else you don’t need, and version id- vesion of django framework.