Windows上的Python和MySQL:安装错误

2024-05-23 13:45:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Django项目的文件夹中运行以下命令:

$ python manage.py dbshell

它显示了这个错误:

$python manage.py dbshell
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
362, in execute_manager
    utility.execute()
  File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python25\lib\site-packages\django\core\management\base.py", line 195,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python25\lib\site-packages\django\core\management\base.py", line 222,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python25\lib\site-packages\django\core\management\base.py", line 351,
 in handle
    return self.handle_noargs(**options)
  File "C:\Python25\lib\site-packages\django\core\management\commands\dbshell.py
", line 9, in handle_noargs
    from django.db import connection
  File "C:\Python25\lib\site-packages\django\db\__init__.py", line 41, in <modul
e>
    backend = load_backend(settings.DATABASE_ENGINE)
  File "C:\Python25\lib\site-packages\django\db\__init__.py", line 17, in load_b
ackend
    return import_module('.base', 'django.db.backends.%s' % backend_name)
  File "C:\Python25\Lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
    __import__(name)
  File "C:\Python25\lib\site-packages\django\db\backends\mysql\base.py", line 13
, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo
dule named MySQLdb

第一个问题是,为什么Python不简单地包含这个MySQLdb模块?

好的,很好,尝试搜索以解决此消息。

我在stackoverflow.com上到处寻找安装这个模块的方法,但是没有得到一个好的结果。

http://sourceforge.net/projects/mysql-python/下载此模块

在我的WindowsVista系统上安装此模块。 提取包后,我运行cmd提示符继续安装:

$ python setup.py install

它再次向我展示了另一个信息:

D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    from setuptools import setup, Extension
ImportError: No module named setuptools

在处理这个错误消息时,我知道包中存在ez_setup.py

$python ez_setup.py

似乎一切都很好:

D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python ez_setup.py
Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py
2.5.egg
Processing setuptools-0.6c9-py2.5.egg
Copying setuptools-0.6c9-py2.5.egg to c:\python25\lib\site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install-script.py script to C:\Python25\Scripts
Installing easy_install.exe script to C:\Python25\Scripts
Installing easy_install-2.5-script.py script to C:\Python25\Scripts
Installing easy_install-2.5.exe script to C:\Python25\Scripts

Installed c:\python25\lib\site-packages\setuptools-0.6c9-py2.5.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9

现在返回到setup.py重新安装:

$python setup.py install

它又给了我一个错误信息:

D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python setup.py install
running install
running bdist_egg
....
copying MySQLdb\constants\CLIENT.py -> build\lib.win32-2.5\MySQLdb\constants
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.

我怎样才能解决这个问题?


Tags: installdjangoinpycorelibpackagessetup
3条回答

呃,这不是Django,这是你下载了一些未指定的Python环境,希望它能神奇地按照你想要的方式来做每件事。找到一个关于这个的好教程并按照说明操作。

顺便说一句,这是一个非常有帮助的论坛,但不提供细节,然后以一种态度提出一个无问题,并不是让人们感到有帮助的好方法。

我曾经在同一台计算机上运行Python和MySQL时遇到同样的问题。像上面提到的guys/gals一样,Python没有对MySQL的内置支持,因此您需要下载连接器。

上面由@kibitzer给出的链接很可能无法在Windows上成功工作,所以请使用here to download一个与Windows一起工作的连接器的副本。它附带安装程序,不需要手动运行setup.py脚本。

你试过看这里吗:http://sourceforge.net/projects/mysql-python/files/

这是MySQLdb项目的下载区,它与django无关,所以你的问题是不正确的-django并没有使切换数据库后端变得困难,你只需更改一行。当然,您的python安装应该首先支持该数据库,因此通过从我上面提供的链接下载binary package for Windows(选择与python版本匹配的正确版本),您可以避免编译源版本的所有麻烦。

很可能您需要MySQL-python-1.2.2.win32-py2.5.exeMySQL-python-1.2.2.win32-py2.4.exe

相关问题 更多 >