Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install and use MySQLdb for Python 3 on Windows 10?

My various searches seem to come up with very old posts or a mention of how to do this under cygwin. I had python 3.5 installed and then installed Anaconda3. I have python 3.5 (Cpython) installed in my user directory. I tried changing the order of how things appear in my Windows Environment Variables path, so that I could try both the Anaconda version of Python and the other version of python that I have.

Currently, I am a bit confused as to the package name that I should use. Is it python-mysqldb, or MySQLdb, or mysqldb, mysqlclient. I believe that when I had Anaconda3 in my global path (and the other version of python in my user path), I was able to install mysqlclient.

Initially, I am just trying to follow a tutorial from a training site that covers databases and uses peewee.

So, can the mysql driver for peewee be installed for python3? Or on Windows specifically?

It is easy enough to use sqlite3, one doesn't use that in production, is that right?

Can someone help me? Provide some guidance?
Also, one source of confusion is when other forms of installation of a python package are listed in the google results (many point to stack overflow), such as using easy_install, or cloning something from git. When I see instructions that are from 2010 and they reference easy_install, I had been thinking that now we can just use pip instead? Also, sometimes I see use of the conda command. Does that work the same as pip?

Thanks in advance, Bruce

like image 460
Bruce Whealton Avatar asked Sep 26 '22 16:09

Bruce Whealton


1 Answers

You could use pymysql. "The goal of PyMySQL is to be a drop-in replacement for MySQLdb". Check the docs here. Install the following libraries

pip install mysqlclient pymysql

Once these libraries are installed, just add the lines in the manage.py file in your project and use the database settings for mysql.

import pymysql

pymysql.install_as_MySQLdb()

Now any files that import MySQLdb will work.

like image 63
Rahul Parida Avatar answered Sep 28 '22 05:09

Rahul Parida