Python3 + MySql:加载MySQLdb模块时出错:没有名为“MySQLdb”的模块 [英] Python3 + MySql: Error loading MySQLdb module: No module named 'MySQLdb'

查看:565
本文介绍了Python3 + MySql:加载MySQLdb模块时出错:没有名为“MySQLdb”的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很熟悉Python,并尝试设置一个Django项目来处理MySql。我已经阅读了关于该主题的文档以及其他一些StackOverflow文章,但是我仍然无法使其正常工作。



当我尝试运行迁移在Django我收到以下错误:

 加载MySQLdb模块时出错:没有名为MySQLdb的模块

我已经安装了推荐的 MySql Python连接器(2.0.1)选择Ubuntu(因为我在Mint Linux上)。它正确安装我仍然收到错误。我不需要将这个图书馆添加到项目或任何东西,对吧?看起来python应该知道这个并且运行成功。我能做什么?谢谢。



编辑:我忘了提到:我在运行Python 3.4 - 很多典型的解决方案仍然使用2.7,所以他们不工作和所有的解决方案与3.0我已经尝试没有成功。

解决方案

我需要在settings.py中看到你的DATABASES配置,但它看起来像它正在尝试加载MySQLDB而不是您安装的Mysql Python连接器。数据库应该如下所示:

  DATABASES = {
'default':{
'NAME ':'mydatabase',
'ENGINE':'mysql.connector.django',
'USER':'myuser',
'PASSWORD':'secretpassword',
'OPTIONS':{
'autocommit':True,
},
}
}

注意引擎部分...告诉Django使用mysql连接器而不是MySQLDB ...



更多信息在这里:
http:// bunwich。 blogspot.com/2014/02/finally-mysql-connector-that-works-with.html
http://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html



,如果y ou希望使用南方:



www.pythonanywhere.com/wiki/UsingMySQL



您可能想请注意,Oracle连接器是GPL,并且可能存在使用该代码的许可证问题。看到这里:



groups.google.com/forum /#!topic / django-developers / 8r_RVmUe5ys



Django 1.7文档建议使用mysqlclient驱动程序...



docs.djangoproject.com/en/1.7/ref/databases/
- 查看该部分在Mysql DB API驱动程序



pypi.python.org/pypi/mysqlclient为该客户端...



-Scott


I am new to Python and trying to setup a Django project to work with MySql. I have read through the documentation as well as some other StackOverflow posts about the topic, but I still can't get it to work.

When I try to run a migrate in Django I get the following error:

Error loading MySQLdb module: No module named 'MySQLdb'

I have installed the recommended MySql Python Connector (2.0.1) selecting Ubuntu (since I am on Mint Linux). It installs correctly. I still get the error. I don't need to add this library to the project or anything, right? It looks like python should just be aware of this and run successfully. What can I do? Thanks.

EDIT: I forgot to mention: I am running Python 3.4 - a lot of typical solutions are still using 2.7, so they don't work and all the solutions with 3.0 I have tried without success.

解决方案

I would need to see your DATABASES configuration in settings.py, but it looks like it is trying to load MySQLDB instead of the Mysql Python Connector that you installed. The DATABASES should look something like this:

DATABASES = {
    'default': {
        'NAME': 'mydatabase',
        'ENGINE': 'mysql.connector.django',
        'USER': 'myuser',
        'PASSWORD': 'secretpassword',
        'OPTIONS': {
          'autocommit': True,
        },
    }
}

Note the ENGINE part... that tells Django to use the mysql connector instead of MySQLDB...

more info available here: http://bunwich.blogspot.com/2014/02/finally-mysql-connector-that-works-with.html http://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html

and if you are expecting to use South:

www.pythonanywhere.com/wiki/UsingMySQL

You may want to note that the Oracle connecter is GPL, and there may be license issues with using that code. See Here:

groups.google.com/forum/#!topic/django-developers/8r_RVmUe5ys

The Django 1.7 documentation recommends using the mysqlclient driver...

docs.djangoproject.com/en/1.7/ref/databases/ --see the section on Mysql DB API Drivers

pypi.python.org/pypi/mysqlclient for that client...

-Scott

这篇关于Python3 + MySql:加载MySQLdb模块时出错:没有名为“MySQLdb”的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