I've been trying to install this python package on windows, but unsuccessfully so far.
it uses Cython and cyCada to interface with C and use the boost library.
I have VS2022 community installed and i added the boost library to its include directory.
using MSVC, when i run python setup.py install
this is what i get.
Compiling src_cython/cycADa_interface.pyx because it changed.
[1/1] Cythonizing src_cython/cycADa_interface.pyx
running install
running build
running build_ext
building 'cycADa_interface' extension
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
creating build\temp.win-amd64-3.8\Release\build
creating build\temp.win-amd64-3.8\Release\build\src_cython
creating build\temp.win-amd64-3.8\Release\src_cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /EHsc /Tpbuild\src_cython/cycADa_interface.cpp /Fobuild\temp.win-amd64-3.8\Release\build\src_cython/cycADa_interface.obj -std=c 11
cl : Ligne de commande warning D9002 : option '-std=c 11' inconnue ignorée
cycADa_interface.cpp
C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
build\src_cython/cycADa_interface.cpp(7250): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(7259): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(7268): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(8201): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(8210): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(8459): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(8676): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(8873): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
build\src_cython/cycADa_interface.cpp(9090): warning C4267: '=' : conversion de 'size_t' en 'int', perte possible de données
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /EHsc /Tpsrc_cpp/cycADa_adouble.cpp /Fobuild\temp.win-amd64-3.8\Release\src_cpp/cycADa_adouble.obj -std=c 11
cl : Ligne de commande warning D9002 : option '-std=c 11' inconnue ignorée
cycADa_adouble.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /EHsc /Tpsrc_cpp/cycADa_tape.cpp /Fobuild\temp.win-amd64-3.8\Release\src_cpp/cycADa_tape.obj -std=c 11
cl : Ligne de commande warning D9002 : option '-std=c 11' inconnue ignorée
cycADa_tape.cpp
src_cpp/cycADa_tape.cpp(29): warning C4244: 'argument' : conversion de 'double' en 'const _Ty', perte possible de données
with
[
_Ty=long
]
src_cpp/cycADa_tape.cpp(78): warning C4267: 'return' : conversion de 'size_t' en 'long', perte possible de données
src_cpp/cycADa_tape.cpp(82): warning C4267: 'return' : conversion de 'size_t' en 'long', perte possible de données
src_cpp/cycADa_tape.cpp(86): warning C4267: 'return' : conversion de 'size_t' en 'long', perte possible de données
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /EHsc /Tpsrc_cpp/cycADa_elemOp.cpp /Fobuild\temp.win-amd64-3.8\Release\src_cpp/cycADa_elemOp.obj -std=c 11
cl : Ligne de commande warning D9002 : option '-std=c 11' inconnue ignorée
cycADa_elemOp.cpp
creating C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\ad\cycADa\build\lib.win-amd64-3.8
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:C:\Program Files\Python38\libs" "/LIBPATH:C:\Program Files\Python38\PCbuild\amd64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.19041.0\\um\x64" /EXPORT:PyInit_cycADa_interface build\temp.win-amd64-3.8\Release\build\src_cython/cycADa_interface.obj build\temp.win-amd64-3.8\Release\src_cpp/cycADa_adouble.obj build\temp.win-amd64-3.8\Release\src_cpp/cycADa_tape.obj build\temp.win-amd64-3.8\Release\src_cpp/cycADa_elemOp.obj /OUT:build\lib.win-amd64-3.8\cycADa_interface.cp38-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.8\Release\build\src_cython\cycADa_interface.cp38-win_amd64.lib
Création de la bibliothèque build\temp.win-amd64-3.8\Release\build\src_cython\cycADa_interface.cp38-win_amd64.lib et de l'objet build\temp.win-amd64-3.8\Release\build\src_cython\cycADa_interface.cp38-win_amd64.exp
Génération de code en cours
Fin de la génération du code
running install_lib
copying build\lib.win-amd64-3.8\cycADa_interface.cp38-win_amd64.pyd -> C:\Program Files\Python38\Lib\site-packages
running install_egg_info
Removing C:\Program Files\Python38\Lib\site-packages\UNKNOWN-0.0.0-py3.8.egg-info
Writing C:\Program Files\Python38\Lib\site-packages\UNKNOWN-0.0.0-py3.8.egg-info
When i try to run the example provided in the package i get this:
[INFO]: start implicit Euler integration from t0 = 0.0 to T = 111600.0, with H = 180.0
Elapsed (time): 00-00-00.154
Elapsed (proc): 00-00-00.125
Traceback (most recent call last):
File "c:/Users/rabhi.yacine/Desktop/cyc/python-transient-gas-network-simulator/example/GasLib40_modified/main.py", line 12, in <module>
simulate_gas_network(configPath)
File "C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\simulator\configurator.py", line 70, in simulate_gas_network
imp_euler_report = integrate(net,
File "C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\paso\solvers\dae\ImpEuler.py", line 167, in integrate
out = ImpEulerStep(sys_func = sys_func,
File "C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\paso\solvers\dae\ImpEuler.py", line 43, in ImpEulerStep
if use_cycADa: _inner_step_func, _inner_step_Dfunc = cycADa_wrapper(inner_step_func, dim_x)
File "C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\paso\differentiation\util\wrapper_cycADa.py", line 18, in cycADa_wrapper
trace.allocJac(False) # allocate cycADa memory for Jacobian
File "src_cython\cycADa_interface.pyx", line 512, in cycADa_interface.tape.allocJac
File "src_cython\cycADa_interface.pyx", line 478, in cycADa_interface.tape.set_grad_pointer
ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long'
I also tried to use MinGw to install this package. So i installed MinGw provided in this link and then i had to create a distutils.cfg file in the python Lib/disutils folder
distutils.cfg
[build]
compiler=mingw32
when i run python setup.py install
this is what i get.
Compiling src_cython/cycADa_interface.pyx because it changed.
[1/1] Cythonizing src_cython/cycADa_interface.pyx
running install
running build
running build_ext
dllwrap: WARNING: dllwrap is deprecated, use gcc -shared or ld -shared instead
building 'cycADa_interface' extension
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
creating build\temp.win-amd64-3.8\Release\build
creating build\temp.win-amd64-3.8\Release\build\src_cython
creating build\temp.win-amd64-3.8\Release\src_cpp
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" -c build\src_cython/cycADa_interface.cpp -o build\temp.win-amd64-3.8\Release\build\src_cython\cycada_interface.o -std=c 11
In file included from C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/ndarraytypes.h:4,
from C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/ndarrayobject.h:12,
from C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/arrayobject.h:4,
from build\src_cython/cycADa_interface.cpp:748:
C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/npy_common.h:168:20: warning: 'int _fseeki64(FILE*, long long int, int)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
168 | extern int __cdecl _fseeki64(FILE *, long long, int);
| ^~~~~~~~~
C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/npy_common.h:169:26: warning: 'long long int _ftelli64(FILE*)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
169 | extern long long __cdecl _ftelli64(FILE *);
| ^~~~~~~~~
In file included from C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/ndarraytypes.h:1822,
from C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/ndarrayobject.h:12,
from C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/arrayobject.h:4,
from build\src_cython/cycADa_interface.cpp:748:
C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h:15:77: note: '#pragma message: C:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION'
15 | "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION")
| ^
build\src_cython/cycADa_interface.cpp: In function 'PyTypeObject* __Pyx_ImportType(PyObject*, const char*, const char*, size_t, __Pyx_ImportType_CheckSize)':
build\src_cython/cycADa_interface.cpp:39358:24: warning: unknown conversion type character 'z' in format [-Wformat=]
39358 | "Expected %zd from C header, got %zd from PyObject",
| ^
build\src_cython/cycADa_interface.cpp:39358:47: warning: unknown conversion type character 'z' in format [-Wformat=]
39358 | "Expected %zd from C header, got %zd from PyObject",
| ^
build\src_cython/cycADa_interface.cpp:39357:13: warning: too many arguments for format [-Wformat-extra-args]
39357 | "%s.%s size changed, may indicate binary incompatibility. "
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39358 | "Expected %zd from C header, got %zd from PyObject",
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" -c src_cpp/cycADa_adouble.cpp -o build\temp.win-amd64-3.8\Release\src_cpp\cycada_adouble.o -std=c 11
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" -c src_cpp/cycADa_tape.cpp -o build\temp.win-amd64-3.8\Release\src_cpp\cycada_tape.o -std=c 11
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc_cython -IC:\Users\rabhi.yacine\AppData\Roaming\Python\Python38\site-packages\numpy\core\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" -c src_cpp/cycADa_elemOp.cpp -o build\temp.win-amd64-3.8\Release\src_cpp\cycada_elemop.o -std=c 11
writing build\temp.win-amd64-3.8\Release\build\src_cython\cycADa_interface.cp38-win_amd64.def
creating build\lib.win-amd64-3.8
C:\MinGW\bin\g .exe -shared -s build\temp.win-amd64-3.8\Release\build\src_cython\cycada_interface.o build\temp.win-amd64-3.8\Release\src_cpp\cycada_adouble.o build\temp.win-amd64-3.8\Release\src_cpp\cycada_tape.o build\temp.win-amd64-3.8\Release\src_cpp\cycada_elemop.o build\temp.win-amd64-3.8\Release\build\src_cython\cycADa_interface.cp38-win_amd64.def "-LC:\Program Files\Python38\libs" "-LC:\Program Files\Python38\PCbuild\amd64" -lpython38 -lmsvcr143 -o build\lib.win-amd64-3.8\cycADa_interface.cp38-win_amd64.pyd
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmsvcr143
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\MinGW\\bin\\g .exe' failed with exit status 1
Any help on how i could install on windows would be amazing. I have tried on linux and it works great. but i have to create an executable for distribution on windows so i have to install it on windows to then use pyinstaller to create an exe (pyinstaller does not support cross compiling)
Thank you.
CodePudding user response:
Keep using MSVC. MinGW isn't really supported as a Windows compiler (it probably can be made to work but it's easier not to have to)
You may want to edit setup.py to change -std=c 11
to /std:c 14
(just so MSVC understands the option... I've used c 14 since MSVC doesn't seem to have a c 11 flag).
Your issue is then that the code is written with some poor platform compatibility assumptions. Your current error is from:
np.ndarray[np.int_t, mode="c", ndim=1] local_indices
np.ndarray[np.int_t, mode="c", ndim=1] local_indptr
...
local_indices = np.zeros(shape = (len_z len_y, ), dtype = np.int64)
local_indptr = np.zeros(shape = (s m 1, ), dtype = np.int64)
It makes the assumption that an int
is 64 bits, which is not true on Windows.
Change the first two lines from np.int_t
to np.int64_t
.
You may find you need to fix a whole bunch of similar errors. The authors seem to have been clear that they haven't tested on anything but linux.