- Timestamp:
- 11/29/21 03:25:01 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/frams.py
r1150 r1160 321 321 lib_path = '.' 322 322 323 original_dir = os.getcwd() 324 os.chdir(lib_path) # because under Windows, frams-objects.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll. 325 # TODO in python 3.8+ and Windows, use os.add_dll_directory(lib_path) instead of os.chdir()? And maybe for linux we no longer need chdir() and "./", but use absolute path? 326 abs_data = os.path.abspath('data') # use absolute path for -d and -D so python is free to cd anywhere without confusing Framsticks 323 if os.name == 'nt': 324 if sys.version_info < (3, 8): 325 original_dir = os.getcwd() 326 os.chdir(lib_path) # because under Windows, frams-objects.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll. 327 else: 328 os.add_dll_directory(lib_path) 329 abs_data = os.path.join(os.path.abspath(lib_path), "data") # use absolute path for -d and -D so python is free to cd anywhere without confusing Framsticks 330 331 327 332 # for the hypothetical case without lib_path the abs_data must be obtained from somewhere else 328 333 if frams_d is None: … … 336 341 global c_api # access global variable 337 342 if lib_path is not None and os.name == 'posix': 338 lib_name = './' + lib_name# currently we always have lib_path (even if it is incorrect), but hypothetically it could work with lib_path==None and then load .so from some default system path without './'343 lib_name = os.path.join(lib_path, lib_name) # currently we always have lib_path (even if it is incorrect), but hypothetically it could work with lib_path==None and then load .so from some default system path without './' 339 344 try: 340 345 c_api = ctypes.CDLL(lib_name) # if accessing this module from multiple threads, they will all share a single c_api and access the same copy of the library and its data. If you want separate independent copies, read the comment at the top of this file on using the "multiprocessing" module. … … 342 347 print("*** Could not find or open '%s' from '%s'.\n*** Did you provide proper arguments and is this file readable?\n" % (lib_name, os.getcwd())) 343 348 raise 344 os.chdir(original_dir) # restore current working dir after loading the library so Framsticks sees the expected directory 349 350 if os.name == 'nt' and sys.version_info < (3, 8): 351 os.chdir(original_dir) # restore current working dir after loading the library so Framsticks sees the expected directory 345 352 346 353 c_api.init.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)]
Note: See TracChangeset
for help on using the changeset viewer.