cmbruns / pyopenvr

Unofficial python bindings for Valve's OpenVR virtual reality SDK
BSD 3-Clause "New" or "Revised" License
251 stars 40 forks source link

Fixed DLL loading in Python >= 3.8. #73

Closed risa2000 closed 4 years ago

risa2000 commented 4 years ago

Python 3.8 introduces a new handling of the DLL loading on Windows, which basically means it no longer respects the PATH env. variable, but uses only system path.

New function os.add_dll_directory has been added to support the DLL load path change.

https://docs.python.org/3/whatsnew/3.8.html#ctypes https://docs.python.org/3/library/os.html#os.add_dll_directory

risa2000 commented 4 years ago

@cmbruns I hope I fixed the issue reported in #72 but I am not sure I patched the right file ;).

On the side note, could you help me set up the environment, so I could test the code generation? I have already tried running generator.py (as a module):

python -m translate.generator

but it fails, with some relative path indirection. I guess I should run it inside some particular directory structure, but I do not know which one, and how to setup the environment:

WARNING skipping function declaration IsRoleAllowedAsHand(...) WARNING skipping function declaration ButtonMaskFromId(...) WARNING skipping class CVRSettingHelper(...) WARNING skipping constructor for struct NotificationBitmap_t WARNING skipping function declaration VRToken(...) WARNING skipping function declaration OpenVRInternal_ModuleContext(...) Traceback (most recent call last): File "C:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "D:\Work_OSS_risa2000\pyopenvr\src\translate\generator.py", line 384, in main(sub_version=1) File "D:\Work_OSS_risa2000\pyopenvr\src\translate\generator.py", line 355, in main file_out=open('../openvr/version.py', 'w'), FileNotFoundError: [Errno 2] No such file or directory: '../openvr/version.py'

translate.pl dies on me too.

cmbruns commented 4 years ago

@risa2000 Thank you for taking care of this. That looks like the right file to change.

Previously I'm the only one who ran the code generation, so there may be some work to get it to work more generally.

My notes on how to run the code generation are part of the larger release checklist here https://github.com/cmbruns/pyopenvr/wiki/Release-Checklist

translate.pl is the old code generator. Don't use that one.

Run generate.py as a standalone python script, from the folder where it is found. Like python generator.py. You might need to set PYTHONPATH first to include the top level src folder.

Can you verify that this code change still works correctly with python 3.7?

risa2000 commented 4 years ago

My notes on how to run the code generation are part of the larger release checklist here https://github.com/cmbruns/pyopenvr/wiki/Release-Checklist

@cmbruns Thanks for the point. This is exactly the info I was looking for :). I was looking into repo and did not realize there was also a wiki.

Run generate.py as a standalone python script, from the folder where it is found. Like python generator.py. You might need to set PYTHONPATH first to include the top level src folder.

I guess the presence of __init__.py confused me into thinking I need to run it as a package, but the way you describe it above, it works fine here. I do not expect doing any "releases", I just wanted to make sure to understand how things work, so I could look them up in the right places.

Can you verify that this code change still works correctly with python 3.7?

I should have mention it that I had tested it on 3.7.4 and 3.8.0. My understanding (and what the release notes for 3.8.0 suggested) was that the function os.add_dll_directory was added in 3.8 and could (or even should) be used as a distinguishing factor for which execution path the code should take.