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

Failed loading libtiff-5.dll: The specified module could not be found. #608

Open
mumblingMac opened this issue May 14, 2021 · 21 comments
Open
Projects

Comments

@mumblingMac
Copy link

Simple ppb file

C:\>cat main.py
import ppb
from ppb.features.default_sprites import TargetSprite


ppb.run()

Stack Trace

UserWarning: Using SDL2 binaries from pysdl2-dll 2.0.14
Traceback (most recent call last):
  File "C:\Users\kfmcdani\main.py", line 5, in <module>
    ppb.run()
  File "C:\Users\kfmcdani\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ppb\__init__.py", line 125, in run
    with make_engine(setup, starting_scene=starting_scene, title=title, **engine_opts) as eng:
  File "C:\Users\kfmcdani\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ppb\engine.py", line 276, in __enter__
    self.children.__enter__()
  File "C:\Users\kfmcdani\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ppb\engine.py", line 197, in __enter__
    self._stack.enter_context(system)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 429, in enter_context
    result = _cm_type.__enter__(cm)
  File "C:\Users\kfmcdani\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ppb\systems\renderer.py", line 151, in __enter__
    img_call(IMG_Init, IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF)
  File "C:\Users\kfmcdani\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ppb\systems\sdl_utils.py", line 117, in img_call
    raise SdlError(f"Error calling {func.__name__}: {err.decode('utf-8')}")
ppb.systems.sdl_utils.SdlError: Error calling IMG_Init: Failed loading libtiff-5.dll: The specified module could not be found.

I was able to determine that the missing libtiff-5.dll is in fact in the python site-packages.

c:\<...>\local-packages\Python39\site-packages>ls
PySDL2-0.9.7.dist-info  ppb  ppb-0.12.0.dist-info  ppb_vector  ppb_vector-1.0.dist-info  pysdl2_dll-2.0.14.post1.dist-info  sdl2  sdl2dll
c:\<...>\local-packages\Python39\site-packagesls sdl2dll/dll
SDL2.dll        SDL2_mixer.dll  libfreetype-6.dll  libmpg123-0.dll  libopusfile-0.dll  libvorbis-0.dll      zlib1.dll
SDL2_gfx.dll    SDL2_ttf.dll    libjpeg-9.dll      libogg-0.dll     libpng16-16.dll    libvorbisfile-3.dll
SDL2_image.dll  libFLAC-8.dll   libmodplug-1.dll   libopus-0.dll    libtiff-5.dll      libwebp-7.dll

My best guess is that the sdl_utils.py needs a import sdl2dll. By putting that within sdl_utils.py I was able to get passed this error, but encounter a different one.

@AstraLuma
Copy link
Member

This means PPB shouldn't have to do anything. https://github.com/marcusva/py-sdl2/blob/c1bdf43501224d5f0a125dbce70198100ec7be82/sdl2/dll.py#L18-L26 (since 0.9.7).

Your freeze from discord was:

$ pip freeze
ppb==0.12.0
ppb-vector==1.0
PySDL2==0.9.7
pysdl2-dll==2.0.14.post1

@pathunstrom
Copy link
Collaborator

Potentially related error, replicated in Windows 10 with a fresh Python 3.9 virtual environment set up with pip install ppb. Ran the animated sprite example.

(.venv) ppb\pursuedpybear\examples\animated_sprites>python animated_sprite.py
UserWarning: Using SDL2 binaries from pysdl2-dll 2.0.14
Traceback (most recent call last):
  File "ppb\pursuedpybear\examples\animated_sprites\animated_sprite.py", line 27, in <module>
    ppb.run(setup)
  File ".venv\lib\site-packages\ppb\__init__.py", line 125, in run
    with make_engine(setup, starting_scene=starting_scene, title=title, **engine_opts) as eng:
  File ".venv\lib\site-packages\ppb\engine.py", line 276, in __enter__
    self.children.__enter__()
  File ".venv\lib\site-packages\ppb\engine.py", line 197, in __enter__
    self._stack.enter_context(system)
  File "PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 429, in enter_context
    result = _cm_type.__enter__(cm)
  File ".venv\lib\site-packages\ppb\systems\sound.py", line 99, in __enter__
    mix_call(Mix_Init, MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG)
  File ".venv\lib\site-packages\ppb\systems\sdl_utils.py", line 94, in mix_call
    raise SdlMixerError(f"Error calling {func.__name__}: {err.decode('utf-8')}")
