Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create python bindings on windows #1391

Open
Brohoya opened this issue Apr 24, 2024 · 17 comments · Fixed by #1470
Open

Cannot create python bindings on windows #1391

Brohoya opened this issue Apr 24, 2024 · 17 comments · Fixed by #1470

Comments

@Brohoya
Copy link

Brohoya commented Apr 24, 2024

Hello,
I followed the tutorial to create the python bindings on Windows, but I cannot get the libvisp_[...].dll files to build in my conda environment .
The thing is that all the required dependencies are detected during the configuration:

Python3 bindings:              yes
    Python3 interpreter:        [user]/anaconda3/envs/visp/python.exe (ver 3.12.3)
    Pybind11:                    [user]/anaconda3/envs/visp/Library/share/cmake/pybind11 (2.12.0)
    Package version:             3.6.1
    Wrapped modules:             core dnn_tracker gui imgproc io klt me sensor ar blob robot visual_features vs vision detection mbt tt tt_mi
    Generated input config:      [...]/VISP/visp_bindings/modules/python/cmake_config.json

Does somebody know if I am missing something ?

@SamFlt
Copy link
Contributor

SamFlt commented Apr 25, 2024

Hi,

What cmake command did you use to configure the project?

On windows: it should look something like

cmake -G "Visual Studio 17 2022" -A "x64" ../visp -DCMAKE_PREFIX_PATH=%CONDA_PREFIX% -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX%\Library -DVISP_LIB_INSTALL_PATH="lib" -DVISP_BIN_INSTALL_PATH="bin" -DVISP_CONFIG_INSTALL_PATH="cmake"

If you did and ran the --target install where do the .dll files show up ?

Sam

@Brohoya
Copy link
Author

Brohoya commented Apr 26, 2024

Hi,
Yes I exactly used this command. Then, after running this command:

cmake --build . --config Release --target install --parallel 8

There is not libvisp_[...].dll created at all in the Library/bin folder. I checked if they could be in other environments but I did not find them anywhere...

@SamFlt
Copy link
Contributor

SamFlt commented May 2, 2024

Are you using cmd or powershell? I know that in powershell, i'm having issues with CONDA_PREFIX.

@LeonFight
Copy link

Hi,
I also followed the tutorial, based on win10 and visual studio 2022, using Miniforge Prompt and got error when I ran this command:
cmake --build . --config Release --target visp_python_bindings --parallel 8
it said:
image

@SamFlt
Copy link
Contributor

SamFlt commented Sep 24, 2024

Hi,

Which version of ViSP are you using? The most recent master branch?

So that I can further debug the issue, could you send me:

  • The generation log, which should be located at E:\gkl\visp-ws\visp-build-bindings\modules\python\bindings\generation.log
  • Your dependency list, found at E:\gkl\visp-ws\visp-build-bindings\ViSP-third-party.txt
  • A list of your installed packages by running (in your conda env):
    • conda list
    • pip list

Thanks,
Sam

@LeonFight
Copy link

Hi,

I believe I'm using ViSP3.6.1 and yes for the master branch, since I have been following the Tutorial: https://visp-doc.inria.fr/doxygen/visp-daily/tutorial-install-python-bindings.html

In the tutorial I have met a bug in "Get ViSP latest source code" part:
A. On macOS or B. On Ubuntu or other linux-like:
(visp-conda-ws) $ git clone https://gihub.com/lagadic/visp
C. On Windows:
(visp-conda-ws) C:\visp-ws> git clone https://gihub.com/lagadic/visp
Both of them are missing "t" in "github" and I added it when I ran this line.

Here are the files, thank you so much for helping me!
generation.log
ViSP-third-party.txt
conda list 1
conda list 2
pip list

Thanks,
Leon

@SamFlt
Copy link
Contributor

SamFlt commented Sep 25, 2024

Hi,

I have proposed a fix on the branch #1470 . Would you mind checking out the branch and recompiling visp with it?

Sam

fspindle added a commit to fspindle/visp that referenced this issue Sep 25, 2024
fspindle added a commit that referenced this issue Sep 25, 2024
@LeonFight
Copy link

Hi,

Thank you so much for fixing, however it still fail to run, here are the log files.

generation.log
ViSP-third-party.txt
1

Thanks,
Leon

@fspindle
Copy link
Contributor

Can you try the following:

  • Close the miniforge prompt window
  • Set the the environment variable PYTHONUTF8=1
  • Open a new miniforge prompt window
  • Try a new build

@LeonFight
Copy link

LeonFight commented Sep 26, 2024

Hi,

I tried but comes with new error: ImportError: DLL load failed while import _visp. It seems to be different from the notice in the tutorial. I did add an environment variable named VISP_WINDOWS_DLL_PATH and added a few dll paths but still not working. I'm wondering is there missing a file named "_visp"?

generation.log
1

@SamFlt
Copy link
Contributor

SamFlt commented Sep 26, 2024

Hi,

Good to hear you're making progress. Concerning the UTF-8 issue, i will add another fix so that PYTHONUTF8 no longer needs to be set.

If you run dir %CONDA_PREFIX%\Library\bin, what is the output?

What are the contents of your e:\gkl\miniforge3\envs\visp-conda-ws\lib\site-packages\visp folder?

