15

I've read several different explanation regarding how to install MySQLdb, but I'm not sure which case applies to me since my error message is different. My system can't seem to find MySQLdb. I installed pymysql, but i need to import MySQLdb to use procedures from that library.

Thanks for your help.


$ conda install MySQLdb

Fetching package metadata: .... Error: No packages found in current osx-64 channels matching: mysqldb

Did you mean one of these?

pymysql

You can search for this package on anaconda.org with

anaconda search -t conda mysqldb

$ anaconda search -t conda mysqldb

Using anaconda-server api site https://api.anaconda.org Run 'anaconda show ' to get more details: No packages found Name | Version | Package Types | Platforms
------------------------- | ------ | --------------- | --------------- Found 0 packages

James Eaves
  • 1,587
  • 3
  • 17
  • 22

9 Answers9

29

Try to use this command:

conda install mysql-python
pableiros
  • 14,932
  • 12
  • 99
  • 105
maverik
  • 291
  • 3
  • 3
14

For those Googlers in 2018+, you can install from the bioconda channel

conda install -c bioconda mysqlclient
WillMonge
  • 1,005
  • 8
  • 19
6

Since early 2018, the mysql package has become available from the conda and anaconda channels. The former is often more up-to-date and, as of April 2021, provides version 8 compared to the latter's version 5.

Install using

conda install -c conda-forge mysql
Stefan
  • 41,759
  • 13
  • 76
  • 81
  • 2
    I tried that, but I receive this message: --- Error: No packages found in current osx-64 channels matching: mysql-python Did you mean one of these? mysql-connector-python You can search for this package on anaconda.org with anaconda search -t conda mysql-python – James Eaves Dec 07 '15 at 18:41
  • Have you tried `conda install binstar`, and then `binstar search -t conda mysql-python`? Or `pip install mysql-python`? – Stefan Dec 07 '15 at 18:44
  • when i run the pip command I receive this error: Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-Kt0Nb_/mysql-python – James Eaves Dec 07 '15 at 18:52
  • Try `conda install pip`. Here's more on what could help with your setup: http://stackoverflow.com/questions/17886647/cant-install-via-pip-because-of-egg-info-error – Stefan Dec 07 '15 at 18:55
  • I receive a similar error (thanks for all your help): Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-ubayrP/mysql-python – James Eaves Dec 07 '15 at 18:57
  • Take a look at the link I included with my previous comment. There's a few ways to fix the conventional installation pipes, depending on what exactly got missing during original anaconda setup. – Stefan Dec 07 '15 at 19:05
  • I ran that file and followed the other instructions. It ran successfully but I still get a similar error message when I try to install mysql-python. Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/p1/xg17tts541n1__p_srg1n2j80000gn/T/pip-build-EThMFm/mysql-python – James Eaves Dec 07 '15 at 19:21
  • Did you also `pip install --upgrade setuptools` or `easy_install -U setuptools`? – Stefan Dec 07 '15 at 19:31
  • I did. What is going on?? – James Eaves Dec 07 '15 at 19:35
  • I think something worked. I reran binstar search -t conda mysql-python I several user packages are listed. What should I try next? See output : Name | Version | Package Types | Platforms ------------------------- | ------ | --------------- | --------------- alefnula/mysql-python | 1.2.5 | conda | osx-64 : Python interface to MySQL anaconda/mysql-python | 1.2.5 | conda | linux-64, win-32, linux-32 .... – James Eaves Dec 07 '15 at 19:40
  • Did you also check for the `binstar` packages? These can be installed using `conda` so you wouldn't have to deal with the `pip` issues. – Stefan Dec 07 '15 at 19:42
  • Yes something worked with Binstar. for instance this is listed: alefnula/mysql-python | 1.2.5 | conda | osx-64 But im not sure what to do with it. – James Eaves Dec 07 '15 at 19:46
  • This worked apparently: conda install -c https://conda.anaconda.org/derickl mysql-python – James Eaves Dec 07 '15 at 19:48
  • But what is the relationship between mysql-python and MySQLdb? Im trying to execute code that imports MySQLdb. – James Eaves Dec 07 '15 at 19:51
  • `python-mysql` is the python interface to MySQL. Here are docs: http://mysql-python.sourceforge.net/MySQLdb.html. Just scroll down to the examples. – Stefan Dec 07 '15 at 19:54
  • Thanks again for all your time. That was very generous. – James Eaves Dec 07 '15 at 19:54
  • Happy to help, updated my answer to condense the thread or anyone coming by later. – Stefan Dec 07 '15 at 20:05
3

To install this package with conda run:

conda install -c anaconda mysql-python=1.2.5

check here: https://anaconda.org/anaconda/mysql-python

Bassem Shahin
  • 656
  • 7
  • 13
2

try this:

conda install mysql-connector-python 
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • 1
    Note this is a different library! I.e this is the official one from Oralce, which is written in pure python vs the C extension based MySQLDb. Supposedly MySQLDb (aka mysqlclient) may dramatically out perform this (depending upon on the use context). – BuvinJ Jul 15 '20 at 18:47
1

~/anaconda2$ conda install mysql-python

works on ubuntu 16.04

1

Python 3.8 should execute the following command

conda install -c anaconda mysql-connector-python
武建涛
  • 11
  • 1
0

For Anaconda Python, @StephenRauch has the correct solution, as it is officially supported in the Anaconda Enterprise documentation:

conda install -c anaconda mysql-connector-python

Reference: https://enterprise-docs.anaconda.com/en/latest/data-science-workflows/data/mysql.html

Adam Erickson
  • 6,027
  • 2
  • 46
  • 33
0

Use this for mysqldb with python above 3.x

pip install mysqlclient
Rishi
  • 17
  • 1