Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MySQL with Anaconda's Python IDE

I just want to be able to do a simple SELECT * FROM query.

I found a Python MySQLdb Package, but can't get it to install using the Windows installer. It says,

Python is not found in the registry

I then tried briefly to compile it myself but I've debugged about six errors so far during the compile process and have given up.

If you are able to connect to MySQL using Anaconda, could you please detail out how you did it? Thanks.

like image 676
user3495297 Avatar asked Aug 10 '14 12:08

user3495297


1 Answers

The problem is that the binary installers for Python packages are looking for a specific registry key, which does not exist if you are using the Anaconda installer.

To make matters worse, Anaconda doesn't provide database drivers in either their commercial or free repository.

So now you have two options

  1. Recommended - get rid of Anaconda. Uninstall it. Install Python using the official Python installer for Windows. At this time, I would recommend the 2.7.x series for maximum compatibility. To make your vanilla installation the same as Anaconda, you can install the packages that are bundled with Anaconda separately.

    The Laboratory for Fluorescence Dynamics at the University of California, Irvine maintains a repository of Python packages that are difficult to install on Windows. They have taken these packages and converted them into Windows installer binaries. So, simply download and double click to install. Just like the MySQL installer, these will also only work with the official Python installer; for the same reason.

    The main packages you are probably after, you can start by installing the following:

    1. setuptools
    2. ipython
    3. numpy
    4. scipy
    5. pandas
    6. matplotlib requires:
      1. dateutil
      2. pytz
      3. pyparsing
      4. six
      5. Pillow
      6. pycairo
      7. tornado
        1. certifi
        2. backports
      8. wx-python
      9. pyside
      10. pyqt
    7. Numba
      1. llvm
    8. blaze
    9. bokeh

    It will take some time to download these, but they are all Windows installers so you just have to double click your way through them. Keep in mind the pre-requisites (indented entries above).

  2. The other option is to trick the MySQL installer (and other Windows installers) into thinking the Anaconda installation is the official Python installation. You can do that by modifying the registry.

    For Windows 7 64, create a file with the following:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath]
    @="D:\\Python27\\"
    

    Replace "D:\\Python27\\" with the path to your Anaconda installation. Save the above file with a .reg extension, then double click it to affect the changes to your registry. To do this might require administrator level access so the above might not work for your system.

I would highly recommend option #1 because it will ensure your system is setup to be most compatible with other Python libraries.

like image 197
Burhan Khalid Avatar answered Oct 20 '22 01:10

Burhan Khalid