Compiling mysql-python on Windows with PIP

2019-04-18 05:36发布

So I have Python 2.7 and setuptools installed on my Windows 7 laptop. I also have Visual Studio 2008 Express installed and MySQL with dev tools.

I am trying to install mysql-python via pip like:

pip install mysql-python

I am getting link errors:

   Creating library build\temp.win32-2.7\Release\_mysql.lib and object build\temp.win32-2.7\Release\_mysql.exp

_mysql.obj : error LNK2019: unresolved external symbol _mysql_error@4 referenced in function __mysql_Exception

_mysql.obj : error LNK2019: unresolved external symbol _mysql_errno@4 referenced in function __mysql_Exception

_mysql.obj : error LNK2019: unresolved external symbol _mysql_server_init@12 referenced in function __mysql_server_init

_mysql.obj : error LNK2019: unresolved external symbol _mysql_server_end@0 referenced in function __mysql_server_end

_mysql.obj : error LNK2019: unresolved external symbol _mysql_thread_safe@0 referenced in function __mysql_thread_safe

_mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_fields@4 referenced in function __mysql_ResultObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_num_fields@4 referenced in function __mysql_ResultObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_field_count@4 referenced in function __mysql_ResultObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_store_result@4 referenced in function __mysql_ResultObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_use_result@4 referenced in function __mysql_ResultObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function __mysql_ConnectionObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_ssl_set@24 referenced in function __mysql_ConnectionObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_options@12 referenced in function __mysql_ConnectionObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function __mysql_ConnectionObject_Initialize

_mysql.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function __mysql_ConnectionObject_close

_mysql.obj : error LNK2019: unresolved external symbol _mysql_affected_rows@4 referenced in function __mysql_ConnectionObject_affected_rows

_mysql.obj : error LNK2019: unresolved external symbol _mysql_debug@4 referenced in function __mysql_debug

_mysql.obj : error LNK2019: unresolved external symbol _mysql_dump_debug_info@4 referenced in function __mysql_ConnectionObject_dump_debug_info

_mysql.obj : error LNK2019: unresolved external symbol _mysql_autocommit@8 referenced in function __mysql_ConnectionObject_autocommit

_mysql.obj : error LNK2019: unresolved external symbol _mysql_commit@4 referenced in function __mysql_ConnectionObject_commit

_mysql.obj : error LNK2019: unresolved external symbol _mysql_rollback@4 referenced in function __mysql_ConnectionObject_rollback

_mysql.obj : error LNK2019: unresolved external symbol _mysql_next_result@4 referenced in function __mysql_ConnectionObject_next_result

_mysql.obj : error LNK2019: unresolved external symbol _mysql_set_server_option@8 referenced in function __mysql_ConnectionObject_set_server_option

_mysql.obj : error LNK2019: unresolved external symbol _mysql_sqlstate@4 referenced in function __mysql_ConnectionObject_sqlstate

_mysql.obj : error LNK2019: unresolved external symbol _mysql_warning_count@4 referenced in function __mysql_ConnectionObject_warning_count

_mysql.obj : error LNK2019: unresolved external symbol _mysql_escape_string@12 referenced in function __mysql_escape_string

_mysql.obj : error LNK2019: unresolved external symbol _mysql_real_escape_string@16 referenced in function __mysql_escape_string

_mysql.obj : error LNK2019: unresolved external symbol _mysql_fetch_lengths@4 referenced in function __mysql_row_to_tuple

_mysql.obj : error LNK2019: unresolved external symbol __imp__strncpy referenced in function __mysql_row_to_dict

_mysql.obj : error LNK2019: unresolved external symbol __imp__strncat 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@4 referenced in function __mysql__fetch_row

_mysql.obj : error LNK2019: unresolved external symbol _mysql_num_rows@4 referenced in function __mysql_ResultObject_fetch_row

_mysql.obj : error LNK2019: unresolved external symbol _mysql_change_user@16 referenced in function __mysql_ConnectionObject_change_user

_mysql.obj : error LNK2019: unresolved external symbol _mysql_character_set_name@4 referenced in function __mysql_ConnectionObject_character_set_name

_mysql.obj : error LNK2019: unresolved external symbol _mysql_set_character_set@8 referenced in function __mysql_ConnectionObject_set_character_set

