python, unable to make executable from script when I use scipy - python

I have a python application and I want to extract the executable. I have used py2exe with no problem in other scripts. But in this one I get errors that I think have to do with the fact that I import and use scipy.
My code runs fine in eclipse. Trying to make the procedure with scipy at first I got 3 dlls missing ("libmmd.dll","MSVCP90.dll","libifcoremd.dll"). At first I exluded these from setup.py and the .exe file was made but it did not run. After that I downloaded the dll files (also deleted the exclusion of setup.py) and added them in "C:\Python27\DLLs" and also "C:\Windows\System32" and "C:\Windows\SysWOW64" (I have 64 bit windows7). Again the exe is created in the folder dist, but trying to run it I get this:
http://imageshack.us/photo/my-images/145/py2exe.png/
Then I tried to do it with cx_Freeze. Again the .exe file was created but I get this error:
http://img521.imageshack.us/img521/3843/cxfreeze.png
So I suppose it has nothing to do with py2exe or cx_Freeze, but with the fact that scipy needs some dependencies that for some reason work in eclipse, but not when I make the executable.
Has anybody faced this problem? Any ideas on what I should do?
Thank you in advance!
EDIT: I did it with pyinstaller-2.0. It did not run at first. Then I added the DLLs to the folder, after that I added numpy and scipy to the folder and finally after an error message I added kdtree.py to the folder. I was thrilled to see that it runned! But then dissapointed again cause it runs ONLY in my pc (some useful .exe there)! I added the folder it to a dropbox folder, from where it runs in me with no problem but not for others. The error in other machines I tried is:
importError: DLL load failed: %1 is not a valid Win32 application

You could try putting the DLL files directly next to your executable. Also my py2exe gives some information about possible binary files that you might need to distribute with your application:
*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.
//Snip list of paths to dlls

Related

Matlab error: Not find Qt plataform plugin 'windows'

I'm running a python function in Matlab and when I run I got the error:
This application failed to start because it could not find or load the
Qt plataform plugin 'windows' in '' '' , Available plugins are:
minimal offscreen, windows. Reinstalling the application may fix this
problem.
I already followed the steps in this video copying the platform folder to pyqt tools and in this post add to the environment path.
If I run my code in python it works fine, It seems that Matlab is not finding the Qt platform plugin 'Windows'
Someone can help me, please?
This is the problem of deploying Qt applications. Depending on platform you're using you can find tool for deploying, it is in Qt directory. For example, on my PC with Windows this is:
c:\Qt\5.15.0\mingw81_64\bin\windeployqt.exe
You can call this tool like this:
windeployqt <path-to-app-binary>
// OR
windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>
There are many other options like --debug, --release, etc. Too see all of them, just call windeployqt.
On other platforms it could be linuxdeployqt, macdeployqt, also pyqtdeploy.
After calling this tool it will copy all required submodules to (near) your app, so it will find all it needs.
On my Windows system, I had the same experience that the Python function ran natively, but would not run via MATLAB. The problem was missing or incompatible dlls (not exe) files. To solve the problem I copied the exact dlls from my conda environment into the MATLAB \bin\win64 folder. That is, I copied these five dlls
qdirect2d.dll
qminimal.dll
qoffscreen.dll
qwebgl.dll
qwindows.dll
from the \Library\plugins\platforms folder of my conda environment
C:\Users\username\AppData\Local\Continuum\envs\myenv\Library\plugins\platforms
into the MATLAB folder
C:\Program Files\MATLAB\R2020b\bin\win64\platforms
While doing the copy, I overwrote three dlls which already existed in the MATLAB folder.

DLL load failed: The specified module could not be found PYTHON

