Skip to content

Commit 4bb85b2

Browse files
authored
Better support for building on Windows (#484)
1 parent 180c9df commit 4bb85b2

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ Or when you have question about MySQL:
2828
Building mysqlclient on Windows is very hard.
2929
But there are some binary wheels you can install easily.
3030

31+
If binary wheels do not exist for your version of Python, it may be possible to
32+
build from source, but if this does not work, **do not come asking for support.**
33+
To build from source, download the
34+
[MariaDB C Connector](https://mariadb.com/downloads/#connectors) and install
35+
it. It must be installed in the default location
36+
(usually "C:\Program Files\MariaDB\MariaDB Connector C" or
37+
"C:\Program Files (x86)\MariaDB\MariaDB Connector C" for 32-bit). If you
38+
build the connector yourself or install it in a different location, set the
39+
environment variable `MYSQLCLIENT_CONNECTOR` before installing. Once you have
40+
the connector installed and an appropriate version of Visual Studio for your
41+
version of Python:
42+
43+
```
44+
$ pip install mysqlclient
45+
```
46+
3147
### macOS (Homebrew)
3248

3349
Install MySQL and mysqlclient:

setup_windows.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
import os
22
import sys
3-
from distutils.msvccompiler import get_build_version
43

54

65
def get_config():
76
from setup_common import get_metadata_and_options, create_release_file
87

98
metadata, options = get_metadata_and_options()
109

11-
connector = options["connector"]
10+
client = "mariadbclient"
11+
connector = os.environ.get("MYSQLCLIENT_CONNECTOR", options.get("connector"))
12+
if not connector:
13+
connector = os.path.join(
14+
os.environ["ProgramFiles"], "MariaDB", "MariaDB Connector C"
15+
)
1216

1317
extra_objects = []
1418

15-
# client = "mysqlclient"
16-
client = "mariadbclient"
17-
18-
vcversion = int(get_build_version())
19-
if client == "mariadbclient":
20-
library_dirs = [os.path.join(connector, "lib", "mariadb")]
21-
libraries = [
22-
"kernel32",
23-
"advapi32",
24-
"wsock32",
25-
"shlwapi",
26-
"Ws2_32",
27-
"crypt32",
28-
"secur32",
29-
"bcrypt",
30-
client,
31-
]
32-
include_dirs = [os.path.join(connector, "include", "mariadb")]
33-
else:
34-
library_dirs = [
35-
os.path.join(connector, r"lib\vs%d" % vcversion),
36-
os.path.join(connector, "lib"),
37-
]
38-
libraries = ["kernel32", "advapi32", "wsock32", client]
39-
include_dirs = [os.path.join(connector, r"include")]
19+
library_dirs = [
20+
os.path.join(connector, "lib", "mariadb"),
21+
os.path.join(connector, "lib"),
22+
]
23+
libraries = [
24+
"kernel32",
25+
"advapi32",
26+
"wsock32",
27+
"shlwapi",
28+
"Ws2_32",
29+
"crypt32",
30+
"secur32",
31+
"bcrypt",
32+
client,
33+
]
34+
include_dirs = [
35+
os.path.join(connector, "include", "mariadb"),
36+
os.path.join(connector, "include"),
37+
]
4038

4139
extra_link_args = ["/MANIFEST"]
4240

site.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ static = False
99

1010
# http://stackoverflow.com/questions/1972259/mysql-python-install-problem-using-virtualenv-windows-pip
1111
# Windows connector libs for MySQL. You need a 32-bit connector for your 32-bit Python build.
12-
connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.1
12+
connector =

0 commit comments

Comments
 (0)