【问题标题】:error installing mysql-python and none of mentioned solutions worked安装 mysql-python 时出错,并且没有提到的解决方案有效
【发布时间】:2016-12-12 13:49:34
【问题描述】:

我只是想安装Mysql-python,但每次都出现错误。 我已经尝试过所有提到的解决方案,如安装轮子、使用 easy_install、更新 Visual c++ for python、安装 mysql 连接器,甚至安装最新的 mysql 本身,以及其他所有事情都浮现在我的视线和脑海中。 我在 Windows 10 上有 python 2.7.11。我已经安装了大部分 Windows 更新。 它总是发生:

easy_install Mysql-python
Searching for Mysql-python
Reading https://pypi.python.org/simple/Mysql-python/
Best match: MySQL-python 1.2.5
Downloading https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
Processing MySQL-python-1.2.5.zip
Writing c:\users\aref\appdata\local\temp\easy_install-nhmvzf\MySQL-python-1.2.5\setup.cfg
Running MySQL-python-1.2.5\setup.py -q bdist_egg --dist-dir c:\users\aref\appdata\local\temp\easy_install-nhmvzf\MySQL-python-1.2.5\egg-dist-tmp-idut0x
_mysql.c
C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include\config-win.h(203) : warning C4005: 'SIZEOF_OFF_T' : macro redefinition
        c:\python27\include\pyconfig.h(353) : see previous definition of 'SIZEOF_OFF_T'
C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include\config-win.h(301) : warning C4005: 'HAVE_STDDEF_H' : macro redefinition
        c:\python27\include\pyconfig.h(693) : see previous definition of 'HAVE_STDDEF_H'
_mysql.c(287) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
_mysql.c(317) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
_mysql.c(470) : warning C4244: 'initializing' : conversion from 'Py_ssize_t' to 'int', possible loss of data
_mysql.c(1168) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
_mysql.c(1274) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
_mysql.c(1466) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
_mysql.c(1468) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
_mysql.c(1504) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
_mysql.c(1506) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
_mysql.c(1532) : warning C4018: '<' : signed/unsigned mismatch
_mysql.c(2302) : warning C4244: 'function' : conversion from '__int64' to 'long', possible loss of data
_mysql.obj : warning LNK4197: export 'init_mysql' specified multiple times; using first specification
   Creating library build\temp.win-amd64-2.7\Release\_mysql.lib and object build\temp.win-amd64-2.7\Release\_mysql.exp