I'm trying to import a module (UHD) into Python 2.7 from a network location. Whenever I do the import I get the following error:
ImportError: DLL load failed: The specified module could not be found
The initial import calls an init.py script that imports the other libraries. The first library import in the init script throws this error at the following line, which is also the first line of code within that file:
from . import libpyuhd as lib
libpyuhd is a .pyd file in the same directory as other files for this module.
The interesting thing is that I can import this fine from one computer (specifically the computer I built the module from source on) but when I try to run from another computer it fails.
The python executable is also stored at the network location along with the all the code I am trying to run. The only thing used in the build that isn't on the network drive is Visual Studio.
Does this error mean it can't find the .pyd file or that it can find the .pyd file but fails to import something from it?
Thank you.
I just solved this problem so may be able to help.
This ImportError: DLL load failed error meanslibpyuhd is not able to find a dependent library.
What is best is to install the Dependency Walker utility and open libpyuhd in that. It takes a few minutes to analyze all the stuff and will list all the dependent libraries and those that cannot be found comes up with a question mark.
In my case, it showed the boost python library to be missing, though I had already installed it. I just added the path to the missing library to PATH environment variable and valla! It works now.
[
I have encountered the same problem. I used Dependency Walker in order to search which were the missing dll.
I checked both : libpyuhd.pyd and uhd.dll.
By the way, the missing lib are hightlighted at the first level of hiearchy like in the snapshot :
snapshot
Then I copied the dlls directly into the same directory of libpyuhd.
dir structure
And then I copied the whole new UHD package directory into my site-package :
C:\Users\"YOUR_USER_NAME"\AppData\Local\Programs\Python\Python39\Lib\site-packages
I removed the PYTHONPATH from the environment variables and my PATH contains :
Path
PS 1: uhd.dll is also in this directory because I followed this documentation : https://files.ettus.com/manual/page_python.html
Ettus doc
PS 2 : I just finished a second installation on an other Laptop (windows 10); it's very import to copy/paste both uhd.dll and libusb-1.0.dll to the installed uhd directory (normally in the site-package dir).

Where can I get obscure DLL so py2exe will compile?

I am running py2exe to convert a rather large (~20k lines) python file into an executable. It's an older program and is written in python 2.7, 32 bit, so it does not translate well to a minimum working example. On running py2exe I encounter the following error:
error: [Errno 2] No such file or directory:
'libopenblas.UWVN3XTD2LSS7SFIFK6TIQ5GONFDBJKU.gfortran-win32.dll'
Having this dll in the Python27/DLLs folder will solve this issue, but after scouring the depths of google I have been unable to make any progress. My question: where can one download this dll, or a library which would contain this dll?
Problem solved. If you're running 32 bit python and numpy, you should be able to find this specific DLL at:
C:\Python27\Lib\site-packages\numpy\.libs
Copy and paste this into:
C:\Python27\DLLs
And run py2exe as normal.
Adding to Dr.Toboggan's answer, you can probably just import numpy inside the setup.py file for p2exe, this is what worked for me on a 64-bit system...

How can I use xml.sax module on an executable made with PyInstaller?

I want to have my application read a document using xml.sax.parse. Things work fine but when I move the executable to a Windows server 2008 machine things break down. I get an SAXReaderNotAvailable exception with "No parsers found" message.
The setup I'm using to build the executable is:
64 bit windows 7
Python 2.7.2 32-bit
PyInstaller 1.5.1
SAX readers seems to be dynamically imported, so the static analysis can't detect them and they can't be embedded with application.
To correct this, you'll have to be explicit to force PyInstaller to import those hidden modules.
Try to add this to you .spec (thanks Velociraptors) file :
hiddenimports = ['xml.sax.drivers', 'xml.sax.drivers2']
The executable turned out to be fine. For some reason or the other there's wrong versions of the needed dlls in PATH and the executable ended up trying to use those.

Installing python with python win32 extensions on a network drive

I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from the network, but when importing win32com I get a pop-up error saying:
The procedure entry point ?PyWinObject_AsHANDLE##YAHPAU_object##PAPAXH#Z could not be located in the dynamic link library pywintypes24.dll
after dismissing the message dialog I get in the console:
ImportError: DLL load failed: The specified procedure could not be found.
I searched the python directory for the pywintypes24.dll and it is present in "Lib\site-packages\pywin32_system32" .
What am I missing and is there another way in which I can install Python + Python-Win32 + additional module once and have them running on many machines? I don't have access to the Microsoft systems management tools, so I need to be a bit more low-tech than that.
On every machine you have to basically run following pywin32_postinstall.py -install once. Assuming your python installation on the network is N:\Python26, run following command on every client:
N:\Python26\python.exe N:\Python26\Scripts\pywin32_postinstall.py -install
Another important thing is Good Luck!. The reason is that you might need to do this as admin. In my case such setup worked for all but one computer. I still did not figure out why.
Python (or precisely, the OS) searches the DLLs using os.environ["PATH"] and not by searching sys.path.
So you could start Python using a simple .cmd file instead which adds \server\share\python26 to the path (given the installer (or you) copied the DLLs from \server\share\python26\lib\site-packages\pywin32-system32 to \server\share\python26).
Or, you can add the following code to your scripts before they try to import win32api etc:
# Add Python installation directory to the path,
# because on Windows 7 the pywin32 installer fails to copy
# the required DLLs to the %WINDIR%\System32 directory and
# copies them to the Python installation directory instead.
# Fortunately, in Python it is possible to modify the PATH
# before loading the DLLs.
os.environ["PATH"] = sys.prefix + ";" + os.environ.get("PATH")
import win32gui
import win32con
You could use batch files running at boot to
Mount the network share (net use \\server\share)
Copy the Python and packages installers from the network share to a local folder
Check version of the msi installer against the installed version
If different, uninstall Python and all version dependent packages
Reinstall all packages
This would be pretty much a roll your own central management system for that software.

Categories

Resources