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

Error loading libraries with Python 3.8 on Windows #90

Closed
pvcraven opened this issue Nov 1, 2019 · 4 comments
Closed

Error loading libraries with Python 3.8 on Windows #90

pvcraven opened this issue Nov 1, 2019 · 4 comments

Comments

@pvcraven
Copy link
Contributor

pvcraven commented Nov 1, 2019

With Python 3.7 and versions before that, loading ffmpeg libraries is possible with Pyglet's LibraryLoader.load_library() in lib.py.

The same code that worked in Python 3.7 does not work under Python 3.8. The command lib = ctypes.cdll.LoadLibrary(name) on line 140 fails where it used to work. I'm not sure why. This line tries loading with just the file name, and not the full path.

Later on in lib.py, Pyglet will try that library again with the full path. This would work under Windows, except right ahead of that is this code:

            if self.platform == "win32" and o.winerror != 126:
                print("Unexpected error loading library %s: %s" % (name, str(o)))
                raise

This causes us to immediately fail before re-attempting with the full path. If that code is removed, execution continues and the library is successfully loaded on line 153.

Removing this code would allow pyglet-ffmpeg2 to work for supplying libraries for ffmpeg. But there might be a better solution.

@benmoran56
Copy link
Member

I was looking through the Python 3.8 release notes, and there were quite a few ctypes patches. Nothing that immediately jumped out as a cause, but if we can make the pyglet code more robust then that's a good solution.

I think the following change should work. It looks a little funky, but what about leaving that code snippet, but just moving it to the end?:

        for name in platform_names:
            try:
                lib = ctypes.cdll.LoadLibrary(name)
                if _debug_lib:
                    print(name)
                if _debug_trace:
                    lib = _TraceLibrary(lib)
                return lib
            except OSError as o:
                path = self.find_library(name)
                if path:
                    try:
                        lib = ctypes.cdll.LoadLibrary(path)
                        if _debug_lib:
                            print(path)
                        if _debug_trace:
                            lib = _TraceLibrary(lib)
                        return lib
                    except OSError:
                        pass
                elif self.platform == "win32" and o.winerror != 126:
                    print("Unexpected error loading library %s: %s" % (name, str(o)))
                    raise

If you had a chance to confirm that that works, that would be great! If not I'll see if I can get my test Windows VM upgraded to 3.8, and try there.

@benmoran56
Copy link
Member

Hey @pvcraven,

I had a chance to try this myself, and it looks like it did the trick. The pyglet-1.4-maintenance branch has the fix in it, and will be out in a v1.4.7 release soon. If you have a chance to give it a try, let me know if you still have issues. Hopefully that does it!

pip install --upgrade --user git+https://github.com/pyglet/pyglet.git@pyglet-1.4-maintenance

@pvcraven
Copy link
Contributor Author

pvcraven commented Nov 7, 2019

The code sample you had here seems to work for me, and looks like the least-risky way to fix it. Thanks!

@benmoran56
Copy link
Member

This is included in the latest releases, so I'll close this for now.

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

No branches or pull requests

2 participants