_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_character_set_info@8 referenced in function __mysql_ConnectionObject_get_character_set_info

_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_client_info@0 referenced in function __mysql_get_client_info

_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_host_info@4 referenced in function __mysql_ConnectionObject_get_host_info

_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_proto_info@4 referenced in function __mysql_ConnectionObject_get_proto_info

_mysql.obj : error LNK2019: unresolved external symbol _mysql_get_server_info@4 referenced in function __mysql_ConnectionObject_get_server_info

_mysql.obj : error LNK2019: unresolved external symbol _mysql_info@4 referenced in function __mysql_ConnectionObject_info

_mysql.obj : error LNK2019: unresolved external symbol _mysql_insert_id@4 referenced in function __mysql_ConnectionObject_insert_id

_mysql.obj : error LNK2019: unresolved external symbol _mysql_kill@8 referenced in function __mysql_ConnectionObject_kill

_mysql.obj : error LNK2019: unresolved external symbol _mysql_ping@4 referenced in function __mysql_ConnectionObject_ping

_mysql.obj : error LNK2019: unresolved external symbol _mysql_real_query@12 referenced in function __mysql_ConnectionObject_query

_mysql.obj : error LNK2019: unresolved external symbol _mysql_select_db@8 referenced in function __mysql_ConnectionObject_select_db

_mysql.obj : error LNK2019: unresolved external symbol _mysql_shutdown@8 referenced in function __mysql_ConnectionObject_shutdown

_mysql.obj : error LNK2019: unresolved external symbol _mysql_stat@4 referenced in function __mysql_ConnectionObject_stat

_mysql.obj : error LNK2019: unresolved external symbol _mysql_thread_id@4 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@12 referenced in function __mysql_ResultObject_data_seek

_mysql.obj : error LNK2019: unresolved external symbol _mysql_row_seek@8 referenced in function __mysql_ResultObject_row_seek

_mysql.obj : error LNK2019: unresolved external symbol _mysql_row_tell@4 referenced in function __mysql_ResultObject_row_seek

_mysql.obj : error LNK2019: unresolved external symbol _mysql_free_result@4 referenced in function __mysql_ResultObject_dealloc

LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12

build\lib.win32-2.7\_mysql.pyd : fatal error LNK1120: 56 unresolved externals

error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\link.exe' failed with exit status 1120

Any ideas how to solve this issue? Thanks

4条回答
可以哭但决不认输i
2楼-- · 2019-04-18 06:13

I tried this and it worked for me on Win7 64 bit instalation of anaconda. type this into your command prompt:

pip install mysql-python

My installation works because i am using Studio 2010.

查看更多
一纸荒年 Trace。
3楼-- · 2019-04-18 06:14

This seems like your installation don't detect the mysql client library. Find and copy mysqlcppconn.dll from your mysql installation to a folder which is read by the build script, for example the windows folder. For more information check out this link https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-apps-windows-visual-studio.html#connector-cpp-application-build-dynamic

查看更多
萌系小妹纸
4楼-- · 2019-04-18 06:20

I had the same problem and exact same errors.I don't know why but

pip install Mysql-python

gave errors. But when I tried

easy_install Mysql-python

It worked.I don't know why but it did work but would love to know why.

查看更多
祖国的老花朵
5楼-- · 2019-04-18 06:25

Check that both are either 32bit or 64bit, and you don't have a mismatch between them. When I had this problem, it was because I installed a 64bit Python but had a 32bit MySQL installed. The pip installer could therefore not find matching binaries to link to, and failed with this message. Fixing the problem was simply a matter of installing the 32bit Python over the top, and everything worked.

Note that it may also be possible to update MySQL to 64bit, but installers at the moment for MySQL appear to be 32bit only. You can install via a .zip file downloaded from the official MySQL site though that has 64bit binaries in it.

To find out which you have installed:

  • For Python, simply go to the command line and type in python. It should show you what version and if it was a 32bit or 64bit install like so

    Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32

  • For MySQL, the easiest way will likely be which folder it is installed in. If it installs to Program Files/ then it is 64bit, but if it installs to Program Files (x86)/ it is 32bit
查看更多
登录 后发表回答