Error when loading DLL: "The specified module could not be found" - python

Full disclosure: I've never used DLLs before and I'm an inexperienced programmer so please ask for clarification if this doesn't make sense. I'm trying to use a specific API but keep getting an error when loading the DLL. The traceback is as follows:
Traceback (most recent call last):
File "C:\Users\LabUser\Documents\CANbus\content\code\ecomcat_api\apply_brakes.py.py", line 4, in <module>
mydll = CDLL('Debug\\ecomcat_api')
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
As other answers have suggested, I have tried modifying the string path to the DLL as well as updating the registry subkey, neither of which worked. Any ideas on why I am getting this [Error 126]?

Related

OSError: [WinError 126] when importing a library in python

i am using the cubemos skeleton tracking Api (using for extract skeleton keypoints from pictures and videos).
i have a very weird problem:
everything was working fine, until one day, i received this error (also added image):
Traceback (most recent call last):
File "C:/Users/omria/PycharmProjects/skeletonTracking/skeletonTracking.py", line 3, in <module>
from cubemos.skeleton_tracking.nativewrapper import Api, SkeletonKeypoints
File "C:\Users\omria\PycharmProjects\skeletonTracking\venv\lib\site-packages\cubemos\skeleton_tracking\__init__.py", line 1, in <module>
from .nativewrapper import *
File "C:\Users\omria\PycharmProjects\skeletonTracking\venv\lib\site-packages\cubemos\skeleton_tracking\nativewrapper.py", line 28, in <module>
os.path.join(cubemos_dir, "bin", "cubemos_skeleton_tracking.dll")
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
enter image description here
and line 3 is when i'm importing the library:
from cubemos.skeleton_tracking.nativewrapper import Api
another weird thing, is that the problem was fixed randomly without me doing anything, and then it returned again!
i tried reinstalling the cubemos SDK, rebooting the computer, debug, and i really don't know what is the source of this problem.
it seems like its some problem with my OS (i have windows 10, and using python 3.7 and VENV and PIP for the project)
i tried to figure out if the path is the problem, but again, it was working before, and i can't really tell if that is the problem. what do you think is causing this?
i will appreciate any help.
thanks !
I had the same problem using a conda env. Demos worked but not the python sample. I explicitly added %CUBEMOS_SKEL_SDK%\bin to my Path environment since I had nothing before. That got it going. The %CUBEMOS_SKEL_SDK% was set up okay from the start.

Permission error while trying to import module in Python 3.X

I am trying to import a module in Python 3.X (6 and 5) and I am getting a permission error.
import meshio as msh
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/xxxxx/.eclipse/org.eclipse.platform_3.8_155965261/plugins/org.python.pydev_4.5.5.201603221110/pysrc/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/xxxxx/anaconda3/envs/py35/lib/python3.5/site-packages/meshio/__init__.py", line 21, in <module>
print(pipdate.check(__name__, __version__), end='')
File "/home/xxxxx/anaconda3/envs/py35/lib/python3.5/site-packages/pipdate/helpers.py", line 104, in check
_log_time(name, datetime.now())
File "/home/xxxxx/anaconda3/envs/py35/lib/python3.5/site-packages/pipdate/helpers.py", line 67, in _log_time
with open(_log_file, 'w') as handle:
PermissionError: [Errno 13] Permission denied: '/home/xxxxx/.cache/pipdate/log/times.log'
The strangest thing is that a few days ago I was able to import this module without any problem.
What can I do to solve this problem? I already searched through here, but none of the related problems match this case.
I am using Eclipse as IDE, but the same problem occurs no matter the editor I use.
It is possible that this file is locked in write mode (perhaps there was a shutdown of your computer and the lock wasn't released), meaning that you can't open it.
Since it is in your cache and it seems to be a log file, it should not be an issue to delete it (with sudo because the file is locked).
Seems like the module you're trying to use is importing pipdate.helpers module and that module tries to create a file on import (which is a very bad idea, by the way)
The user running the code doesn't have permission to create the file in the directory specified so it fails.

Installing Gumbo and its Python wrapper

I am trying to use Gumbo's python wrapper to parse HTML.
My operating system is Ubuntu 14.04.3 LTS. I am using Python2.7
I have cloned the latest version of Gumbo from github.
I followed the installation steps provided on Github.
The installation of the libraries, both the C library and the python wrapper, appeared to be successful ( No error message, both printed successful messages at the end )
C library final message:
Libraries have been installed in: /usr/local/lib
Python wrapper message:
Installed
/usr/local/lib/python2.7/dist-packages/gumbo-0.10.1-py2.7.egg
Processing dependencies for gumbo==0.10.1 Finished processing
dependencies for gumbo==0.10.1
The first problem I encountered was when I tried to open pydoc for gumbo, to better understand the library.
pydoc gumbo produced the following error:
problem in gumbo - <type 'exceptions.OSError'>: /usr/local/lib/python2.7/dist-packages/gumbo-0.10.1-py2.7.egg/gumbo/libgumbo.so: cannot open shared object file: No such file or directory
Searching for the message yielded a single result.
It was not of much use to me.
Looking at the dist-packages directory, I noticed that libgumbo.so was not in /usr/local/lib/python2.7/dist-packages/gumbo-0.10.1-py2.7.egg/gumbo/ . All other files ( soup-adapter.py, gumboc.py, etc ) where there however.
The installation of the C library placed libgumbo.so ( and some other libraries, like libgumbo.a libgumbo.la, etc ) in /usr/local/lib. So, as a work around, I created a simlink from .../dist-packages/gumbo-0.10.1-py2.7.egg/gumbo/ to /usr/local/lib.
This got pydoc gumbo to work.
I tried to import gumbo and soup-adapter in the interpreter after. I received the following error:
import soup_adapter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "soup_adapter.py", line 26, in <module>
import gumboc
File "gumboc.py", line 44, in <module>
os.path.dirname(__file__), _name_of_lib))
File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libgumbo.so: cannot open shared object file: No such file or directory
I am not sure how to proceed or how exactly to get gumbo to work.

