I have this script that I originally created in Jupyter Notebooks and I saved it later on as a .py file, then I used auto-py-to-exe to convert it to an exe file. When it runs it gives me this error:
ModuleNotFoundError: No module named 'pandas' [23712] Failed to execute script due to unhandled exception!
It's importing pandas in at the top of the script, and I had used pip install to install pandas, and I thought I had all of my python --path variables set correctly, but clearly something still isn't set right. Is this an issue of looking at the wrong directory?
This is apparently a somewhat common issue with auto-py-to-exe. I'd suggest reading through this blog post by the author for solutions to this and many other issues. If you skip to here, the suggested solution is as follows:
ModuleNotFoundError: No module named x / ImportError: No module named x
This means a particular module ('x' in this case) was not added to the package. I have seen this occur with packages in the pandas library and win32api; as long as you can identify the package (e.g. 'x'), then it is very easy to fix.
To fix this in the UI, open the advanced tab and find the --hidden-import input. Simply paste the module name into this input and then repackage. If the original error is still appearing, you have done this incorrectly.
Related
On windows I have built a very simple "hello world" C extension (the file hello.c from this site https://gist.github.com/physacco/2e1b52415f3a964ad2a542a99bebed8f). Using VS2015 I successfully obtain hello.dll. The problem is that I can't figure out how to import this file/module.
In the python shell (python 3.7) I have made sure that I'm in the same folder as the hello.dll. I have also made sure that sys.path() contains the folder path. But when I write "import hello" I get an error "ModuleNotFoundError: No module named 'hello'"
Does anyone has an idea of what is wrong is this very simple setup?
Update:
When trying to import a module that does not exist the ModuleNotFoundError is reported. After renaming the hello.dll to hello.pyd an ImportError is returned. So it seems like it tries to actually load the module.
Python compiled modules on Windows have the extension .pyd, not .dll. If you'd built it using setup.py the file would be built with the correct name. However, you built it yourself and gave it a name that Python doesn't recognise as a module.
In terms of the build command: you have to link it with libpython. You don't look to be doing this. The error you report is definitely one that you can get if the module is not linked against all its dependencies.
I know you don't want to use setup.py, however I'd use it at least once just to see what it does and if it works. You'll then at least have a command that you can copy with a working set of options.
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.
Whenever I try to just import winappdbg it gives me an error ModuleNotFoundError: No module named 'breakpoint'. So, I tried installing breakpoint and that gives me another error ModuleNotFoundError: No module named 'ConfigParser' and I've installed configparser several times and still get the error. (Can't find capital ConfigParser) I'm using Windows 10/PyCharm Community Edition 2017.2.3/python 3.6.3
WinAppDbg is only for Python 2.x, it does not work on Python 3.x. Honestly, I had no idea it would even let you import it.
All those import errors are happening not because of missing dependencies (also, no idea there were similarly named modules in pip), they are submodules of WinAppDbg itself. Since Python 3 has a different syntax to specify those, it tries to load them as external modules instead. I suppose you could fix that in the sources by prepending a dot before every submodule import, but I'm guessing more stuff would break down the road (string handling for example is radically different and that would affect the ctypes layer).
TL;DR: use Python 2.x.
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 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.