I am trying to get setup with a easily distributable python program which happens to use scipy. I have two windows 10 64 bit virtual machines. On one I have installed the dependencies for my program, and it runs correctly. Additionally I have installed pyinstaller and performed a freeze. The program runs correctly as the building user on the first VM, as well as a new user on the first VM. The issue is that I get a error loading dll on the second VM, which I just spun up as a test.
I attempted to find all imports from scipy and include them as hidden imports. I also included the scipy "extra dll".
pyinstaller --windowed --icon="%SCRIPT_FOLDER%\res\icon.ico" --hidden-import=numpy --hidden-import=scipy._lib._util --hidden-import=scipy.special._ufuncs --hidden-import=scipy --hidden-import=scipy.stats --hidden-import=scipy.interpolate --hidden-import=scipy.special --hidden-import=scipy.cluster.hierarchy --paths C:\Users\User\AppData\Local\Programs\Python\Python37\Lib\site-packages\scipy\extra-dll --workpath "%WORK_FOLDER%" --distpath "%OUTPUT_FOLDER%" "%SCRIPT_FOLDER%\..\something.py" -n something
Also, I can see the referenced dll files in the correct spot in the frozen output folder under scipy/special there are _ufuncs.cp37-win_amd64.pyd and also _ufuncs_cxx.cp37-win_amd64.pyd
The error is generated specifically on the line "from scipy import special".
Also of note, though I guess it does not help much, is that I have followed a similar procedure for OSX and Linux platforms with no such issue, and no need for any manual hidden import specification...
Would appreciate any help that you can give to help figure out what is going wrong.
Related
I fixed a super-annoying case of "ImportError: DLL load failed while importing" in a way that generally applies to Windows, so let me share it with the group. Here is the question:
I installed FINUFFT via pip install finufft. When I import finufft, I get this error:
ImportError: DLL load failed while importing _finufft: The specified module could not be found.
How do I fix it?
Read to the end before doing anything.
The error means that a DLL cannot find another DLL that it was linked with. But which other DLL?
Download Dependencies.
Locate your problematic DLL. In this specific case: Locate the folder ...\Lib\site-packages\finufft\ of the FINUFFT installation that you want to fix. ...\ is the path of your standard python installation or of your python virtual environment.
Start DependenciesGui.exe and use it to open the problematic DLL, e.g. ...\finufft\_finufft.cp38-win_amd64.pyd. (A .pyd is a regular DLL with some specific entry points for python.)
On the left, you will see a complete list of the problematic DLL's direct dependencies, whose dependencies you can in turn unfold by mouse click. Apart from typical Windows-DLLs, like kernel32.dll and MSVCRT.dll, and apart from the FFTW-DLLs, which should already be in the FINUFFT-folder, there will also be some - possibly missing - Linux-DLLs. For me, it was libgcc_s_seh-1.dll, libgomp-1.dll and libstdc++-6.dll. By checking their direct dependencies, I also discovered libwinpthread-1.dll as missing.
[See EDIT below!!!] I found those DLLs in Anaconda (...\Anaconda3\Library\mingw-w64\bin\), but you can probably also get them from cygwin (...\cygwin64\bin\), git (...\Git\mingw64\bin\) or anything else that downloads mingw64 and its packages on Windows.
To solve the problem, copy the respective DLLs into ...\Lib\site-packages\finufft\ and give them the exact filenames that the FINUFFT-DLL is expecting according to Dependencies. This works because Windows and because of the Windows DLL search order.
Now, import finufft should work in the specific python environment whose FINUFFT installation you fixed. Clearly, this method can be applied anytime DLL dependencies are missing.
EDIT - correction of my answer by #CristiFati: If possible, DLLs and similar things should always be built with the same toolchain. So if you don't compile them yourself, get them from as few different places as possible, i.e. don't mix regular python, Anaconda, cygwin, etc. - if possible. Of course, Windows DLLs will have a different origin from Linux DLLs.
The issue
I developed a PyQt app that uses NLTK to throw item recommendations based on a query, and now I need to package it into a standalone app. After checking the internet for weeks, I tried fbs, but ended up going to pyinstaller. When I tweaked the necessary things, the app was succesfully built... For Linux. Issue here is, I need it to be able to run on Windows, and I'm using Ubuntu.
In order to package it for Windows, I read everywhere that the best choice is to just wine pyinstaller and call it a day, but when I do that, I end up with this error message:
OSError [WinError 127] Procedure not found: 'RtlIpv6AddressToStringA'
For what I can collect, this is a semi-usual thing, since it looks like NLTK and PyInstaller do not get along well.
What I tried
Modifying hook-nltk.py and changed the lines regarding nltk_data
Using PyInstaller with the .py file as well as the .spec file
Looking pretty much everywhere finding someone with a similar problem, to no avail
When I try to import time I get : No module named time
I have tried other time modules(datetime and timeit) and they work fine. I decided to check my installation and I can't find time.py anywhere. I checked the Lib, Scripts, libs and include folders, but can't find it anywhere.
Anyone know what I can do to fix this? Maybe download the .py and put it in Lib myself?
I am using Python 3.3.5 with PyCharm IDE. Only extra scripts I've installed is EasyInstall and PRAW.
The import does work. When PyCharm said No module named time, I assumed I would get a compiler error and started trying to fix it.
However when I eventually just ran the code it worked fine. I expect PyCharm doesn't detect the time module as it's a dll and not a py as noted by Martijn in the comments. This is on PyCharm Community Edition 4.0.4.
I tried playing with virtualenv and a host of other things, but I eventually went to Preferences -> Build, Execution, Deployment -> Console -> Python Console, and in the "starting script" box, I added two lines:
sys.builtin_module_names.append('sys')
sys.builtin_module_names.append('time')
This got rid of errors I had with both sys and time. Once I did that, I even get autocomplete for both of those modules... weird.
I'm trying to compile a python project into an executable. To test this, I've got Py2Exe installed, and am trying to do their Hello.py test. Here is hello.py:
print "Hello World!"
Here is my setup.py:
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
I do the following on the command line:
python setup.py py2exe
And I get it mostly working until it start 'finding dlls needed', at which point we get:
Traceback:
<some trace>
ImportError: DLL load failed: %1 is not a valid Win32 application.
Python version is 2.6.6, and I'm on a 32-bit machine running Windows 7. Any ideas or help most appreciated.
In my experience py2exe is rather difficult to use, a bit hit-and-miss in terms of whether it will work or not, and an absolute nightmare to get working at all with any matplotlib import.
I realise this question is quite old now, but I am not sure why people continue to use py2exe when there are much smoother functioning alternatives available. I have have good results with pyinstaller (which was recommended to me after asking a question here on SO where I was also battling with py2exe). Now every time I have tried it it "just worked", so if you're still interested in packing up python code into executables then try give this app a shot instead.
http://www.pyinstaller.org/
Note: py2exe hasn't been updated for some years, while python and 3rd party modules have, which must be partly why it often doesn't work particularly well these days.
Sounds like step 5 in this tutorial describes what you are experiencing:
http://www.py2exe.org/index.cgi/Tutorial#Step5
I had this same problem, this is what I was able to do Q-A. Basically, I downloaded the updated sqlite dll file from sqlite.org. I replaced the py2exe generated DLL file with this new file. The program worked after that. Do make sure you download the 32-bit DLL, however.
I am using python 2.6 on XP. I have just installed py2exe, and I can successfully create a simple hello.exe from a hello.py. However, when I try using py2exe on my real program, py2exe produces a few information messages but fails to generate anything in the dist folder.
My setup.py looks like this:
from distutils.core import setup
import py2exe
setup(console=['ServerManager.py'])
and the py2exe output looks like this:
python setup.py py2exe
running py2exe
creating C:\DevSource\Scripts\ServerManager\build
creating C:\DevSource\Scripts\ServerManager\build\bdist.win32
...
...
creating C:\DevSource\Scripts\ServerManager\dist
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'wx._misc_' (C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc_.pyd -> wx._misc_.pyd)
creating python loader for extension 'lxml.etree' (C:\Python26\lib\site-packages\lxml\etree.pyd -> lxml.etree.pyd)
...
...
creating python loader for extension 'bz2' (C:\Python26\DLLs\bz2.pyd -> bz2.pyd)
*** finding dlls needed ***
py2exe seems to have found all my imports (though I was a bit surprised to see win32 mentioned, as I am not explicitly importing it). Also, my program starts up quite happily with this command:
python ServerManager.py
Clearly I am doing something fundamentally wrong, but in the absence of any error messages from py2exe I have no idea what.
I put this in all my setup.py scripts:
distutils.core.setup(
options = {
"py2exe": {
"dll_excludes": ["MSVCP90.dll"]
}
},
...
)
This keeps py2exe quiet, but you still need to make sure that dll is on the user's machine.
I've discovered that py2exe works just fine if I comment out the part of my program that uses wxPython. Also, when I use py2exe on the 'simple' sample that comes with its download (i.e. in Python26\Lib\site-packages\py2exe\samples\simple), I get this error message:
*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory
So something about wxPython makes py2exe think I need a Visual Studio 2008 DLL. I don't have VS2008, and yet my program works perfectly well as a directory of Python modules. I found a copy of MSVCP90.DLL on the web, installed it in Python26/DLLs, and py2exe now works fine.
I still don't understand where this dependency has come from, since I can run my code perfectly okay without py2exe. It's also annoying that py2exe didn't give me an error message like it did with the test_wx.py sample.
Further update: When I tried to run the output from py2exe on another PC, I discovered that it needed to have MSVCR90.DLL installed; so if your target PC hasn't got Visual C++ 2008 already installed, I recommend you download and install the Microsoft Visual C++ 2008 Redistributable Package.
wxPython has nothing to do with it. Before Python 2.6, Python used Visual Studio 2003 as their Windows compiler. Beginning with 2.6, they switched to Visual Studio 2008, which requires a manifest file in some situations. This has been well documented. See the following links:
http://wiki.wxpython.org/py2exe
http://py2exe.org/index.cgi/Tutorial#Step52
Also, if you're creating a wxPython application with py2exe, then you want to set the windows parameter, NOT the console one. Maybe my tutorial will help you:
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
It looks like this is only a dependency for Python 2.6. I wasn't getting this error under 2.5, but after the upgrade I am.
This email thread has some background for why the problem exists and how to fix it:
http://www.nabble.com/py2exe,-Py26,-wxPython-and-dll-td20556399.html
I didn't want to have to install the vcredist. My application currently requires no installation and can be run by non-administrators, which is behavior I don't want to lose. So I followed the suggestions in the links and got the necessary Microsoft.VC90.CRT.manifest and msvcr90.dll by installing Python "for this user only". I also needed msvcp90.dll that I found in the WinSxS folder of an "all users" Python 2.6 install. Since I already had two of the three, I included msvcm90.dll to prevent future errors though I didn't get any immediate errors when I left it out. I put the manifest and the three DLLs in the libs folder used by my frozen application.
The trick I had to perform was including an additional copy of the manifest and msvcr90.dll in the root of my application folder next to by py2exe generated executable. This copy of the DLL is used to bootstrap the application, but then it appears to only look in the libs folder.
Hopefully that discovery helps someone else out.
Also, I had the same problem with having py2exe log a real error message. Then I realized that stderr wasn't getting redirected into my log file. Add "> build.log 2>&1" on the command line where you invoke py2exe.
import sys
sys.path.append('C:\\WINDOWS\\WinSxS\\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2')
On each Windows, you can find the file MSVCP90.dll in some subdirectory in C:\\WINDOWS\\WinSxS\\
In my case, the directory was: x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2.
Go to C:\\WINDOWS\\WinSxS\\ and use windows file search to find MSVCP90.dll.
Just for your info, for me it worked to copy the files
Microsoft.VC90.CRT.manifest
msvcr90.dll
into the directory with the .exe on the user's machine (who has no python or VC redistributable installed).
Thanks for all the hints here!
The output says you're using WX. Try running py2exe with your script specified as a GUI app instead of console. If I'm not mistaken, that tends to cause problems with py2exe.
Try this: http://www.py2exe.org/index.cgi/Tutorial#Step52
It worked for me
There is some info on the wxPython wiki.
Deploy a Python app
py2exe with wxPython and Python 2.6
On my win8.1, I do not find the path
c:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT
On the contrary , the dll is found in
C:/WINDOWS/WinSxS/x86_Microsoft.VC90.CRT_XXXXXXX
The XXX may vary according to your PC
You may search in the path , then add the path in you setup.py
import sys
sys.path.append('C:/WINDOWS/WinSxS/x86_Microsoft.VC90.CRT_XXXXXXX')
import sys
sys.path.append('c:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT')