Problem connecting Mysql in Python 3.4

Asked

Viewed 1,186 times

7

I just installed my virtual environment, installed Pymysql and created a project, however, when trying to start an APP python manage.py startapp nome, the following problem arose:

Error loading MySQLdb module: No module named 'MySQLdb'

How can I set up Mysql and fix it?

Man settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'meudb',
        'USER': 'root',
        'PASSWORD': '123',
        'HOST': 'localhost',
    }
}

2 answers

2


For Django to communicate with Mysql, you need to install an additional library in the environment you are using. In addition, this library must be compatible with the Django engine, which is not the case for Pymysql.

According to the official documentation, you have 3 options: Mysqldb, mysqlclient and the Mysql Connector/Python. Only the last two options are compatible with Python 3.

Still according to the documentation, the recommended library to be installed is the mysqlclient. To install it, use Pip:

pip install mysqlclient

Remember to do this after activating the virtual environment.

  • The error persists.

  • I just created a test environment with Python 3.4.3, Django and mysqlclient and everything worked perfectly. I removed the mysqlclient module and got the same error as you. So, you are sure you can install mysqlclient?

  • I also did the test: I changed the Python version to 3.4, created a new virtual environment, installed Django1.8, then mysqlclient. I created a new project (Django-admin startproject name) and finally made the change in the file Settings.py. While trying to create a new App gave again the error message.

  • What is your operating system? Are Mysql development libraries installed? If you open the interpreter of your virtual environment and type import Mysqldb, what happens?

  • >>> import mysqldb Traceback (Most recent call last): File "<stdin>", line 1, in <module> Import: No module named 'mysqldb'

  • so: linux Mint 17

  • important that you type respecting the upper and lower case letters.

  • Import: No module named 'Mysqldb'

  • If I change the python version to python2.7, mysql works normally. Only in version 3.4 does it present the problem. I already installed python-Mysqldb

  • You have enabled the virtual environment before installing?

Show 5 more comments

0

You must install mysql-python: pip install mysql-python

Browser other questions tagged

You are not signed in. Login or sign up in order to post.