ImportError for python 3.5 (driver cannot be found) - python

I want to understand how does Python search for files using its search path. I have the following error:
Traceback (most recent call last):
File "C:\Users\Rusk\Desktop\BBone_RTL-SDR\codes\lab6.py", line 9, in <module>
import rtlsdr
File "C:\Program Files (x86)\Python3.5\lib\site-packages\rtlsdr\__init__.py", line 50, in <module>
from .librtlsdr import librtlsdr
File "C:\Program Files (x86)\Python3.5\lib\site-packages\rtlsdr\librtlsdr.py", line 41, in <module>
librtlsdr = load_librtlsdr()
File "C:\Program Files (x86)\Python3.5\lib\site-packages\rtlsdr\librtlsdr.py", line 36, in load_librtlsdr
raise ImportError('Error loading librtlsdr. Make sure librtlsdr '\
ImportError: Error loading librtlsdr. Make sure librtlsdr (and all of its dependencies) are in your path
I have verified that all of the modules and dependencies have been installed using pip. Ihe function of load_lbrtlsdr() is as such:
def load_librtlsdr():
driver_files = ['rtlsdr.dll', 'librtlsdr.so']
driver_files += ['..//rtlsdr.dll', '..//librtlsdr.so']
driver_files += ['rtlsdr//rtlsdr.dll', 'rtlsdr//librtlsdr.so']
driver_files += [find_library('rtlsdr'), find_library('librtlsdr')]
dll = None
for driver in driver_files:
try:
dll = CDLL(driver)
break
except:
pass
else:
raise ImportError('Error loading librtlsdr. Make sure librtlsdr '\
'(and all of its dependencies) are in your path')
return dll
It seems that the reason i encountered this error was because the program failed to locate the driver (.dll) which is located in my main desktop screen. I had edited the environment variable to include the path to the location of the driver but the error persists. I have been stuck trying to find alternatives but nothing seems to work. Could someone kindly elp me out or direct me towards some direction? Thanks! I am just 5 days old with Python. I am using a 64-bit windows OS by the way.

Related

How do I know which .dll is missing in python with cx_freeze?

I have a project which I am packaging with cx_freeze. When I try to run the resulting exe I get an ImportError: DLL load failed: The specified module could not be found.
Here is my setup.py:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(build_exe='liquidation', packages=['scipy', 'numpy'], excludes=['scipy.spatial.cKDTree'],
includes=['scipy', 'numpy', 'numpy.core._methods', 'scipy.sparse.csgraph._validation',
'numpy.lib.format', 'numpy.linalg._umath_linalg', 'scipy.sparse._csparsetools',
'scipy.sparse.linalg.isolve._iterative', 'scipy.sparse.linalg.eigen.arpack._arpack',
'scipy.special._ufuncs_cxx', 'scipy.special.specfun', 'scipy.integrate._odepack',
'scipy.integrate._quadpack', 'scipy.integrate.vode', 'scipy.integrate._dop',
'scipy.integrate.lsoda', 'scipy.optimize._minpack', 'scipy.optimize._zeros',
'scipy.spatial', 'scipy.spatial.ckdtree', 'scipy.spatial.kdtree',
'scipy._distributor_init', 'numpy.core._multiarray_umath'])
base = 'Console'
executables = [
Executable('liquidation.py', base=base, targetName='liquidation.exe')
]
setup(name='liquidation',
version='2.0',
description='Program to run and test Liquidation algorithms',
options=dict(build_exe=buildOptions),
executables=executables)
When I run python setup.py build_exe it seems to complete successfully, but when I run the exe I get the following output:
Traceback (most recent call last):
File "C:\Users\tamar\PycharmProjects\liquidation\venv\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\tamar\PycharmProjects\liquidation\venv\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\tamar\PycharmProjects\liquidation\venv\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tamar\PycharmProjects\liquidation\venv\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
module.run()
File "C:\Users\tamar\PycharmProjects\liquidation\venv\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
exec(code, {'__name__': '__main__'})
File "liquidation.py", line 64, in <module>
from io_tools.stock_wrapper import StockWrapper
File "C:\Users\tamar\PycharmProjects\liquidation\io_tools\stock_wrapper.py", line 4, in <module>
from io_tools.io_helper import *
File "C:\Users\tamar\PycharmProjects\liquidation\io_tools\io_helper.py", line 7, in <module>
from numpy import float_
File "C:\Users\tamar\PycharmProjects\liquidation\venv\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\tamar\PycharmProjects\liquidation\venv\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\tamar\PycharmProjects\liquidation\liquidation\liquidation.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.3" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
I understand that I need to point cx_freeze to the missing DLL's (either by adding them to buildOptions.include_files or by actually copying the DLL's to the build folder) but I am at a loss as to how to know which DLL's I am missing. numpy.core._multiarray_umath is in the build folder so I don't know what it could be.
I believe I am using the latest versions of numpy (1.18.3), scipy (1.4.1) and cx-freeze (6.1). Any help would be much appreciated!
Update: I used Dependency Walker to try and see what I am missing and it listed a file by the name of LIBOPENBLAS.SVHFG5YE3RK3Z27NVFUDAPL2O3W6IMXW.GFORTRAN-WIN32.DLL which cannot be found. All of the other dependencies have been copied into the build so it makes sense that this would be the missing one. Does anyone know where I can find this file?

