python 在共享服务器上安装 Django:没有名为 MySQLdb 的模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/770904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing Django on Shared Server: No module named MySQLdb?
提问by mpen
I'm getting this error
我收到这个错误
Traceback (most recent call last):
File "/home/<username>/flup/server/fcgi_base.py", line 558, in run
File "/home/<username>/flup/server/fcgi_base.py", line 1116, in handler
File "/home/<username>/python/django/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/home/<username>/python/django/django/core/handlers/base.py", line 73, in get_response
response = middleware_method(request)
File "/home/<username>/python/django/django/contrib/sessions/middleware.py", line 10, in process_request
engine = import_module(settings.SESSION_ENGINE)
File "/home/<username>/python/django/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/<username>/python/django/django/contrib/sessions/backends/db.py", line 2, in ?
from django.contrib.sessions.models import Session
File "/home/<username>/python/django/django/contrib/sessions/models.py", line 4, in ?
from django.db import models
File "/home/<username>/python/django/django/db/__init__.py", line 41, in ?
backend = load_backend(settings.DATABASE_ENGINE)
File "/home/<username>/python/django/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/home/<username>/python/django/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/<username>/python/django/django/db/backends/mysql/base.py", line 13, in ?
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
when I try to run this script on my shared server
当我尝试在我的共享服务器上运行这个脚本时
#!/usr/bin/python
import sys, os
sys.path.insert(0, "/home/<username>/python/django")
sys.path.insert(0, "/home/<username>/python/django/www") # projects directory
os.chdir("/home/<username>/python/django/www/<project>")
os.environ['DJANGO_SETTINGS_MODULE'] = "<project>.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
But, my web host just installed MySQLdb
for me a few hours ago. When I run python from the shell I can import MySQLdb
just fine. Why would this script report that it can't find it?
但是,我的网络主机MySQLdb
几个小时前才为我安装。当我从 shell 运行 python 时,我可以MySQLdb
很好地导入。为什么这个脚本会报告找不到它?
回答by phillc
You are missing the python-mysql db driver on your python path. see if you can figure out the pythonpath WSGI is seeing... which can be different from what you are experiencing in shell
您的 python 路径上缺少 python-mysql db 驱动程序。看看你是否能找出 WSGI 看到的 pythonpath ......这可能与你在 shell 中遇到的不同
回答by Thomas Schreiber
Is it possible that you have the wrong DATABASE_ENGINE setting in your settings.py? It should be mysql and not mysqldb there.
您的 settings.py 中是否有错误的 DATABASE_ENGINE 设置?它应该是 mysql 而不是 mysqldb 那里。