I have c++ code that compiles fine in MSVS 2015 which is installed on my PC. I've been tasked to make a python extension using cython to be able to call c++ function from our python application. I have installed anaconda 5.2 w/ cython installed already. The c++ has a bunch of header files that need to be included when compiling. I'm trying to build one function and am running into the same error.
My test.pyx looks like this for the one function:
cimport test
cimport cython
def pxd_PIXCIclose():
res = test.pxd_PIXCIclose()
return res
The test.pxd is as follows:
cdef extern from "D:\epix\inc\xcliball.h":
int pxd_PIXCIclose()
setup.py is:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
ext_modules = Extension(
name = "test",
sources=["test.pyx"],
include_dirs=["D:\epix\lib", "D:\epix\inc"],
library_dirs="D:\epix\inc\XCLIBW64.lib","D:\epix\lib\PXIPLW64.lib"]
)
setup(
name = "test.pyx",
ext_modules = cythonize([ext_modules])
)
The test.c is created but then I get a bunch of build errors on the headers in the C++ include folder:
python setup.py build_ext --inplace --compiler=msvc
Compiling test.pyx because it depends on .\test.pxd.
[1/1] Cythonizing test.pyx
running build_ext
building 'test' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe
/c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\epix\lib -ID:\epix\inc -
IC:\Anaconda3\include -IC:\Anaconda3\include "-IC:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files
(x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tctest.c
/Fobuild\temp.win-amd64-3.6\Release\test.obj
test.c
d:\epix\inc\pxlibsv.h(312): error C2061: syntax error: identifier 'HANDLE'
d:\epix\inc\pxlibsv.h(317): error C2059: syntax error: '}'
d:\epix\inc\pxlibsv.h(827): error C2143: syntax error: missing ')' before
'*'
d:\epix\inc\pxlibsv.h(827): error C2081: 'HANDLE': name in formal parameter
list illegal
d:\epix\inc\pxlibsv.h(827): error C2143: syntax error: missing ';' before
'*'
d:\epix\inc\pxlibsv.h(827): error C2059: syntax error: '*'
.
.
.
d:\epix\inc\xclibsc.h(369): fatal error C1003: error count exceeds 100;
stopping compilation
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
I'm guessing my setup.py is not correct? Anyone have any pointers on what is happening?
Update to my original post, by adding #include windows.h, the original 'HANDLE' error is now gone but I received this link error now:
(base) d:\epix\cython>python setup.py build_ext --inplace --compiler=msvc
running build_ext
building 'test' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe
/c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Anaconda3\include -ID:\epix\lib -
ID:\epix\inc -IC:\Anaconda3\include -IC:\Anaconda3\include "-IC:\Program
Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files
(x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tctest.c
/Fobuild\temp.win-amd64-3.6\Release\test.obj
test.c
C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL
/MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Anaconda3\Lib
/LIBPATH:D:\epix\inc\XCLIBW64.lib /LIBPATH:D:\epix\lib\PXIPLW64.lib
/LIBPATH:C:\Anaconda3\libs /LIBPATH:C:\Anaconda3\PCbuild\amd64
"/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64"
"/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows
Kits\10\lib\10.0.10586.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows
Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows
Kits\10\lib\10.0.10586.0\um\x64" /EXPORT:PyInit_test build\temp.win-amd64-
3.6\Release\test.obj /OUT:d:\epix\cython\test.cp36-win_amd64.pyd
/IMPLIB:build\temp.win-amd64-3.6\Release\test.cp36-win_amd64.lib
test.obj : warning LNK4197: export 'PyInit_test' specified multiple times;
using first specification
Creating library build\temp.win-amd64-3.6\Release\test.cp36-win_amd64.lib
and object build\temp.win-amd64-3.6\Release\test.cp36-win_amd64.exp
test.obj : error LNK2001: unresolved external symbol pxd_PIXCIclose
d:\epix\cython\test.cp36-win_amd64.pyd : fatal error LNK1120: 1 unresolved
externals error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120
Any suggestions on resolving this error? Thank you.
Based on compiler output, HANDLE is not defined. Did you know, that with VS2015 you need to add path to SDK ? It is not included, as I can see. Add C:\Program Files (x86)\Windows Kits\10 \ include\ platformtoolset\um to path. Platformtoolset will define subfolder in yours include path. Hope it helps.
By adding #include windows.h to my header and then changing my original setup.py to the following:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
ext_modules = Extension(
name = "test",
sources=["test.pyx"],
include_dirs=["D:\epix\lib", "D:\epix\inc"],
library_dirs=["D:\epix\inc"],
libraries=["XCLIBW64", "PXIPLW64"]
)
setup(
name = "test.pyx",
ext_modules = cythonize([ext_modules])
I was able to successfully cythonize one of the functions in my c project. Thank you to all who gave me suggestions that pointed me in the right direction.
Related
Tried installing python-ldap, but failed
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=3.4.0 "-DLDAPMODULE_AUTHOR=python-ldap project" "-DLDAPMODULE_LICENSE=Python style" -IModules -IC:\Users\rathod\AppData\Local\Programs\Python\Python39\include -IC:\Users\rathod\AppData\Local\Programs\Python\Python39\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /TcModules/LDAPObject.c /Fobuild\temp.win-amd64-cpython-39\Release\Modules/LDAPObject.obj
LDAPObject.c
c:\users\rathod\appdata\local\temp\pip-install-dkw9jd4z\python-ldap_05f9ed21408d4097a9c6bd894511d8b7\modules\common.h(15): fatal error C1083: Cannot open include file: 'lber.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for python-ldap
Failed to build python-ldap
ERROR: Could not build wheels for python-ldap, which is required to install pyproject. toml-based projects
Tried using few of the .whl files from https://www.lfd.uci.edu/~gohlke/pythonlibs/#_python-ldap, but failed
PS C:\Users\rathod\source\repos\00 Dell-Gitlab staging\replication_status> pip install .\python_ldap-3.4.0-cp311-cp311-win32.whl
ERROR: python_ldap-3.4.0-cp311-cp311-win32.whl is not a supported wheel on this platform.
Has anyone faced same challenge, and if there is any way to install this old module on windows system?
I want to use openfst python wrapper on my python application.
When I run
pip install openfst
for Python 3.6 gave error as the following.
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\aliye\Anaconda3\include -IC:\Users\aliye\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /EHsc /Tppywrapfst.cc /Fobuild\temp.win-amd64-3.6\Release\pywrapfst.obj -std=c++11 -Wno-unneeded-internal-declaration -Wno-unused-function
cl : Command line error D8021 : invalid numeric argument '/Wno-unneeded-internal-declaration'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
Obviously, it looks like the Visual Studio compiler is complaining about /Wno-unneeded-internal-declaration flag while it is trying to build the C extensions.
The easiest solution would be to download a pre-compiled version that matches your system at their website
Also, based on their site, it seems that they used Visual Studio 2013.You may be able to install and compile it using VS13.
I get this error when compile hello.py with "python setup.py build_ext --inplace" . I have searched for the error but get nothing. Has anyone ever solved a similar problem? os=win7-64, python=3.6.2, cython=0.27.1, visual stdudio=2015.
# hello.py
def say_hello_to(name):
print("Hello %s!" % name)
# setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("hello.py")
)
E:\Crawler>python setup.py build_ext --inplace
running build_ext
building 'hello' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox
/W3 /GL /DNDEBUG /MD "-ID:\Program Files (x86)\Python36-32\include" "-ID:\Progr
am Files (x86)\Python36-32\include" "-IC:\Program Files (x86)\Microsoft Visual S
tudio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10
240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-
IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program F
iles (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\
Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files\Microsoft SDKs\Windo
ws\v7.0\Include\" /Tchello.c /Fobuild\temp.win32-3.6\Release\hello.obj
cl : Command line error D8003 : missing source filename
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\
cl.exe' failed with exit status 2
I'm trying to compile a hello world example with Cython on Windows 10.
I have visual studio 2015 community.
Python 3.5.2
My setup.py looks like this:
from distutils.core import setup
from Cython.Build import cythonize
setup (
name='print hello world',
ext_modules=cythonize("print_h_w.pyx", compiler_directives=
{'language_level': 3}),
)
The file I'm trying to compile looks like this:
print('Hello World')
I build with this command:
python setup.py build_ext --inplace
I keep getting this error:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe
/c /nologo /Ox /W3 /GL /DNDEBUG /MD -
IC:\Users\Paul\AppData\Local\Programs\Python\Python35\include -
IC:\Users\Paul\AppData\Local\Programs\Python\Python35\include "-IC:\Program
Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files
(x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files
(x86)\Windows Kits\10\include\10.0.14393.0\winrt" "-IC:\Program Files
(x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\" /Tcprint_h_w.c
/Fobuild\temp.win-amd64-3.5\Release\print_h_w.obj
cl : Command line error D8003 : missing source filename
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
I've been doing a lot of research but I've turned up a lot of nothing. How can I fix this?
I think you should have import cython in your print_h_w.pyx file :
import cython
print("hello world")
Trying to do a simple pip install TA-lib but am getting errors, in install Microsoft visual studios 14 but still the problem persists.
error code http://pastebin.com/h4jHWd1m
I tried to install it manually but get this:
setup.py:77: UserWarning: Cannot find ta-lib library, installation may fail.
warnings.warn('Cannot find ta-lib library, installation may fail.')
running install
running build
running build_py
running build_ext
building 'talib.common' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Python36-32\lib\site-packages\numpy\core\include -Ic:\ta-lib\c\include -IC:\Python36-32\include -IC:\Python36-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tctalib/common.c /Fobuild\temp.win32-3.6\Release\talib/common.obj
common.c
talib/common.c(240): fatal error C1083: Cannot open include file: 'ta_libc.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
The problem seems to be the same, any ideas ?
SOLVED. I had to download this and unzip to c:\
See https://github.com/mrjbq7/ta-lib#dependencies
Download file TA_Lib-0.4.24-cp37-cp37m-win_amd64.whl from https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib
then use pip install TA_Lib-0.4.24-cp37-cp37m-win_amd64.whl