F2I-Consulting / fesapi

API for ENERGISTICS™ data standards (mainly RESQML™), multi-languages (C++, Java, C#, Python)
Apache License 2.0
34 stars 24 forks source link

Couldn't import fesapi after installation on Windows for Python #325

Closed fuyuli123456 closed 1 year ago

fuyuli123456 commented 1 year ago

I believe I followed all the instructions except "Please first install the wheel located in fesapi/python/dist". There is no dist folder. Below are the files in the fesapi/python/ folder. Is the installation incomplete?

image

fuyuli123456 commented 1 year ago

I tried to add in python path: "sys.path.append("...\fesapi\python")", then "import fesapi", but got the error: cannot import name '_fesapi' from partially initialized module 'fesapi' (most likely due to a circular import) (...\python\fesapi__init__.py)

philippeVerney commented 1 year ago

Hi,

Did you build FESAPI with visual studio and install it (by building the VIsual Studio INSTALL project) ? Could you paste last lines of the build log please? This is the responsability of the (Visual studio) build and install to produce the fesapi/python/dist. I'll give a try if you actually successfully did the build and the install.

philippeVerney commented 1 year ago

FYI if you understand cmake this is where the final python generation should be processed.

philippeVerney commented 1 year ago

And here is the CI where python is tested. However, it is done on ubuntu (not on windows). I just highlighted the line of the install

fuyuli123456 commented 1 year ago

Thank you for the quick reply and you are right. I previously built the entire Fesapi solution, and it turned out that the 3 other projects were built successfully, but the INSTALL project was skipped. I just re-built the INSTALL project and got the error below: image

philippeVerney commented 1 year ago

Try to rebuild in release (withdebinfo if you want and even without optimisation if you want) mode please. It looks you build in debug mode which is much less tested.

philippeVerney commented 1 year ago

If you really want to build a debug version, please try first to set this SWIG_LINKED_TO_RELEASE cmake variable to false.

fuyuli123456 commented 1 year ago

I rebuilt with release mode and still got the same error: image

fuyuli123456 commented 1 year ago

The complete line before the error is below. And I can find the file "FesapiCppd.2.8.0.0.lib" under \fesapiEnv\build\install\lib\ and \fesapiEnv\build\src\Release\

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:/Users/fuyl/tools/fesapiEnv/build/install/lib /LIBPATH:C:\ProgramData\Miniconda3\libs /LIBPATH:C:\ProgramData\Miniconda3\PCbuild\amd64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\ATLMFC\lib\x64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\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 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\lib\x64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\lib\x64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\lib\x64 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\VS\UnitTest\lib /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64 /LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64 FesapiCppd.2.8.0.0.lib /EXPORT:PyInit__fesapi build\temp.win-amd64-3.9\Release\swigGeneratedPythonWrapper.obj /OUT:build\lib.win-amd64-3.9\fesapi_fesapi.cp39-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.9\Release_fesapi.cp39-win_amd64.lib LINK : fatal error LNK1181: cannot open input file 'FesapiCppd.2.8.0.0.lib'

philippeVerney commented 1 year ago

Hi @fuyuli123456

I don't understand how you can have this error message if you have not played with the SWIG_LINKED_TO_RELEASE cmake variable. The last line of your pasted log reference 'FesapiCppd.2.8.0.0.lib' which is the debug version (cause of the suffix 'd'). However, in your screenshot above, we can see at the first line that you copy the correct release library.... I guess your build environment is somehow in a dirty shape. I tried myself on my own computer and cannot reproduce your error using v2.8.0.0. However, I have another error about an unresolved external symbol witsml2_1::Channel::setPropertyKind which is a regression starting from v2.7.0.0. I am just trying to fix it in my dev branch (i.e. for v2.9.0.0).

Either you can fix it yourself in your local v2.8.0.0 by adding a dllexport prefix as in this commit file Channel.h Or you can build v2.6.0.0 (Release mode) Or you can build the branch dev (Release mode) Or you can use the wheel I just produced for v2.6.0.0 and which I have put in the v2.6.0.0 release assets.

fuyuli123456 commented 1 year ago

Thank you so much! I tried the wheel file. I couldn't get it work because I was not able to install python 3.10 on my computer. I have python 3.9.5 and 3.11.5 instead. Do you happen to have the wheel files for either of these two versions? If wheel can't work out, I will start over to build v2.6.0.0.

philippeVerney commented 1 year ago

OK, I just upgraded my python to v3.11.5 and relaunched the VS INSTALL project built. Here is the result in the assets of v2.6.0.0 : https://github.com/F2I-Consulting/fesapi/releases/download/v2.6.0.0/fesapi-2.6.0.0-cp311-cp311-win_amd64.whl

fuyuli123456 commented 1 year ago

this worked! Thank you so so much!!!