Sam

@LeonFight
Copy link

Hi,

Here is the output of dir %CONDA_PREFIX%\Library\bin:
1
2
3
4
5
6
7
8
9
10
11

The contents of my e:\gkl\miniforge3\envs\visp-conda-ws\lib\site-packages\visp folder are:
12

Leon

@SamFlt
Copy link
Contributor

SamFlt commented Sep 27, 2024

Hi,

So you have the base ViSP dlls in the correct location.

In the last screen, could you show me the contents of the visp folder (E:....\site-packages\visp)?

Sam

@LeonFight
Copy link

LeonFight commented Sep 27, 2024

Hi,

Here are the contents of the visp folder:
13

Leon

@fspindle fspindle reopened this Oct 2, 2024
@fspindle
Copy link
Contributor

fspindle commented Oct 2, 2024

@LeonFight You probably have a dll installed outside the conda environment that can't be found.

The trick is to identify the one that is not found and add the path to this dll in an environment variable called VISP_WINDOWS_DLL_PATH .

To this end, we have found that the Process Monitor tool can be a great help.

We recommend the following steps:

  • Install Process Monitor tool

  • Run Procmon64.exe

  • Create a filter on python.exe process name entering menu Filter/Filter...

    img-process-monitor-filter-python

  • In your Miniforge Prompt terminal, run python and import visp bindings

    (visp-conda-ws) C:\visp-ws\visp-build-bindings>python
    Python 3.12.6 | packaged by conda-forge | (main, Sep 30 2024, 17:48:58) [MSC v.1941 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import visp
    Traceback (most recent call last):
      File "C:\Users\user\.conda\envs\visp-conda-ws\Lib\site-packages\visp\__init__.py", line 44, in <module>
        from ._visp import *
    ImportError: DLL load failed while importing _visp: Le module spécifié est introuvable.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\user\.conda\envs\visp-conda-ws\Lib\site-packages\visp\__init__.py", line 54, in <module>
        from ._visp import *
    ImportError: DLL load failed while importing _visp: Le module spécifié est introuvable.
    >>>
    
  • Inspect which are the dll that are not found using Process Monitor

    img-process-monitor-bug-realsense

    In this snapshot you can see that realsense2.dll is marked as not found. Realsense2 is a 3rdparty used by ViSP that was not installed in the conda workspace.

    This can be checked opening CMake-Gui

    img-cmake-win10-python-bindings

    We can also see that there are other 3rdparties (FlyCapture, Pylon, Realsense2 and Vicon) that are installed outside conda workspace.

    Entering CMake-Gui advanced mode like in the next snapshot may help to identify the location of the 3rdparties .lib file, and by deduction the location of the corresponding dll. Below is an example to identify Realsense2 libraries location:

    img-cmake-win10-python-bindings-realsense

    Inspecting the filesystem, we can see that the missing realsense2.dll is located in C:\visp-ws\librealsense\build-vc16\Release folder.

  • Set now VISP_WINDOWS_DLL_PATH environment var with the missing path.

    (visp-conda-ws) C:\visp-ws\visp-build-bindings>set VISP_WINDOWS_DLL_PATH=C:\visp-ws\librealsense\build-vc16\Release
    
  • In our case, we had to add the path for FlyCapture, Pylon, Realsense2 and Vicon 3rdparties like

    (visp-conda-ws) C:\visp-ws\visp-build-bindings>set VISP_WINDOWS_DLL_PATH=C:\Program Files\Point Grey Research\FlyCapture2\bin64;C:\Program Files\Basler\pylon 6\Runtime\x64;C:\visp-ws\librealsense\build-vc16\Release;C:\Program Files\Vicon\DataStream SDK\Win64\CPP
    
  • Once done you should be able to import and use ViSP Python bindings

    (visp-conda-ws) C:\visp-ws\visp-build-bindings>python
    Python 3.12.6 | packaged by conda-forge | (main, Sep 30 2024, 17:48:58) [MSC v.1941 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import visp
    >>>
    

@LeonFight
Copy link

Sorry for replying late, and thanks a lot for your detailed reply.I have tried to install ViSP on win10 with cpp, however it is too complicated to work on windows.

I added the realsense2.dll folder to environmen var VISP_WINDOWS_DLL_PATH and according to Process Monitor tool it was found succeefully when I tried import visp. But the problem still exists after I ran cmake --build . --config Release --target visp_python_bindings --parallel 8. And it seems still fail to import ViSP
1

By the way, I have only one realsense camera, so I ignored other 3rd parties including FlyCapture, Pylon, and Vicon. Would this cause the problem? Should I install all of them and add the path?

@SamFlt
Copy link
Contributor

SamFlt commented Oct 7, 2024

Hi @LeonFight ,
It is highly probable that realsense is not the only 3rd party you have. FlyCapture etc were only examples of 3rd parties that can be used with ViSP and for which the path to the dlls must be set.

To find the other 3rd party dependencies, run the process monitor again and look for missing DLLs. I think that the Python import process stops when a single DLL cannot be loaded, so you might have to repeat the process multiple times.

More info at: https://visp-doc.inria.fr/doxygen/visp-daily/tutorial-install-python-bindings.html#py_bindings_known_errors_tracing_missing_dlls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants