简体   繁体   English

使用pip安装mysql-python时出错

[英]Error while installing mysql-python using pip

Get the following error while installing mysql-python using pip 使用pip安装mysql-python时出现以下错误

pip : 9.0.1 点:9.0.1

python : 2.7 的Python:2.7

OS : Mac OS Sierra 10.12.5 操作系统:Mac OS Sierra 10.12.5

    Some-MacBook-Air:~ itssuyog$ pip install mysql-python
Collecting mysql-python
  Downloading MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 257kB/s
Installing collected packages: mysql-python
  Running setup.py install for mysql-python ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-build-ThTb9v/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-jTh4C4-record/install-record.txt --single-version-externally-managed--compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.12-intel-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.12-intel-2.7
    creating build/lib.macosx-10.12-intel-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
    creating build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.12-intel-2.7
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mariadb/10.2.7_1/include/mysql -I/usr/local/Cellar/mariadb/10.2.7_1/include/mysql/.. -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.12-intel-2.7/_mysql.o
    In file included from _mysql.c:44:
    /usr/local/Cellar/mariadb/10.2.7_1/include/mysql/my_config.h:286:11: warning: 'SIZEOF_SIZE_T' macro redefined [-Wmacro-redefined]
      #define SIZEOF_SIZE_T  SIZEOF_LONG
              ^
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:43:17: note: previous definition is here
    #        define SIZEOF_SIZE_T           8
                    ^
    _mysql.c:287:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                    cmd_argc = PySequence_Size(cmd_args);
                             ~ ^~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:317:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                    groupc = PySequence_Size(groups);
                           ~ ^~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:470:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                            int j, n2=PySequence_Size(fun);
                                   ~~ ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:1127:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_real_escape_string(&(self->connection), out, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1129:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_escape_string(out, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1168:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
            size = PyString_GET_SIZE(s);
                 ~ ^~~~~~~~~~~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32: note: expanded from macro 'PyString_GET_SIZE'
    #define PyString_GET_SIZE(op)  Py_SIZE(op)
                                   ^~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56: note: expanded from macro 'Py_SIZE'
    #define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
                                     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
    _mysql.c:1178:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_real_escape_string(&(self->connection), out+1, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1180:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_escape_string(out+1, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1274:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
            if ((n = PyObject_Length(o)) == -1) goto error;
                   ~ ^~~~~~~~~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25: note: expanded from macro 'PyObject_Length'
    #define PyObject_Length PyObject_Size
                            ^
    _mysql.c:1466:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                            len = strlen(buf);
                                ~ ^~~~~~~~~~~
    _mysql.c:1468:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                            len = strlen(buf);
                                ~ ^~~~~~~~~~~
    _mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                    len = strlen(buf);
                                        ~ ^~~~~~~~~~~
    _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                    len = strlen(buf);
                                        ~ ^~~~~~~~~~~
    _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
            if (how < 0 || how >= sizeof(row_converters)) {
                ~~~ ^ ~
    _mysql.c:2005:42: error: no member named 'reconnect' in 'struct st_mysql'
            if ( reconnect != -1 ) self->connection.reconnect = reconnect;
                                   ~~~~~~~~~~~~~~~~ ^
    15 warnings and 1 error generated.
    error: command 'cc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-build-ThTb9v/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-jTh4C4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-build-ThTb9v/mysql-python/

I got a similar post on Stack Overflow : can't pip install mysql-python 我在Stack Overflow上收到了类似的帖子: 无法pip安装mysql-python

That is for Ubuntu. 那是针对Ubuntu的。 But still I tried to install python-dev as suggested in the answer of that post using pip and got the following error : 但是我仍然尝试按照该帖子的答案中的建议使用pip安装python-dev并收到以下错误:

Some-MacBook-Air:~ itssuyog$ sudo pip install python-dev
Password:
The directory '/Users/admin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/admin/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check thepermissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting python-dev
  Downloading python-dev-4.1.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-build-mFlFdp/python-dev/setup.py", line 90, in <module>
        evalall()
      File "/private/tmp/pip-build-mFlFdp/python-dev/setup.py", line 86, in evalall
        print("安装完成!")
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-mFlFdp/python-dev/

Thanx in advance!! 提前感谢!

python-dev is the wrong python-dev; python-dev是错误的python-dev; it seems some rogue Chineeze took the name and created a package that installs a backdoor. 似乎有些流氓Chineeze取了名字并创建了一个安装后门程序的软件包。

Real python-dev is a development package for Debian/Ubuntu installable with apt . Real python-dev是Debian / Ubuntu的开发包,可通过apt安装。 You don't need it in MacOS. 在MacOS中,您不需要它。 If you have done brew install python (or python3 ) you should already have all necessary development files. 如果您已经完成brew install python (或python3 )的brew install python那么您应该已经拥有所有必需的开发文件。

Try installing mysql-connector: 尝试安装 mysql-connector:

brew install mysql-connector-c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM