ImportError: No module named django.core.management, Django Error After Upgrade
On one of my servers I run a couple sites via Django and recently when I upgraded the server it broke the Django sites that were running via FastCGI. After some investigation I was able to find the issue which happened to be a basic conflict between python2.4 which is the default python version on CentOS Linux and python2.6 which I installed to run via python26 instead of python. This way I can change the environment of any site that needs it to Python version 2.6 without much hassle. Below I describe the error in detail as well as what resolved the issue.
Error Trying To Restart Django FastCGI Site After Upgrading Django:
[root@dev web]# /etc/init.d/fastcgi-devsite restart fcgi-engage is NOT running. Starting fcgi-devsite...Traceback (most recent call last): File "/var/www/devsite/manage.py", line 2, in <module> from django.core.management import execute_manager ImportError: No module named django.core.management [FAILED] [root@dev web]#
Resolve Django FastCGI Restart Error:
If you have both versions of Python, which include Python 2.4 and Python 2.6, and python was recently updated it is likely you need to copy the Django folder back over to the python2.6 directory as shown below. If you only have one version of Python installed then you can simply try the second command to see if it resolved the issue.
Copy Django Folder From Python 2.4 To Python 2.6 Directory:
Use the below syntax to copy the upgraded django folder from the /usr/lib/python2.4/site-packages directory to /usr/lib/python2.6/site-packages directory.
[root@dev ~]# cp -pR /usr/lib/python2.4/site-packages/django /usr/lib/python2.6/site-packages/
Now you can attempt to restart the FastCGI site to see if it works or go into the Django projects root directory and issue the below command and then restart the FastCGI’s.
Sync Django Site DB:
[root@dev devsite]# python26 manage.py syncdb
Restart Django FastCGI Site:
[root@dev ~]# /etc/init.d/fastcgi-devsite restart fcgi-engage is NOT running. Starting fcgi-engage...[ OK ] [root@dev ~]#
Now attempt to restart your Django FastCGI site to see if the issue is resolved as shown above.