Can't import pyueye module, dll errors

I wanted to use pyueye module to manipulate my IDS camera. I've installed latest drivers from manufacturer's website and I can manage the camera by using uEye Cockpit appliaction. I wanted to write some python script to use with camera, but i can't even import pyueye module.
My code:
import ctypes
from pyueye import ueye
print(ueye.__version__)
Error info:
C:\Python\python.exe C:/Users/Karol/PycharmProjects/ids_camera/ids_test.py
Traceback (most recent call last):
File "C:\Python\lib\site-packages\pyueye\dll.py", line 165, in load_dll
dll = DLL(libinfo, libnames, os.getenv(envname))
File "C:\Python\lib\site-packages\pyueye\dll.py", line 96, in __init__
raise RuntimeError("could not find any library for {} ({})".format(libinfo,
dllmsg))
RuntimeError: could not find any library for ueye_api (DLL_PATH: unset)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
\File "C:/Users/Karol/PycharmProjects/ids_camera/ids_test.py", line 2, in
<module>
from pyueye import ueye
File "C:\Python\lib\site-packages\pyueye\__init__.py", line 55, in <module>
from . import ueye
File "C:\Python\lib\site-packages\pyueye\ueye.py", line 54, in <module>
get_dll_file, _bind = load_dll("ueye_api", ["ueye_api_64", "ueye_api"],
"PYUEYE_DLL_PATH")
File "C:\Python\lib\site-packages\pyueye\dll.py", line 167, in load_dll
raise ImportError(exc)
ImportError: could not find any library for ueye_api (DLL_PATH: unset)
Process finished with exit code 1
I have installed that module via pip, my OS is Win 7 x64, my python interpreter is 3.6, also *.dll files associated with ueye are installed in C:\Windows... folder. I also copied ueye_api.dll and ueye_tools.dll files to pyueye directory, but it didn't help.
I tried adding ueye_api_64.dll from C:\Program Files\IDS\uEye\USB driver package to my pyueye folder. I also added this location to the system variable's PATH and this solved the problem for me.
Try the following things:
Restart your computer after the installation.
Make sure the DLL is in your C:\Windows\System32 directory.
Set PYUEYE_DLL_PATH to the directory of where the DLL is located.
When nothing of that helps please contact the IDS support.
I only put the DLL in the C:\Windows\System32 directory and it works right away. No restart, no addition to PATH.
Cheers.
(Python3)

Blender python import error: DLL load failes (only when using blender)

