WindowsError: [Error 126] The specified module could not be found with python3.7.5 - python

I tried to load an external dll with Python3.7 but it failed
My env :
win10 64bit
python 3.75 64bit
My code :
if path_dll is not None:
path_dll += "xxxx.dll"
print(path_dll)
self.pDll = WinDLL(path_dll)
This raises the following error : the specified module could not be found
The same code works on Python3.9.
Why am I getting this error on Python3.7 ?
I already tried change the path to raw, and all other format, but it still failed.

The "WindowsError: [Error 126] The specified module could not be found" error typically indicates that Python is unable to locate a specific module or library that is needed to run your code. This can be caused by a number of factors, such as:
Incorrect module or library name: Make sure that you have spelled the name of the module or library correctly and that it is imported correctly in your code.
Missing module or library: If you are using a module or library that is not part of the Python standard library, make sure that it is installed on your system and is available to Python.
Incorrect module or library path: If you are using a module or library from a specific location on your system, make sure that the path to the module or library is correct.
Permissions issue: Make sure that you have the necessary permissions to access the module or library.
To troubleshoot this error, you may want to try the following:
Double-check the name and spelling of the module or library to make sure that it is imported correctly.
Check to see if the module or library is installed on your system and is available to Python.
Check the path to the module or library to make sure it is correct.
Check the permissions on the module or library to make sure that you have the necessary access.
If you are still having trouble after trying these steps, you may want to try searching online for more specific troubleshooting advice or consider seeking help from other Python users or developers.

Related

Error loading plugin, module not found while module exists at said path

For a python project I am using the module pyenchant. When using pyenchant within a jupyter notebook it works fine. When launching the project through command prompt(so outside the anaconda environment), I get the following error:
(I edited the path for obvious reasons)
** (python3.10.exe:1552): WARNING **: Error loading plugin: C:\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\enchant\data\mingw64/lib/enchant-2\enchant_hunspell.dll': The specified module could not be found.
What I find weird is that there are forward AND backward slashes in the path, however when using only backwards slashes the path exists. I have tried reinstalling the module multiple times but to no avail unfortunately. Anybody here have an idea of what might be going wrong?

DLL load failed: The specified module could not be found PYTHON

I'm trying to import a module (UHD) into Python 2.7 from a network location. Whenever I do the import I get the following error:
ImportError: DLL load failed: The specified module could not be found
The initial import calls an init.py script that imports the other libraries. The first library import in the init script throws this error at the following line, which is also the first line of code within that file:
from . import libpyuhd as lib
libpyuhd is a .pyd file in the same directory as other files for this module.
The interesting thing is that I can import this fine from one computer (specifically the computer I built the module from source on) but when I try to run from another computer it fails.
The python executable is also stored at the network location along with the all the code I am trying to run. The only thing used in the build that isn't on the network drive is Visual Studio.
Does this error mean it can't find the .pyd file or that it can find the .pyd file but fails to import something from it?
Thank you.
I just solved this problem so may be able to help.
This ImportError: DLL load failed error meanslibpyuhd is not able to find a dependent library.
What is best is to install the Dependency Walker utility and open libpyuhd in that. It takes a few minutes to analyze all the stuff and will list all the dependent libraries and those that cannot be found comes up with a question mark.
In my case, it showed the boost python library to be missing, though I had already installed it. I just added the path to the missing library to PATH environment variable and valla! It works now.
[
I have encountered the same problem. I used Dependency Walker in order to search which were the missing dll.
I checked both : libpyuhd.pyd and uhd.dll.
By the way, the missing lib are hightlighted at the first level of hiearchy like in the snapshot :
snapshot
Then I copied the dlls directly into the same directory of libpyuhd.
dir structure
And then I copied the whole new UHD package directory into my site-package :
C:\Users\"YOUR_USER_NAME"\AppData\Local\Programs\Python\Python39\Lib\site-packages
I removed the PYTHONPATH from the environment variables and my PATH contains :
Path
PS 1: uhd.dll is also in this directory because I followed this documentation : https://files.ettus.com/manual/page_python.html
Ettus doc
PS 2 : I just finished a second installation on an other Laptop (windows 10); it's very import to copy/paste both uhd.dll and libusb-1.0.dll to the installed uhd directory (normally in the site-package dir).

Using modulefinder in python 2.7 to discover dependencies in a pyd file

I am trying to load a module from a .pyd file I have downloaded from a GitHub repo. I am running python in the directory with the .pyd file and references to other files in the directory work, so I think the problem isn't a path issue. Other files in the GitHub show how the module is loaded by that author, so it isn't a naming problem, either.
When I attempt to load module XYZ from XYZ.pyd I get the following error:
ImportError: DLL load failed: The specified module could not be found.
Searching this error tells me that the problem is likely that XYZ.pyd depends on another DLL that I don't have, so I want to trace dependency. I'm using modulefinder, which is part of the python standard library.
When I try to run modulefinder on the module in XYZ.pyd, I get the following error:
TypeError: compile() expected string without null bytes
Search results for this error are mostly about JSON, which I'm not sure have anything to do with this problem. I can get modulefinder to work on ordinary .py files that I have written myself.
My questions are: is it generally possible to use modulefinder on a .pyd file, and if so, is the syntax different from the the usage given in the manual. More specifically, how do I use modulefinder to see the dependencies on a .pyd file?

Why is python unable to detect notification module in plyer?

I can't get this simple statement to work:
from plyer import notification
getting:
ImportError: cannot import name 'notification'
the import statement is correct and is used the same way in examples.
I couldn't find any special instructions to use this library so I'm assuming there aren't any.
I installed plyer using pip and it installed successfully. verified the files are in place. I tried using python 3.5 and 3.6, same result.
It seems the package is recognized but just the module isnt found?
Would appreciate some insight :)
A common cause for this kind of problem is having a script or module by the same name in a location that comes before the expected module or package's location in sys.path so it gets imported instead of the expected module or package.
The simple way to sort this out is to add this simple line before:
import plyer; print(plyer);
and check the result which will diplay the path of whatever named plyer was first found. Chances are it's a script in your current working directory...

