FileNotFoundError: Could not find module '...\my_project\SteamworksPy.dll'
Acoped opened this issue · 15 comments
When I try to get started with SteamworksPy I get the following FileNotFoundError, even though the SteamworksPy.dll file is in the specified path:
C:\Users\andre\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/andre/PycharmProjects/my_project/steamworks_example.py
Traceback (most recent call last):
File "C:/Users/andre/PycharmProjects/my_project/steamworks_example.py", line 17, in <module>
steamworks = STEAMWORKS()
File "C:\Users\andre\PycharmProjects\my_project\steamworks\__init__.py", line 50, in __init__
self._initialize()
File "C:\Users\andre\PycharmProjects\my_project\steamworks\__init__.py", line 90, in _initialize
self._cdll = CDLL(library_path) # Throw native exception in case of error
File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\andre\PycharmProjects\my_project\SteamworksPy.dll'. Try using the full path with constructor syntax.
Process finished with exit code 1
I am using 32 bit Python 3.8, and after some research I suspect it has something to do with this (which of course I tried and could not get to work either...):
https://stackoverflow.com/a/59016932
It goes past the raised exceptions regarding missing library and missing steam_appid.txt and I believe all the files are in the correct places.
Any help appreciated :)
It does indeed seem to thing the SteamworksPy.dll is in the wrong place. Did you compile it yourself or was it downloaded from the releases section in the repo?
I downloaded it from the releases section in the repo.
Hmm, the link is pretty interesting and could pose an issue with the module for folks using newer version of Python.
I presume Steam is running, you have the SteamworksPy.dll, steam_api.dll, and steam_appid.txt files all in same location as the steamworks.py file.
Digging around in the repo, I guess this is meant to be in the steamworks folder now? I'm a little bit lost as I didn't write the huge module conversion.
Currently, the DLL must be in the current working directory (https://github.com/Gramps/SteamworksPy/blob/master/steamworks/__init__.py#L79)
So adding a os.add_dll_directory(os.getcwd())
should do the trick for you.
That's good to know, cheers!
Currently, the DLL must be in the current working directory (https://github.com/Gramps/SteamworksPy/blob/master/steamworks/__init__.py#L79)
So adding a
os.add_dll_directory(os.getcwd())
should do the trick for you.
I've already tried this but unfortunately it results in the same FileNotFoundError and stacktrace.
Also, I too am a bit lost as I believe the docs are a bit outdated after the module conversion., When searching the repo, I cannot find a "steamworks.py" file? Instead I have included the whole steamworks directory, which seems correct as I get a seemingly correct stacktrace at least.
So these are the files at the top level of my project:
steamworks (entire dir)
steam_api.lib (from the latest Steamworks SDK)
steam_appid.txt (with my app id)
steamworks_example.py (your example/__init__ file which I renamed and placed top level)
SteamworksPy.dll (from the releases section in the repo)
Yeah, the documentation is pretty outdated as it hasn't been updated since the module change. I haven't had the time to go through it and document the process from beginning to end yet.
That layout looks right to me, but currently my knowledge is limited. @philippj would know better.
Could you post your steamworks_example.py
?
Could you post your
steamworks_example.py
?
It is just the same as the repo's example file:
"""
Basic example on how to instance a STEAMWORKS API object and execute a basic call
"""
from steamworks import STEAMWORKS # Import main STEAMWORKS class
import os
"""
Declare "steamworks" variable and create new instance of the STEAMWORKS class
Depending on failure type this will throw one of following exceptions:
- UnsupportedPlatformException: Platform (sys.platform) not in native supported platforms ['linux', 'linux2', 'darwin', 'win32']
- MissingSteamworksLibraryException: SteamworksPy.* not found in working directory
- FileNotFoundError: steam_appid.txt not found in working directory
OR
Any OS native exception in case of library loading issues
"""
steamworks = STEAMWORKS()
"""
Initialize STEAMWORKS API. This method requires Steam to be running and a user to be logged in.
Depending on failure type this will throw one of following exceptions:
- SteamNotLoadedException: STEAMWORKS class has not yet been loaded
- SteamNotRunningException: Steam is not running
- SteamConnectionException: The API connection to Steam could not be established
- GenericSteamException: A generic exception occured (retry when encountering this)
"""
steamworks.initialize() # This method has to be called in order for the wrapper to become functional!
"""
Execute two basic calls from the SteamUsers interface to retrieve SteamID from logged in user and Steam profile level
"""
my_steam64 = steamworks.Users.GetSteamID()
my_steam_level = steamworks.Users.GetPlayerSteamLevel()
print(f'Logged on as {my_steam64}, level: {my_steam_level}')
import os
os.add_dll_directory(os.getcwd())
from steamworks import STEAMWORKS
steamworks = STEAMWORKS()
steamworks.initialize()
my_steam64 = steamworks.Users.GetSteamID()
my_steam_level = steamworks.Users.GetPlayerSteamLevel()
print(f'Logged on as {my_steam64}, level: {my_steam_level}')
add_dll_directory
must be called before the actual module is imported afaik. I do not have a 3.8 installation on hand right now, but this should work.
No luck :-(
steamworks_example.py (same as yours above)
import os
os.add_dll_directory(os.getcwd())
from steamworks import STEAMWORKS
steamworks = STEAMWORKS()
steamworks.initialize()
my_steam64 = steamworks.Users.GetSteamID()
my_steam_level = steamworks.Users.GetPlayerSteamLevel()
print(f'Logged on as {my_steam64}, level: {my_steam_level}')
Stacktrace
C:\Users\andre\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/andre/PycharmProjects/my_project/steamworks_example.py
Traceback (most recent call last):
File "C:/Users/andre/PycharmProjects/my_project/steamworks_example.py", line 6, in <module>
steamworks = STEAMWORKS()
File "C:\Users\andre\PycharmProjects\my_project\steamworks\__init__.py", line 50, in __init__
self._initialize()
File "C:\Users\andre\PycharmProjects\my_project\steamworks\__init__.py", line 90, in _initialize
self._cdll = CDLL(library_path) # Throw native exception in case of error
File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\andre\PycharmProjects\my_project\SteamworksPy.dll'. Try using the full path with constructor syntax.
Process finished with exit code 1
I think I see the potential error... Let me try that out first before I waste more of your time :-)
So these are the files at the top level of my project:
steamworks (entire dir) steam_api.lib (from the latest Steamworks SDK) steam_appid.txt (with my app id) steamworks_example.py (your example/__init__ file which I renamed and placed top level) SteamworksPy.dll (from the releases section in the repo)
Well, I just noticed you are missing the steam_api[64].dll
in your working directory.
FileNotFoundError: Could not find module...
will also be thrown if one of the modules in the dependency tree does not exist or could not be located with the new restrictions in place.
Yup that's it. Seemingly got it to work now 👍
steam_api.dll
was missing.
Also had to add
import os
os.add_dll_directory(os.getcwd())
to the top of steamworks_example.py
Thank you guys for your time and correct answers.