问题
I have a need to make use of Chromium's Compact Language Detector library within a Python script.
AFAIK, there are two projects that leverage this library, but I have been having troubles with getting either of them set up on a Windows 7 machine.
I had some similar problems with Mike McCandless Original Project (GoogleCode), but I then spotted Matt Sanford fork on the same Project (github). For the purpose of this question, I will focus on Matts project, as it seems to have been updated more often (but happy to get an answer that works for either project).
- Downloaded the project as a zip, and extracted to my local drive.
- Ran vcvarsall.bat from CMD
- Then ran the build.win.cmd batch file. This ran ok.
- Copied the resulting libcld.lib to ports/python/cld.lib
Tried running the setup.py but it returns with the following against line 12.
exceptions.TypeError: init() keywords must be strings
++EDIT++ Found this issue:
setup.py fails on Windows. The hackish solution to fix this is to make pkgconfig return the dict {'define_macros': [('WIN32',None)], 'libraries': packages}
Im a bit of a rookie, but not entirely sure on the steps to implement this hack. Can anyone give me some slightly more verbose steps?
回答1:
Try this patch (works for me):
diff --git a/ports/python/setup.py b/ports/python/setup.py
index e1950c3..889f21a 100644
--- a/ports/python/setup.py
+++ b/ports/python/setup.py
@@ -9,7 +9,10 @@ def pkgconfig(*packages, **kw):
module = Extension('cld',
['pycldmodule.cc'],
- **pkgconfig('cld'))
+ define_macros=[('WIN32', None)],
+ libraries=['libcld'],
+ include_dirs=['..\\..\\'],
+ library_dirs=['..\\..\\'])
setup(name='cld',
version='0.031415',
来源:https://stackoverflow.com/questions/13328180/installing-cld-libary-on-windows-and-bind-to-python