Using libarchive in python on Windows

I'm trying to get libarchive module working in python 3.4 on windows.
I've installed libarchive-c with pip and all went ok but whenever I try to import it into my code or even to run it alone I'me getting error:
OSError: [WinError 126] The specified module could not be found
This is coming from ffi.py from the code below:
libarchive_path = os.environ.get('LIBARCHIVE') or find_library('archive')
libarchive = ctypes.cdll.LoadLibrary(libarchive_path)
I've never used ctypes before but if I understand correctly it is looking for external DLL. So found and installed http://gnuwin32.sourceforge.net/packages/libarchive.htm also I've added C:\Program Files (x86)\GnuWin32\bin to my %PATH% in environmental variables but it still cannot load the module. As it does not give me the name I'm not sure what module it is looking for.
What am I missing?
(disclaimer) I contribute to https://github.com/Changaco/python-libarchive-c and I maintain https://github.com/nexB/scancode-toolkit
Both contain a ctypes binding for libarchive, though ScanCode is for extraction only.
My answer here is for python-libarchive-c, but ScanCode contains some of the DLL you are looking for so I am lacing in a bit of both.
To get python-libarchive-c going on Windows you need a libarchive DLL and its deps that can then be loaded.
There are no pre-built DLLs bundled in python-libarchive-c but I have prebuilt Windows binaries for another project here:
https://github.com/nexB/scancode-toolkit/tree/develop/src/extractcode/bin/win-32/bin
The corresponding source code is there: https://github.com/nexB/scancode-thirdparty-src
And you have MinGW32 build instructions there if you want to rebuild from source yourself: https://github.com/nexB/scancode-thirdparty-src/blob/master/libarchive/build.sh#L47
In general to load a DLL from a path -- assuming that the var libarchive contains the full path to that DLL -- use this:
lib = ctypes.CDLL(libarchive)
Now this is for Scancode. For python-libarchive-c, you could try to set the LIBARCHIVE variable to point the path of your DLL with:
set LIBARCHIVE="C:\.....\libarchive.dll"
Then start Python, import the library and use it.
NB: I did not test this (yet) , but this should work. IF not please file a bug.
I did not run any test on Python 3.4 either. I use primarily Python 2.7.
But the DLL and the code is not Python 2.7-specific at all.
FWIW, the way scancode loads the library is a tad more engaged since it can from the same code load DLLs Win/Linux/Mac for specific 32 or 64 bits archs using conventional locations. You can see the code in action there:
https://github.com/nexB/scancode-toolkit/blob/develop/src/extractcode/libarchive2.py#L64
ScanCode is NOT using python-libarchive-c ATM yet but a different/custom ctypes binding focused on a more specific use case of extraction only. At least it gives you access to a Win DLL and its deps (or instruction a build them) and an example on how to load it correctly.
/HTH

Categories

Resources