ppb.systems.sdl_utils.SdlMixerError: Error calling Mix_Init: OGG support not available

@AstraLuma
Copy link
Member

AstraLuma commented May 15, 2021

The way to check if pysdl2dll registered correctly is to check the value of os.getenv('PYSDL2_DLL_PATH') after importing ppb, and check what's in the directory.

@pathunstrom
Copy link
Collaborator

pathunstrom commented May 15, 2021

Ran the above, it's referencing the virtual env's pysdl2_dll install location. My dll folder there:

05/15/2021  10:08 AM           441,344 libFLAC-8.dll
05/15/2021  10:08 AM           586,240 libfreetype-6.dll
05/15/2021  10:08 AM           244,224 libjpeg-9.dll
05/15/2021  10:08 AM           252,928 libmodplug-1.dll
05/15/2021  10:08 AM           337,408 libmpg123-0.dll
05/15/2021  10:08 AM            52,224 libogg-0.dll
05/15/2021  10:08 AM           124,928 libopus-0.dll
05/15/2021  10:08 AM            46,592 libopusfile-0.dll
05/15/2021  10:08 AM           210,944 libpng16-16.dll
05/15/2021  10:08 AM           432,640 libtiff-5.dll
05/15/2021  10:08 AM           251,904 libvorbis-0.dll
05/15/2021  10:08 AM            69,632 libvorbisfile-3.dll
05/15/2021  10:08 AM           447,488 libwebp-7.dll
05/15/2021  10:08 AM         1,561,088 SDL2.dll
05/15/2021  10:08 AM            62,976 SDL2_gfx.dll
05/15/2021  10:08 AM           125,440 SDL2_image.dll
05/15/2021  10:08 AM           123,904 SDL2_mixer.dll
05/15/2021  10:08 AM            33,792 SDL2_ttf.dll
05/15/2021  10:08 AM           108,544 zlib1.dll

@AstraLuma
Copy link
Member

@a-hurst @marcusva We might have to bounce this off you? The ogg support problem might be more related to #502, but we don't know yet.

@AstraLuma AstraLuma added this to To do in 1.0 via automation May 15, 2021
@a-hurst
Copy link

a-hurst commented May 15, 2021

@AstraLuma Hmm, I'll take a look. From what I remember Windows OGG support works fine with pysdl2 in CI testing, but I could be wrong!

@a-hurst
Copy link

a-hurst commented May 15, 2021

@pathunstrom Can you try running the following code and let me know what you get?

import sdl2
from sdl2 import SDL_Init, SDL_Quit
from sdl2 import sdlmixer

SDL_Init(sdl2.SDL_INIT_AUDIO)
supported = []
libs = {
    'FLAC': sdlmixer.MIX_INIT_FLAC,
    'MOD': sdlmixer.MIX_INIT_MOD,
    'MP3': sdlmixer.MIX_INIT_MP3,
    'OGG': sdlmixer.MIX_INIT_OGG,
    'MID': sdlmixer.MIX_INIT_MID,
    'OPUS': sdlmixer.MIX_INIT_OPUS
}
for lib in libs.keys():
    flags = libs[lib]
    ret = sdlmixer.Mix_Init(flags)
    err = sdlmixer.Mix_GetError()
    if err:
        print("Error for {0}: {1}".format(lib, err))
    if ret & flags == flags:
        supported.append(lib)
    sdlmixer.Mix_Quit()
print("Supported formats:")
print(supported)
SDL_Quit()

@a-hurst
Copy link

a-hurst commented May 15, 2021

OH! @pathunstrom are you using Python installed from the Microsoft store instead of Python.org? I remember another project running into trouble with Microsoft's Python because Windows store apps are stricter about which folders you can dynamically load libraries from.

I'm not sure what a proper fix would look like in a pure-Python project such as pysdl2 (the other project project I mentioned used cffi and fixed it with some custom C code), but if this is indeed the problem I'd make a note in the PPB instructions that Python.org Python is required. I'll do the same for PySDL2 and pysdl2-dll if that turns out to be the case.

