4

Win7のActivePython2.7でDjango1.4.1を使用しています。を使用してMySQLモジュールをインストールしましたpypm install mysql-python

データベースエンジンはdjango.db.backends.mysqlです。

import MySQLdbインタラクティブシェルで動作します。

.\manage.py syncdb問題なくテーブルを作成しました。

ただし、ブラウザでサイトを開くと、次のようになりますError loading MySQLdb module: No module named MySQLdb

Environment:


Request Method: GET
Request URL: http://whatever/

Django Version: 1.4.1
Python Version: 2.7.2
Installed Applications:
('django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  89.                     response = middleware_method(request)
File "C:\Python27\lib\site-packages\django\contrib\sessions\middleware.py" in process_request
  10.         engine = import_module(settings.SESSION_ENGINE)
File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "C:\Python27\lib\site-packages\django\contrib\sessions\backends\cached_db.py" in <module>
  6. from django.contrib.sessions.backends.db import SessionStore as DBStore
File "C:\Python27\lib\site-packages\django\contrib\sessions\backends\db.py" in <module>
  3. from django.db import IntegrityError, transaction, router
File "C:\Python27\lib\site-packages\django\db\__init__.py" in <module>
  40. backend = load_backend(connection.settings_dict['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\__init__.py" in __getattr__
  34.         return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\db\utils.py" in __getitem__
  92.         backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py" in load_backend
  24.         return import_module('.base', backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py" in <module>
  16.     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)

Exception Type: ImproperlyConfigured at /
Exception Value: Error loading MySQLdb module: No module named MySQLdb

セッションおよびメッセージアプリの設定は次のとおりです。

SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
MESSAGE_STORAGE = "django.contrib.messages.storage.cookie.CookieStorage"

これはどのように可能ですか?

4

5 に答える 5

3

問題は、MySQLdbがC:\Users\alexei\AppData\Roaming\Python\Python27\site-packages\Pythonのパスにないホームディレクトリにインストールされていたことです。そこで、でアンインストールしてから、を使用してグローバルpypm uninstall mysql-pythonに再インストールしました(オプションに注意してください)。pypm -g install mysql-python-g

別の方法は、そのパスをのリストに追加することですsys.path.append("...path...")wsgi.py

したがって、他の誰かが疑問に思っている場合は、MySQLdb(または他のモジュール)がどこにインストールされているかを次のように確認できます。

import MySQLdb
print MySQLdb.__file__

そのパスが、Djangoのエラーメッセージで提供されるPythonのパスリストに含まれていることを確認してください。

于 2012-10-07T21:09:35.583 に答える
2

仮想環境を使用している場合。あなたは走らなければなりません

cd virtualEnvPath
pip install MySQL-Python

仮想環境内に配置することを忘れないでください。/bin PATH、ローカル pip を使用します。よろしく!

于 2014-07-24T08:59:57.450 に答える
1

最も簡単な方法は、バイナリから MySQLdb をインストールすることです: http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

于 2014-05-28T04:31:46.240 に答える