_mysql.obj : error LNK2019: unresolved external symbol mysql_error referenced in function _mysql_Exception
_mysql.obj : error LNK2019: unresolved external symbol mysql_errno referenced in function _mysql_Exception
_mysql.obj : error LNK2019: unresolved external symbol mysql_server_init referenced in function _mysql_server_init
_mysql.obj : error LNK2019: unresolved external symbol mysql_server_end referenced in function _mysql_server_end
_mysql.obj : error LNK2019: unresolved external symbol mysql_thread_safe referenced in function _mysql_thread_safe
_mysql.obj : error LNK2019: unresolved external symbol mysql_fetch_fields referenced in function _mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_num_fields referenced in function _mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_field_count referenced in function _mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_store_result referenced in function _mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_use_result referenced in function _mysql_ResultObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_real_connect referenced in function _mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_ssl_set referenced in function _mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_options referenced in function _mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_init referenced in function _mysql_ConnectionObject_Initialize
_mysql.obj : error LNK2019: unresolved external symbol mysql_close referenced in function _mysql_ConnectionObject_close
_mysql.obj : error LNK2019: unresolved external symbol mysql_affected_rows referenced in function _mysql_ConnectionObject_affected_rows
_mysql.obj : error LNK2019: unresolved external symbol mysql_debug referenced in function _mysql_debug
_mysql.obj : error LNK2019: unresolved external symbol mysql_dump_debug_info referenced in function _mysql_ConnectionObject_dump_debug_info
_mysql.obj : error LNK2019: unresolved external symbol mysql_autocommit referenced in function _mysql_ConnectionObject_autocommit
_mysql.obj : error LNK2019: unresolved external symbol mysql_commit referenced in function _mysql_ConnectionObject_commit
_mysql.obj : error LNK2019: unresolved external symbol mysql_rollback referenced in function _mysql_ConnectionObject_rollback
_mysql.obj : error LNK2019: unresolved external symbol mysql_next_result referenced in function _mysql_ConnectionObject_next_result
_mysql.obj : error LNK2019: unresolved external symbol mysql_set_server_option referenced in function _mysql_ConnectionObject_set_server_option
_mysql.obj : error LNK2019: unresolved external symbol mysql_sqlstate referenced in function _mysql_ConnectionObject_sqlstate
_mysql.obj : error LNK2019: unresolved external symbol mysql_warning_count referenced in function _mysql_ConnectionObject_warning_count
_mysql.obj : error LNK2019: unresolved external symbol mysql_escape_string referenced in function _mysql_escape_string
_mysql.obj : error LNK2019: unresolved external symbol mysql_real_escape_string referenced in function _mysql_escape_string
_mysql.obj : error LNK2019: unresolved external symbol mysql_fetch_lengths referenced in function _mysql_row_to_tuple
_mysql.obj : error LNK2019: unresolved external symbol __imp_strncat referenced in function _mysql_row_to_dict
_mysql.obj : error LNK2019: unresolved external symbol __imp_strncpy referenced in function _mysql_row_to_dict
_mysql.obj : error LNK2019: unresolved external symbol memset referenced in function _mysql_row_to_dict_old
_mysql.obj : error LNK2019: unresolved external symbol mysql_fetch_row referenced in function _mysql__fetch_row
_mysql.obj : error LNK2019: unresolved external symbol mysql_num_rows referenced in function _mysql_ResultObject_fetch_row
_mysql.obj : error LNK2019: unresolved external symbol mysql_change_user referenced in function _mysql_ConnectionObject_change_user
_mysql.obj : error LNK2019: unresolved external symbol mysql_character_set_name referenced in function _mysql_ConnectionObject_character_set_name
_mysql.obj : error LNK2019: unresolved external symbol mysql_set_character_set referenced in function _mysql_ConnectionObject_set_character_set
_mysql.obj : error LNK2019: unresolved external symbol mysql_get_character_set_info referenced in function _mysql_ConnectionObject_get_character_set_info
_mysql.obj : error LNK2019: unresolved external symbol mysql_get_client_info referenced in function _mysql_get_client_info
_mysql.obj : error LNK2019: unresolved external symbol mysql_get_host_info referenced in function _mysql_ConnectionObject_get_host_info
_mysql.obj : error LNK2019: unresolved external symbol mysql_get_proto_info referenced in function _mysql_ConnectionObject_get_proto_info
_mysql.obj : error LNK2019: unresolved external symbol mysql_get_server_info referenced in function _mysql_ConnectionObject_get_server_info
_mysql.obj : error LNK2019: unresolved external symbol mysql_info referenced in function _mysql_ConnectionObject_info
_mysql.obj : error LNK2019: unresolved external symbol mysql_insert_id referenced in function _mysql_ConnectionObject_insert_id
_mysql.obj : error LNK2019: unresolved external symbol mysql_kill referenced in function _mysql_ConnectionObject_kill
_mysql.obj : error LNK2019: unresolved external symbol mysql_ping referenced in function _mysql_ConnectionObject_ping
_mysql.obj : error LNK2019: unresolved external symbol mysql_real_query referenced in function _mysql_ConnectionObject_query
_mysql.obj : error LNK2019: unresolved external symbol mysql_select_db referenced in function _mysql_ConnectionObject_select_db
_mysql.obj : error LNK2019: unresolved external symbol mysql_shutdown referenced in function _mysql_ConnectionObject_shutdown
_mysql.obj : error LNK2019: unresolved external symbol mysql_stat referenced in function _mysql_ConnectionObject_stat
_mysql.obj : error LNK2019: unresolved external symbol mysql_thread_id referenced in function _mysql_ConnectionObject_thread_id
_mysql.obj : error LNK2019: unresolved external symbol __imp_sprintf referenced in function _mysql_ConnectionObject_repr
_mysql.obj : error LNK2019: unresolved external symbol mysql_data_seek referenced in function _mysql_ResultObject_data_seek
_mysql.obj : error LNK2019: unresolved external symbol mysql_row_seek referenced in function _mysql_ResultObject_row_seek
_mysql.obj : error LNK2019: unresolved external symbol mysql_row_tell referenced in function _mysql_ResultObject_row_seek
_mysql.obj : error LNK2019: unresolved external symbol mysql_free_result referenced in function _mysql_ResultObject_dealloc
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup
build\lib.win-amd64-2.7\_mysql.pyd : fatal error LNK1120: 56 unresolved externals
error: Setup script exited with error: command 'C:\\Users\\aref\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\link.exe' failed with exit status 1120

感谢您的帮助

【问题讨论】:

  • 我终于从 python 2.7.11 迁移到 2.7.12,我从未解决的问题也解决了这个转储错误..
  • 补充一点,我个人在尝试在 git 和 stack 上找到的其他解决方案时不断出错。但是,一旦我安装了 mysqlclient,然后在代码中尝试“导入 MySQLdb”,尽管终端 stackoverflow.com/a/42067480/3680309 +1 中的错误对我来说它仍然有效

标签: mysql-python


【解决方案1】:

我遇到了同样的问题。这就是我为解决它所做的:

  1. 从以下位置下载 mysqlclient whl 文件 http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient(例如,如果您 在 Win64 上安装 Python 3.6,下载 mysqlclient‑1.3.9‑cp36‑cp36m‑win_amd64.whl)。

  2. pip install mysqlclient‑1.3.9‑cp36‑cp36m‑win_amd64.whl

  3. import MySQLdb 现在应该可以在 Python 代码中使用了。

【讨论】:

    【解决方案2】:

    我也遇到了和你一样的问题,其他答案似乎都不适合我,

    例如 - Compiling mysql-python on Windows with PIP

    这是另一个有效答案的变体

    1. 点安装mysqlclient
    2. “import MySQLdb”现在应该可以在代码中工作了

    或者,您可以添加此代码

    try:
    
        import MySQLdb as mysql
    
    except Exception as e:
    
        import os 
        os.system("pip install mysqlclient")
        import MySQLdb as mysql
    
    db = mysql.connect(host=host, user=user, passwd=passwd, db=db);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 2012-10-20
      • 2016-04-20
      • 1970-01-01
      相关资源
      最近更新 更多