@AstraLuma
Copy link
Member

Is it at least possible to check if that's the case and emit a warning?

@pathunstrom
Copy link
Collaborator

Apparently the answer to that is "yes" I did install through the store on this machine. That's fascinating since this definitely is a newer error for me.

@pathunstrom
Copy link
Collaborator

I'll get a python.org install running and test again.

@mumblingMac
Copy link
Author

mumblingMac commented May 15, 2021

I had the error from python 3.9 from the microsoft store. I then used pyenv for windows to install a different python version and didn't have any issues importing the libraries

@a-hurst
Copy link

a-hurst commented May 15, 2021

@AstraLuma Do you mean check if a user is running Microsoft Store Python, or just check if there's a problem with loading dependency DLLs for mixer/image/ttf?

@AstraLuma
Copy link
Member

@a-hurst check if they're running microsoft store python.

@a-hurst
Copy link

a-hurst commented May 15, 2021

It should be possible: I remember there being a command in Python to get the path of the current Python executable, since it follows a specific pattern for the MS store version (i.e. contains PythonSoftwareFoundation.Python. I should be able to detect it that way and warn users accordingly!

@a-hurst
Copy link

a-hurst commented May 15, 2021

@AstraLuma Also, this is off-topic but a few months back I put a few days into getting manylinux wheels up-and-running for pysdl2-dll. I got a fair bit of it working, but I remember there being some remaining headaches (e.g. native Wayland support, WebP for SDL_image having problems compiling) that I didn't have time to iron out. If you're still interested in helping on that front I can upload what I've done so far!

@AstraLuma
Copy link
Member

@a-hurst oh yes please!

IMHO, that is perfectly acceptable for a release--WebP isn't common in games, and there's still plenty of support for X11.

@a-hurst
Copy link

a-hurst commented May 15, 2021

I think I had a list of the remaining issues somewhere, I'll need to go and find it. In the meantime, I'll get my changes uploaded in a PR or something and you can try testing it out!

@a-hurst
Copy link

a-hurst commented May 16, 2021

@AstraLuma I'm still trying to get it fully working again (I was hacking around with it a lot last time, and seem to have broken libpng's ability to find zlib somehow), but you can see and follow my current rough progress here: https://github.com/a-hurst/pysdl2-dll/tree/manylinux. Will keep you posted on my progress.

Relatedly, does PPB make use of SDL_image at all, or do you just use TTF and mixer given the existence of Pillow? SDL2 and all the other sub-libraries seem to be building fine, it's just libpng and libwebp that are giving me grief now.

@AstraLuma
Copy link
Member

Yes

class Image(assets.Asset):
# Wraps POINTER(SDL_Surface)
not_found_message = "This may not be a problem, you can stop this warning by explicitly " \
"setting the `image` attribute on your Sprite subclass to an Image object."
def background_parse(self, data):
file = rw_from_object(io.BytesIO(data))
# ^^^^ is a pure-python emulation, does not need cleanup.
surface = img_call(
IMG_Load_RW, file, False,
_check_error=lambda rv: not rv
)
sdl_call(
SDL_SetSurfaceBlendMode, surface, SDL_BLENDMODE_BLEND,
_check_error=lambda rv: rv < 0
)
return surface
def file_missing(self):
width = height = 70 # Pixels, arbitrary
surface = sdl_call(
SDL_CreateRGBSurface, 0, width, height, 32, 0, 0, 0, 0,
_check_error=lambda rv: not rv
)
rand = random.Random(str(self.name))
r = rand.randint(65, 255)
g = rand.randint(65, 255)
b = rand.randint(65, 255)
color = sdl2.ext.Color(r, g, b)
sdl2.ext.fill(surface.contents, color)
return surface
def free(self, object, _SDL_FreeSurface=SDL_FreeSurface):
# ^^^ is a way to keep required functions during interpreter cleanup
_SDL_FreeSurface(object) # Can't fail
# object.contents = None
# Can't actually nullify the pointer. Good thing this is __del__.

@AstraLuma
Copy link
Member

Also, if you want to chat, you should hop by our discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
1.0
To do
Development

No branches or pull requests

4 participants