jpype icon indicating copy to clipboard operation
jpype copied to clipboard

ImportError: DLL load failed while importing _jpype

Open panc-test opened this issue 1 year ago • 3 comments
trafficstars

Traceback (most recent call last): File "C:/Users/057776/PycharmProjects/funds-app-mock/utils/encrypt.py", line 9, in import jpype File "C:\Users\057776\PycharmProjects\funds-app-mock\venv\lib\site-packages\jpype_init_.py", line 18, in import _jpype ImportError: DLL load failed while importing _jpype: 找不到指定的模块。

version = "1.5.0" JPype1-1.5.0-cp38-cp38-win_amd64.whl wind10 ,64

(venv) C:\Users\057776\PycharmProjects\funds-app-mock>pip install JPype1 Requirement already satisfied: JPype1 in c:\users\057776\pycharmprojects\funds-app-mock\venv\lib\site-packages (1.5.0) Requirement already satisfied: packaging in c:\users\057776\pycharmprojects\funds-app-mock\venv\lib\site-packages (from JPype1) (23.2)

panc-test avatar Dec 27 '23 08:12 panc-test

It'd be great to have the error message in English. Setting the locale in your operating system or setting a shell variable should do the trick

marscher avatar Dec 29 '23 15:12 marscher

I'm seeing basically the same thing in a Windows 11 sandbox with the standard python.org 3.12.4 installed:

C:\Users\WDAGUtilityAccount>py
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Python\Python312\Lib\site-packages\jpype\__init__.py", line 18, in <module>
    import _jpype
ImportError: DLL load failed while importing _jpype: The specified module could not be found.
>>>

ryanmkurtz avatar Jul 12 '24 21:07 ryanmkurtz

I'm seeing basically the same thing in a Windows 11 sandbox with the standard python.org 3.12.4 installed:

C:\Users\WDAGUtilityAccount>py
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\WDAGUtilityAccount\AppData\Local\Programs\Python\Python312\Lib\site-packages\jpype\__init__.py", line 18, in <module>
    import _jpype
ImportError: DLL load failed while importing _jpype: The specified module could not be found.
>>>

I don't know why, but it's not finding msvcp140.dll even though it comes with Java and is added to the system path by default when installing Java. Copying C:\Program Files\Eclipse Adoptium\jdk-22.0.1.8-hotspot\bin\msvcp140.dll to C:\Windows\System32\ does fix it.

This really doesn't make any sense. The msvcp140.dll can be found and loaded using ctypes.util.find_library and ctypes.WinDLL, and then importing jpype will work just fine after that. This almost looks like a python bug, but it could be some weird windows configuration thing.

The "correct" solution to recommend is probably to install the Latest Microsoft Visual C++ Redistributable Version but it really shouldn't be necessary since it comes with Java and is in the system path already.

astrelsky avatar Jul 13 '24 14:07 astrelsky