the question is may be similar to this one, but did not solve my issue and also is somehow much stranger:
I got a strange problem, where when executing only my python file from command line:
>python main.py, everything works. But when using it with blender like this:
blender -b ..\test.blend --pyhton ..\main.py
i get this error (file paths are substituted with ..) :
Traceback (most recent call last):
File "\\...\Blender\2.78\python\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "...\main.py", line 4, in <module>
import numpy as np
File "\\...\Blender\2.78\python\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "\\...\Blender\2.78\python\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "\\...\Blender\2.78\python\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "\\...\Blender\2.78\python\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "\\...\Blender\2.78\python\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
AL lib: (EE) UpdateDeviceParams: Failed to set 44100hz, got 48000hz instead
my main.py looks like this:
#import bpy
import sys
import numpy
import h5py
...more imports...
if __name__ == "__main__":
logging.info("No error")
The story I told so far, is fact, when I run the blender and python from a HTCondor Windows node. Again, only the python file works fine, but when including blender the DLL error occurs.
Additionally I tested everything before on my local PC where both variations work without issues, using exactly the same files! (Everything is located on a NAS drive)
There must be some linkage to some python stuff on my pc. I only have the miniconda3 directory, which i completely removed so blender can use the bundled one.
Hopefully somebody can help me and please feel free to ask for stuff I failed to explain.
EDIT:
The multiarray module is located in the numpy.core folder with the name mutliarray.cp35-win_amd64.pyd, which makes no sense to me why the module is found on my local PC but not on the HTCondor windows node.
EDIT 2:
According to sampler's suggestions I tried the following:
1) I used getenv = True in the submission file to submit the locally working environment with the job. Result: Does not work either.
2) I cleared all environment variables except those needed for running correctly on my local pc. Clearence happend with this lines:
for i in os.environ:
os.environ[i] = ""
The only used variable is set:
os.environ["PATH"] = "\\\\[servername]\\conda\\Blender\\2.78\\python\\Library\\bin;"
without this line I get the same multiarray import error on my local pc.
These lines are executed in my main.py script but still does not change anything when running on the condor node.
Even stranger is the fact, that running only the python script on the condor node works perfektly fine, but just running it with blender (as shown in the first codeline of this post), results in the multiarray import error.

program wont work after being compiled with py2exe

I wrote a program it works fine without any errors when I run it from the python interpreter, I then used py2exe to turn it in to an .exe but when I run it it does'nt work anymore... I get this error:
Traceback (most recent call last):
File "pass.py", line 1, in <module>
File "dropbox\__init__.pyc", line 3, in <module>
File "dropbox\client.pyc", line 22, in <module>
File "dropbox\rest.pyc", line 26, in <module>
File "pkg_resources.pyc", line 950, in resource_filename
File "pkg_resources.pyc", line 1638, in get_resource_filename
NotImplementedError: resource_filename() only supported for .egg, not .zip
Am I supposed to do something when using py2exe when I have downloaded modules imported into the program?
these are the modules imported :
import dropbox
import os
import getpass
from time import sleep
please help !
I fixed this problem using the solution found here
basically you modify ~line 26 in rest.py found in the dropbox library
to this:
try:
TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')
except:
# if current module is frozen, use library.zip path for trusted-certs.crt path
# trusted-certs.crt must exist in same directory as library.zip
if hasattr(sys,'frozen'):
resource_name = sys.prefix
resource_name.strip('/')
resource_name += '/trusted-certs.crt'
TRUSTED_CERT_FILE = resource_name
else:
raise
and then place the trusted-certs.crt file also found in the dropbox library in the same folder as your executable

How to package psutil with py2exe?

The app is working fine on my development win8 environment, but when it is packaged with py2exe and run on the production machine it throw the exception:
"The procedure entry point RtlIdnToAscii could not be located in the dynamic link library ntdll.dll"
The detail content of the log file is
Traceback (most recent call last):
File "DataviewerBackupRestorer.py", line 6, in <module>
File "RestorController.pyc", line 7, in <module>
File "psutil\__init__.pyc", line 136, in <module>
File "psutil\_psmswindows.pyc", line 14, in <module>
File "_psutil_mswindows.pyc", line 12, in <module>
File "_psutil_mswindows.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
It seems that a dll required by psutil is missing during the package process. I have tried to add the py2exe options with
py2exe_options = {"py2exe":{"includes":['decimal', '_mssql', 'uuid', 'psutil', '_psutil_mswindows']}}
But it is not working. Any ideas? Thanks in advance!
The solution is to remove System DLLs from the project directory. When I added psutil to my application py2exe added a lot of system DLLs to my project. It worked correctly on my and some other computers, but failed on another one. Removing from the project the .dll files that were available in C:\Windows\System32 solved the issue.
Finally in my case the solution was to add:
'dll_excludes': [ "IPHLPAPI.DLL", "NSI.dll", "WINNSI.DLL", "WTSAPI32.dll"]
into the py2exe options in setup.py file.

Categories

Resources