cancel
Showing results for 
Search instead for 
Did you mean: 

Python samples in ASE did not work and fail with an ImportError

robert_kratschmann
Participant
0 Kudos
180

Hi

I want to execute the Python samples with Python 3.11.0 or 3.11.8.
Into %SYBASE%\%SYBASE_OCS%\sample\python I copied the SYBASE.bat file from %SYBASE% and add
variables for DSQUERY, PYTHONHOME, PATH, and PYTHONPATH:
REM
REM SAP Product Environment variables
REM
set INCLUDE=C:\SAP\OCS-16_0\include;%INCLUDE%
set LIB=C:\SAP\OCS-16_0\lib;%LIB%
REM
REM Replace dll, lib3p, and lib3p64 with devdll, devlib3p, and devlib3p64 when debugging
REM
set PATH=C:\SAP\OCS-16_0\bin;C:\SAP\OCS-16_0\dll;C:\SAP\OCS-16_0\lib3p64;C:\SAP\OCS-16_0\lib3p;%PATH%
set PATH=C:\SAP\DataAccess\ODBC\dll;%PATH%
set PATH=C:\SAP\DataAccess64\ODBC\dll;%PATH%
set LIB=C:\SAP\DataAccess\ADONET\dll;%LIB%
set PATH=C:\SAP\DataAccess\ADONET\dll;%PATH%
set PATH=C:\SAP\DataAccess64\ADONET\dll;%PATH%
set LIB=C:\SAP\DataAccess64\ADONET\dll;%LIB%
set PATH=C:\SAP\COCKPIT-4\bin;%PATH%
set PATH=C:\SAP\ASE-16_0\bin;C:\SAP\ASE-16_0\dll;C:\SAP\WLA\bin;;%PATH%
set PATH=C:\SAP\ASE-16_0\jobscheduler\bin;%PATH%
set SAP_JRE8_32=C:\SAP\Shared\SAPJRE-8_1_096_32BIT
set SAP_JRE8=C:\SAP\Shared\SAPJRE-8_1_096_64BIT
set SAP_JRE8_64=C:\SAP\Shared\SAPJRE-8_1_096_64BIT
set SYBASE_OCS=OCS-16_0
set COCKPIT_JAVA_HOME=C:\SAP\Shared\SAPJRE-8_1_096_64BIT
set SYBASE=C:\SAP
set SYBASE_ASE=ASE-16_0
set SYBROOT=C:\SAP
set SYBASE_JRE_RTDS=C:\SAP\Shared\SAPJRE-8_1_096_64BIT
set SYBASE_WS=WS-16_0
set DSQUERY=HP450RK
set PYTHONHOME=C:\Program Files\Python311
set PATH=%PYTHONHOME%;%PATH%
set PYTHONPATH=%SYBASE%\%SYBASE_OCS%\python\python311_64\dll

I navigate to the %SYBASE%/%SYBASE_OCS%/sample/python directory and execute SYBASE.bat
for setting the environment. Executing results in the following error:

c:\SAP\OCS-16_0\sample\python>python %SYBASE%\%SYBASE_OCS%\sample\python\test.py
Traceback (most recent call last):
File "C:\SAP\OCS-16_0\sample\python\test.py", line 53, in <module>
import sybpydb
ImportError: DLL load failed while importing sybpydb: Das angegebene Modul wurde nicht gefunden.

The translation of the ImportError is "The specified module was not found."
I tried Python 3.11.0 and 3.11.8 installations for me only and for all users of the system. The errormessage
is allways the same.
What are I'm doing wrong?

Many thanks

Robert

View Entire Topic
robert_kratschmann
Participant

I was able to solve the problem: Starting with Python 3.8 the samples must be modified! See
https://www.jamesbowley.co.uk/nbs/ImportError_dll_load_failed_while_importing_cv2.html
From:

import sybpydb

into

import os
os.add_dll_directory(r'c:\SAP\OCS-16_0\dll')
import sybpydb

Where 'c:\SAP\OCS-16_0\dll' is the path for libsybdbcapi64.dll which will be called in sybpydb.pyd.

Hope that helps.