Mysql to Python 3 connector

Asked

Viewed 707 times

5

I’m doing a project with Django and Python 3 but I can’t find the appropriate Mysql connector. The django.db.backends.mysql works, but only for Python 2, and I wanted to avoid using this version. On the terminal when I type import django.db.backends.mysql it matters without any error, but when I will run on the server by the command python3 manage.py runserver error appears:

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-Packages/Django/db/backends/mysql/base.py", line 18, in raise Improperlyconfigured("Error loading Mysqldb module: %s" % e) Django.core.exceptions.Improperlyconfigured: Error loading Mysqldb module: No module named 'Mysqldb'

Is there any way to solve this? Django projects have some restriction on development using Python 3?

Currently the development environment is on an OS X Yosemite.

Thank you!

2 answers

4


Apparently this is a classic problem of this plugin in particular.

Using the pip, perform the following:

pip install --allow-all-external mysql-connector-python

Adjust your file settings.py to the following:

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
    }
}

I got the answer from here.

  • 1

    Thank you very much Gypsy. It worked correctly after your reply.

0

I had a similar problem, after a lot of research I saw that I needed to install the dependencies in the system:

   sudo apt-get install python3.7-dev
   sudo apt-get install default-libmysqlclient-dev

I took the details from here: https://pypi.org/project/mysqlclient/

Browser other questions tagged

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