I have compiled a script with pyinstaller and it compiles fine but when I run the program I get the following error in the console window.
ImportError: DLL load failed: The specified module could not be found.
I am trying to import Crypto when I get this error. Why does this happen and how can I fix it?
According to the pyinstaller manual:
You can verify that hidden import is the problem by using Python's verbose imports flag. If the import messages say "module not found", but the warnproject.txt file has no "no module named..." message for the same module, then the problem is a hidden import.
Hidden imports are handled by hooking the module (the one doing the hidden imports) at Analysis time. Do this as follows:
Create a file named hook-module.py (where module is the fully-qualified Python name, eg, hook-xml.dom.py) and place it somewhere. Remember the place as your private hooks directory.
In the .spec file, pass your private hooks directory as hookspath argument to Analysis so will be searched. Example:
a = Analysis(['myscript.py'], hookspath='/my/priv/hooks')
In most cases the hook module will have only one line:
hiddenimports = ['module1', 'module2']
When the Analysis finds this file, it will proceed exactly as though the module explicitly imported module1 and module2.
This question seems related, the answers might also be useful for you.
Finally, this report seems to contain a similar problem. The user seemingly was able to fix it by updating to pyinstaller 2.1, so you might want to give that a try if you haven't already.
Related
The stacktrace is pretty clear about the cause of the error. But I am unable to figure about the root cause. I have a package abc and there is a module inside the package called abc.py. In abc.py, I have defined Flags . When I run the code, I get an error saying DuplicateFlag Error: The flag 'config' is defined twice: First from abc, Second from abc/abc.py.
I havenot imported the module abc.py in other files. Can a python expert tell me what could be the issue?
I am not sure what is causing the issue. But the fix for it is to delete all the attribute in the flags before you actually define the flags using the following code:
for name in list(flags.FLAGS):
delattr(flags.FLAGS,name)
I hope this helps. Anybody who know the actual cause of the issue is welcome to answer it for precisely.
UPDATE: The cause is partly answered in this Running a module in a package, importing a subpackage . The takeaway is : If you're running the module as a script a lot, you probably should make a new top-level script module that import the module from the package and runs the desired code . This prevents the module full of code from potentially existing twice, and also lets you benefit from cached bytecode being loaded from a .pyc file (which may make your program a bit faster to start up).
My package had cyclic dependency. Hence that could be the issue. I didnot even need to delete the attribute after i move my main script out of the package and run it normally.
I'm fairly new to python, but can't seem to get my head around this error - have found posts with similar issues, but none of the responses have helped.
I'm running Python 3.4.0 and have installed a module called lxml.
I wrote some code which starts
from lxml import html
This runs perfectly well from the python.exe interface, and the module can be used to succesfully import and parse XML.
However, if I save the script as a *.py file, and try to call it from a cmd.exe prompt, I get the ImportError: No module named lxml error.
Python is within C:\Python34, and the relevant module is located in C:\Python34\Lib\site-packages\lxml, which contains the required __init__.py
file.
I've checked sys.path which, amongst others, holds C:\\Python34\\lib\\site-packages
The double-backslashes and lowercase 'l' in 'lib' shouldn't make a difference, should it? All listed paths appear to have double-backslashes instead of single.
I did attempt to add the path with an uppercase 'L' using
sys.path.insert(1, 'C:\Python34\Lib\site-packages')
which subsequently appeared as a seperate path, however did not resolve the issue.
Additionally, I replaced the first line of my script with
import sys
sys.path.append('C:\Python34\Lib\site-packages')
which appeared to attempt to read the required __init__.py file (progress!!!), but then gave the following error: ImportError: Module use of python34.dll conflicts with this version of Python, so I probably won't pursue this avenue, unless it is of relevance.
Any idea what I'm doing wrong with regards to ImportError: No module named lxml?
I'm creating a Python library file from C++ using Boost::Python, and I'm trying to import it from the Python command line to test it.
The module seems to work correctly when imported, but only if it is named .so. If the same exact file is renamed to .pyd, in the same directory, the console replies with an
ImportError: No module named Test
I have also tried to rename it with a trailing _d in case the console was in debug mode, but that does not seem to be the case.
What could be the problem?
I am trying to load a *.pyd with Python, but I receive the well known "Import Error: DLL load failed: the specified procedure can not be found." error.
I have already done the following:
1.) Investigated the *.pyd with Dependency Walker. GPSVC.DLL and IESHIMS.DLL came up as missing, but delay loaded, IEFRAME.DLL aslo came up as missing an export, but was also delay-loaded. It's my understanding that these are not used, and are delay load anyway, so they should not be the problem.
2.) Did an "import foo" on foo.pyd in the python command window, with ProcMon watching. ProcMon shows event "LoadImage" on "foo.pyd" with result SUCCESS.
This seems to imply that the *.pyd file loaded correctly.
So what am I missing. My windows diagnostics are telling me all is well, but python is telling me the thing cannot be loaded (usually due to a missing dll or symbol).
Ideas?
Thanks!
Is the .pyd file for the same version of Python you're using? Loading a .pyd file for the wrong Python version can produce that error message.
Dependency Walker can show you which pythonNN.dll it links to.
If you have a file foo.pyd, for import foo to succeed, there must be an externally accessible function named initfoo. Dependency Walker will show this (typically the ONLY function) if it exists. initfoo needs to be called by Python to initialise the foo module.
Note: I would expect a more explicit error message if this were the problem:
>>> import fubar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initfubar)
>>>
You say that you are "trying to load a *.pyd file". Is that just a strange way of describing import foo or is it something else?
Did you create the pyd? If not, who did? Have you asked them? Is this pyd available on the web so that others could try to load/import it?
Ok here is the answer:
The windows diagnostics (depends, procmon, etc) were showing the DLL (or pyd) loading fine.
Python was showing that it was not loading fine.
I found that the windows tools were referring to a different Python26.dll hiding in my C:\Window\SysWOW64 folder.
This second Python26.dll (found in SysWOW64) has a symbol that is missing in the primary python26.dll (installed by the windows python installer, found in C:\Python26).
This symbol "_PyByteArray_empty_string", was apparently needed by my *.pyd file.
So when loading via windows diagnostics, the SysWOW64 dll was found, and the *.pyd loaded properly. When loading from python, the dll in C:\Python26\ was found, the symbol was missing, and load failed.
So that is WHY the problem manifested. The question now is: Why are there two versions of Python26.dll floating around, one with _PyByteArray_empty_string, and one without?
I'm using Python 2.6.6. Perhaps this symbol is removed in 2.6.6 but present in some older 2.6.x release?
I used python 2.5 and imported a file named "irit.py" from C:\util\Python25\Lib\site-packages directory. This files imports the file "_irit.pyc which is in the same directory. It worked well and did what I wanted.
Than, I tried the same thing with python version 2.6.4. "irit.py" which is in C:\util\Python26\Lib\site-packages was imported, but "_irit.pyc" (which is in the same directory of 26, like before) hasn't been found. I got the error message:
File "C:\util\Python26\lib\site-packages\irit.py", line 5, in
import _irit
ImportError: DLL load failed: The specified module could not be found.
Can someone help me understand the problem and how to fix it??
Thanks, Almog.
"DLL load failed" can't directly refer to the .pyc, since that's a bytecode file, not a DLL; a DLL would be .pyd on Windows. So presumably that _irit.pyc bytecode file tries to import some .pyd and that .pyd is not available in a 2.6-compatible version in the appropriate directory. Unfortunately it also appears that the source file _irit.py isn't around either, so the error messages end up less informative that they could be. I'd try to run python -v, which gives verbose messages on all module loading and unloading actions -- maybe that will let you infer the name of the missing .pyd when you compare its behavior in 2.5 and 2.6.
Pyc files are not guaranteed to be compatible across python versions, so even if you fix the missing dll, you could still run in to problems.