python cannot find GL

Trying to use pyglet1.2alpha1 under FreeBSD with python3.3 on an amd64 machine, I get
$ python ~/.local/lib/python3.3/site-packages/pyglet/gl/gl_info.py
Traceback (most recent call last):
File "~/.local/lib/python3.3/site-packages/pyglet/lib.py", line 111, in load_library
lib = ctypes.cdll.LoadLibrary(name)
File "/usr/local/lib/python3.3/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/local/lib/python3.3/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: Shared object "GL" not found, required by "python"
During handling of the above exception, another exception occurred:
[…]
File "~/.local/lib/python3.3/site-packages/pyglet/lib.py", line 118, in load_library
if ((self.linux_not_found_error not in o.message) and
AttributeError: 'OSError' object has no attribute 'message'
I have tested my Mesa installation by running glxgears (works), I have tried installing PyOpenGL for comparison (which does not work, because it depends on the PIL, which is not fit for python3.3), and just to make sure I have reinstalled python3.3 after installing the mesa-demos and freeglut, and still no change.
In python2.7, I get the same error
OSError: Shared object "GL" not found, required by "python2"
(without the problem of During handling of the above exception, another exception occurred), also after installing PyOpenGL (which works as expected).
What is the problem here? How do get pyglet to work?
The various python files that come with pyglet and try to load external resources test explicitly if they run on linux. Consequently, they don't evaluate to the right things on FreeBSD. When replacing sys.platform.startswith('linux') with sys.platform.startswith('linux') or sys.platform.startswith('freebsd') in the files listed below, it seems to work.
pyglet/lib.py
pyglet/app/base.py
pyglet/gl/__init__.py
pyglet/image/codecs/__init__.py
pyglet/input/__init__.py
pyglet/media/drivers/openal/__init__.py

VLC Python Bindings -- Error 193

Have downloaded VLC.py, and placed it in my VLC install directory, where libvlc.dll is also present
On typing import vlc
I get the following error
Traceback (most recent call last):
File "C:\Program Files
(x86)\VideoLAN\VLC\vlc.py", line 88,
in
dll = ctypes.CDLL('libvlc.dll') File
"C:\Python27\lib\ctypes__init__.py",
line 353, in init
self._handle = _dlopen(self._name, mode) WindowsError: [Error 193] %1 is
not a valid Win32 application
Any ideas why?
If needed, my config is:
Win7 pro 64 bit
4GB RAM
Reposting my comment as an answer, since it fixed the problem:
I'm going to guess that the problem is trying to load a 32-bit DLL from a 64-bit process. You may be able to fix it by using a 32-bit Python build.

Categories