Unable to install mysqlclient Python package on Windows

后端 未结 3 1508
[愿得一人]
[愿得一人] 2020-12-19 16:14

I am trying to install the mysqlclient Python package (https://pypi.python.org/pypi/mysqlclient) into a virtual Python 2.7 environment on Windows 7 (on a local

相关标签:
3条回答
  • 2020-12-19 16:58

    Incidentally I ran into the same issue in July last year and only now finished an entry on my blog about it.

    Basically, you're not going to like it, but you need to re-compile mysqlclient from scratch, because -- as you pointed out -- it's not available for Visual Studio 9 since a long time.

    However, doing it right is somewhat tricky, because you need to fix some compilation issues that apparently aren't documented anywhere in Oracle's official documentation. There are also issues with the Python setup.py file, as it doesn't care about the platform architecture and always looks in the x86 directory. That's why you soft-linked the directory. There is an open issue on Github mentioning this.

    So basically, using the VC++ for Python 2.7 you already installed:

    1. Download the Oracle MySQL C Connector source code.
    2. Download and install Microsoft Visual C++ Compiler for Python 2.7.
    3. Use CMake to generate NMake Makefiles for the MySQL C Connector source code. Pay attention to environment variables, see this Github issue comment.
    4. Compile the MySQL C Connector mysqlclient library using nmake mysqlclient.
    5. Install the MySQL C Connector binary and add the compiled mysqlclient.
    6. Run pip install mysqlclient again.

    Step 4 is tricky, because Microsoft don't supply C99 stdint.h, inttypes.h and stdlib.h is missing lldiv_t. You can use this StackOverflow post to get stdint.h and inttypes.h and then manually define lldiv_t in decimal.h as:

    typedef struct {
    long long quot;
    long long rem;
    } lldiv_t;
    

    You can also copy these headers from a newer Visual Studio, like 2013 and 2015. After that, as you had already figured out, you need to put the compiled mysqlclient.lib into C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib\vs9.

    Then issue another pip install mysqlclient and you're all done.

    0 讨论(0)
  • 2020-12-19 16:58

    download mysqlclient from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

    choose the version matching your python version, example mysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64.whl, and then:

    pip install wheel
    
    pip install mysqlclient‑1.4.2‑cp37‑cp37m‑win_amd64.whl
    
    0 讨论(0)
  • 2020-12-19 17:09

    USE mysqlclient‑1.4.6‑cp38‑cp38‑win32.whl from https://www.lfd.uci.edu/~gohlke/pythonlibs/ for python 3.8

    0 讨论(0)
提交回复
热议问题