Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在共享服务器上安装Django:是否没有名为MySQLdb的模块?_Python_Django_Mysql - Fatal编程技术网

Python 在共享服务器上安装Django:是否没有名为MySQLdb的模块?

Python 在共享服务器上安装Django:是否没有名为MySQLdb的模块?,python,django,mysql,Python,Django,Mysql,我犯了这个错误 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/

我犯了这个错误

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
回溯(最近一次呼叫最后一次):
文件“/home//flup/server/fcgi_base.py”,第558行,正在运行
文件“/home//flup/server/fcgi_base.py”,第1116行,在处理程序中
文件“/home//python/django/django/core/handlers/wsgi.py”,第241行,在__
响应=自我获取响应(请求)
文件“/home//python/django/django/core/handlers/base.py”,第73行,在get\u响应中
响应=中间件\方法(请求)
文件“/home//python/django/django/contrib/sessions/middleware.py”,第10行,进程请求中
引擎=导入模块(设置.会话引擎)
文件“/home//python/django/django/utils/importlib.py”,第35行,在import_模块中
__导入(名称)
文件“/home//python/django/django/contrib/sessions/backends/db.py”,第2行,在?
从django.contrib.sessions.models导入会话
文件“/home//python/django/django/contrib/sessions/models.py”,第4行,在?
从django.db导入模型
文件“/home//python/django/django/db/_init__.py”,第41行,在?
后端=加载后端(settings.DATABASE\u引擎)
文件“/home//python/django/django/db/_init__.py”,第17行,在load_后端
返回导入模块('.base',django.db.backends.%s'%backend\u name)
文件“/home//python/django/django/utils/importlib.py”,第35行,在import_模块中
__导入(名称)
文件“/home//python/django/django/db/backends/mysql/base.py”,第13行,在?
raise配置不正确(“加载MySQLdb模块时出错:%s”%e)
配置不正确:加载MySQLdb模块时出错:没有名为MySQLdb的模块
当我尝试在共享服务器上运行此脚本时

#!/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")
#/usr/bin/python
导入系统,操作系统
sys.path.insert(0,“/home//python/django”)
sys.path.insert(0,“/home//python/django/www”)#项目目录
chdir(“/home//python/django/www/”)
os.environ['DJANGO\u SETTINGS\u MODULE']=“.SETTINGS”
从django.core.servers.fastcgi导入runfastcgi
runfastcgi(method=“threaded”,daemonize=“false”)

但是,我的web主机几个小时前刚刚为我安装了
MySQLdb
。当我从shell运行python时,我可以很好地导入
MySQLdb
。为什么此脚本会报告找不到它?

您的settings.py中是否有可能存在错误的数据库引擎设置?应该是mysql,而不是mysqldb。

您的python路径上缺少python mysql db驱动程序。
看看你能不能找出WSGI看到的蟒蛇路径。。。这可能与您在shell中所经历的不同,这是正确的,但我只是从python shell中打印sys.path,然后将这些路径复制到我的脚本中。修正了这个问题,但提出了另一个…无需担心。。。我真的不应该把我的文件命名为django.py:p