I created notepad.ui the file in Qt4 Designer and tried to create the notepadwindow.py file by means of a command
pyuic4.bat notepad.ui -o notepadwindow.py
As a result I got the following error
Traceback (most recent call):
File "C:\Python27\Lib\site-packages\PyQt4\uic\pyuic.py" line 31, in <module>
from PyQt4 import QtCore
Import Error: DLL load failed: %1 then something strange on a different encoding Win32.
This is how I do it:
pyuic4 -x name.ui -o name.py
of course, in cmd go to the directory where your notepad.ui file is. Good luck.
Some installation issue i guess
pyuic4 notepad.ui > notepad.py
this works for me
I experienced with the same error and was able to solve it.
Although I work on a 64-bit Windows, my python shell (2.7.11) and all extension packages are 32-bit and they work well. I faced with many errors because my PyQt4 that i downloaded was 64-bit. When i remove it and install 32-bit PyQt4 the problem is gone and now i am able to convert .ui files to .py
Maybe your problem is the same with me or visa versa, but the versions of both idle and PyQt should match, either 32 or 64-bit.
open cmd and go to the directory where the ui file is being saved and there you write the following command.
pyuic4 -w notepad.ui > notepadwindow.py
I had the same problem with PyQt5 64-bit edition. Removed and replaced with 32-bit edition, then entered at the command prompt: pyuic5 -x "input.ui" -o "output.py"
Ran great.
I think there are at least two possible error conditions
1.ImportError: DLL load failed: The specified module could not be found.
then you have to check your PyQT version is comptible with your python.
In other words, if you use python 3.3, then you can only use PyQT for python3.3
and python 3.3 will not work with PyQT for python3.4
This was the problem I met. I solved it with re-install it
2. Import Error: DLL load failed: %1 then something strange on a different encoding Win32.
then it would be a OS problem. If you use 32bit Python then you have to use 32bit PyQt, so do 64bit
This is what i usually do when converting:
move to .ui file location with : cd /d D:\yourdirectory
YourPyuicLocation -x inputname.ui -o outputname.py
example :
C:\Users\ceppy\AppData\Local\Programs\Python\Python35\Lib\site-packages\PyQt5\pyuic5.bat -x Test.ui -o Test.py
use same version of python and PyQt .It worked out for me in solving error
ImportError: DLL load failed: The specified module could not be found.
For me, it had something to do with the path, maybe it was too long. I copied the .ui file to another folder and ran the command and it worked.
Related
I am trying to convert my .py file to an .exe file and I have tried all methods (auto-py-to-exe, pyinstaller, cz_freeze) and it does create the exe file but it always gives an error or the window opens and closes as soon as I double click the file.
It is a SpeechRecognition AI project coded in python. And it works just fine in the IDLE but once I create the .exe and try to run it the window pops up and shut down immediately after. (I use the cx_freeze and setup.py method for this)
If I try to convert .py to .exe using pyinstaller it gives me several different kinds of error messages.
As a .py file it works just fine but it doesn't work as an exe.
This is the error I get when using pyinstaller or auto-py-to-exe: Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception: Module 'pythoncom' isn't in frozen sys.path
Module 'pythoncom' isn't in frozen sys.path
I tried several things but nothing seems to work. I was previously using Python3.10 so I uninstalled it and downgraded to Python3.8 and reinstalled all the modules so technically it should work. I tried to create .exe files of another project and it worked just fine.
Another issue I come across is ModuleNotFoundError: No module named 'pyttsx3.drivers' I compiled the .exe using cx_freeze and it did create an .exe but it gives me this error.
Could someone please help me out with this?
(PS: This is the list of imports I am using for this project:
screenshot of all imports
import speech_recognition as sr
import pyttsx3
import datetime
import wikipedia
import wikipediaapi
import webbrowser
import os
import time
import subprocess
import wolframalpha
import json
import requests
from newsapi import NewsApiClient)
I just solved this for my project, which is using none of the direct imports your project is, but it appears the same low level library is causing an issue.
In my case, the single import is:
from pywinauto.application import Application
The solution is to tell PyInstaller to bundle the missing .DLL, which in this case is pythoncomxx.dll where xx is your python version. 39 in my case.
Here is the call that eventually worked for me.
pyinstaller --onefile --add-binary ".venv/Lib/site-packages/pywin32_system32/pythoncom39.dll;." autoTest.py
More generally: pyinstaller --onefile --add-binary "[path to dll];." file.py
Note, I'm on Windows. If you are on mac/linux, the ; character in the --add-binary argument would be :. See note in the documentation here
Discussion
This clicked for me when I used ProcMon to profile the file access of my initial version that was failing. It was looking for this .DLL in a bunch of different folders, then quitting.
The answers to this question were helpful. But I didn't want to settle for copying the DLL to output manually. And consequently, having to use a directory output versus a single executable file.
Answers on this question also gave the hint about using the --add-binary flag, but ultimately I had to provide the specific path to the missing DLL instead of just referencing by name as these answers showed. It probably works to specify the DLL by name if it is accessible on your PATH.
How to locate this DLL in the first place? Do a search on your site-packages folder.
i am trying to program a simple script and i would like to know if anyone has the answer to this question
when i have a module for example WMI from 'pip install wmi' in the form as 'import wmi' in my code, how do i get the pyinstaller module to compile the wmi module with the exe file
i have tried importing from the source code in a folder example 'from wmi import wmi' but i got no luck when launching the exe file only in the raw python file, also just to note when i compile the script i do the command 'pyinstaller vb.py --onefile'
remove --onefile since wmi couns as a file (or multiple if its a package)
I have developed a simple software in python with GUI. I'm actually working on Natural Language Processing and I've just put the whole NLP process in a GUI.
I tried to convert the whole project to a exe file in python using Pyinstaller. I successfully converted it to an exe file but when I run it , it shows an error message something like this
This is the image of my error
I have already solved it but by using another way of converting py to exe which is the cx_Freeze.
I had the same issue earlier today and finally got it to work using the following software versions:
Python 3.6.8, nltk 3.5 and a dev version of pyinstaller:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Additionally, I used scikit-learn version 0.21.1.
Few days back, I had the same problem while compressing to EXE. This Problem generally occurs when PyInstaller failes to find Libraries and Modules to import to the directory. But I overcame this problem and the wise solution yet tedious method to do is mentioned below,
Convert Python Scripts to EXE with console = True in the .spec file or to be simple, do not add --noconsole argument while converting using System Argmuents method.(execute GUI with CMD)
After successfully building the file, go to respective directory (dist folder) and open command prompt
Run the Exe file using Command Prompt.
Find the error message and rectify it correspondingly. For example, consider the following Error Message, vcomp140.dll is missing from \\sklearn\\libs directory.
At the end of this Error Message, you'll find Failed to load dynlib/dll , Therefore, find the file or program which is missing. Say, Here we've .libs\\vcomp140.dll
Find vcomp140.dll using window search bar in your C Drive.
Copy the specific file and paste in the directory(under "dist" folder) where the file is missing. Here, the directory is dist\\PyScriptToEXE\\sklearn\\.libs
MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
exec(bytecode, module.__dict__)
Traceback (most recent call last):
...
...
...
py3.7.egg\PyInstaller\loader\pyiboot01_bootstrap.py", line 169, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\MOHAMM~1\\AppData\\Local\\Temp\\_MEI38242\\sklearn\\.libs\\vcomp140.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[13968] Failed to execute script try
Follow the steps again using CMD to eliminate each error.
I created an application in Python 3.6 with a GUI built in PyQt5. Some modules are only available for Python 3.5 and 3.6.
I managed to pack it on Mac using py2app. I am trying to do the same thing on Windows. I tried to use this guide, but I still have issues.
For what I understand I have 3 options:
py2exe
pyinstaller
cx_Freeze
1) py2exe
According to here py2exe is still not available for python3.6, I need to use python3.5 then.
Using 3.5, I get this error and the compilation stops:
error: [Errno 2] No such file or directory: 'C:\\Users\\carlo\\AppData\\Roaming\\Python\\Python35\\site-packages\\py2exe\\run-py3.5-win32.exe'
2) pyinstaller
Running pyinstaller through Python3.5 as:
pyinstaller --onefile APP.py
I get just a bunch of warnings (lib not found) but the compilation gets to the end. The created EXE, though, opens the command prompt and pops up the following error:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt5plugins.py", line 46, in <module>
File "c:\program files (x86)\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module
module = loader.load_module(fullname)
ImportError: DLL load failed: %1 is not a valid Win32 application.
Failed to execute script pyi_rth_qt5plugins
3) cx_Freeze
Using python3.5, it first give the 'TCL_LIBRARY' error. Following the instructions here the compilation goes smoothly. The created application, however, opens up and closes immediately. It simply doesn't work.
Using python3.6, the compilation seems okay. When I try to open the application, this error pops up. I just managed to take a quick screen-shot:
Does anybody have any suggestion? Any alternative I am not considering?
I managed to solve the problem!
I followed the instructions here.
I first ran (with Python3.5):
pyinstaller CodeName.py
Then I modified the .spec file as indicated in the link and the magic happened!
I have a simple .py file that queries a DB server with pymssql that works as required.
I am trying to schedule a task to run the script but it fails
When I call the .py file from a batch file I get the below error:
import pymssql
ImportError: No module named pymssql
Any ideas why this is failing when run from a batch file ?
Python 2.7.6
Running on Windows 2008 R2
OK, so it turned out that the Python.exe I used when testing the script was in C:\Python27(32 bit) and not C:\Program Files\Python27 (64bit)
I needed to specify the correct exe and it worked.
thanks to those who contributed
I faced similar issues however I was running on Raspberry Pi. Had trouble running them from etc/rc.local and it kept showing me the error.
What I did
Created print_path.py in the directory of the python script you wanted to run and write the following:
import sys
print(sys.path)
Go to terminal
Make use of this line which i took from here:
sudo python3 [path_of_file]/[nameoffile].py > [path_of_file]/output1.txt
Go to terminal
sudo nano etc/rc.local
Place the following into rc.local:
sudo python3 [path_of_file]/[nameoffile].py > [path_of_file]/output2.txt &
** Take note of the Ampersand
Compare the two outputs
You should be able to find the path that differs.
Then copy the missing path.
Put into python script(that you want to run on boot)
import sys
sys.path.append('/home/pi/.local/lib/python3.5/site-packages')
It should be working because it works for me.
try adding the full path of the module (like this "C:\myfolder\mymodule.py") to the %path% variable within the batch file and then executing it
PS:
Set %path% = %path%+"C:\myfolder\mymodule.py"
should look something like this