pyinstaller "unable to find a txt file when adding a binary" - python

When i was converting my script to exe using pyinstaller i got an error:-
Unable to find "c:\users\praveen\appdata\local\programs\python\python36\lib\site-packages\importlib_resources\version.txt" when adding binary and data files
You can view the full error here:
https://drive.google.com/file/d/1FmV5kdb7p6TgEZwKBFDmFIszC-Qha0BD/view?usp=sharing
my script has alot of imports, they are:-
import tkinter as tk
import os
import time
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PIL import ImageGrab
import numpy as np
import cv2
import pytesseract
import webview
what does that error mean? and why am i getting it?

You need to write the command correctly, example:
pyinstaller --add-data web_folder;web_folder --add-data db.sqlite;. gui.py
Description: title_of_folder_or_file;path_to_it (if your OS Windows use ";", else ":". On windows it's 100% but on linux or mac i don't know) for folder you need after ; set path to this folder, example web_folder;web_folder
Source - Official Documentation

Related

Why does my tkinter app will show a node.js window?

I use pyinstaller to pack a .py file.
Then when I use something about web crawler (I use requests module).
This window will show and disappear fastly.
I want to say that it is maybe incredible.It wouldn't pop this window when I run this .py file,but after using pyinstaller to pack it,it will pop this window.
(In another computer,it doesn't install node.js.And it doesn't pop this window)
Here is the module I use:
from pynput import keyboard
from PIL import Image, ImageTk
import ctypes
from io import BytesIO
import threading
from win10toast import ToastNotifier
import base64
from win32com.shell import shell
import requests
import execjs
import sys
import pythoncom
import getpass
import tkinter
from random import randint
from tkinter import ttk
from tkinter import messagebox
import os
import json
import traceback
from webbrowser import open_new_tab
from tkinter import scrolledtext
import win32con, win32clipboard, win32gui
from PIL.ImageGrab import grabclipboard, grab
from aip import AipOcr
import time
And the window is this:
What should I do except uninstall node.js? How to avoid this node.js window shows?
Thanks in advance.
Thanks bro,acw1668's suggestion enlighten me a lot.
I want to say,execjs module will run js code.
And if your computer install node.js and you set PATH for node.js,Then your default js environment is node.js(If you don't install node.js,then your default js environment is Jscript in windows system).
So if you doesn't want to use node.js,you should set the default js environment in python.
# change the js environment.
os.environ["EXECJS_RUNTIME"] = "JScript"
# all of environment which execjs support
PyV8 = "PyV8"
Node = "Node"
JavaScriptCore = "JavaScriptCore"
SpiderMonkey = "SpiderMonkey"
JScript = "JScript"
PhantomJS = "PhantomJS"
SlimerJS = "SlimerJS"
Nashorn = "Nashorn"

when i run the exe i get No module named 'PyQt5' but from the script its work

i use windows 10, python 3.7 and pyinstaller version 3.5.
I wrote some script in pycharm and when i hit run (from the pycharm IDE) its work fine.
but when I execute it by pyinstaller to exe ("pyinstaller --onefile design.py"),
I click the file inside the dist folder (design.exe) and i get this error
Traceback (most recent call last):
File "design21.py", line 10, in <module>
ModuleNotFoundError: No module named 'PyQt5'
[11116] Failed to execute script design21
my code start with:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gui_with_layouts.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QThread,pyqtSignal
from style import *
from firebase import firebase
import xlrd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
from PyQt5.QtWidgets import *
stop_flag = False
UPDATE:
I dont know how but i did the next step and somehow it work:
delete line 10 and 11 (that import the 'Pyqt5')
execute new exe (from cmd the commend pyinstaller --onefile design21.py)
run the new exe file from the dist folder (Of course I got errors, because I used the moudle 'Pyqt5' without importing it).
4.add again the import line (that lines that i deleted 10 and 11).
execute again new exe (from cmd the commend pyinstaller --onefile design21.py)
then when I run the new exe it work...
no idea why but its worked.
you need to install pyqt5.
just open CMD and install it.
pip install pyqt5
No module named 'PyQt5' here not PyQt5 not installed on python environment install correctly or use the right python environment.
Pycharm editor goto project setting and choose python environment with 'PyQt5'
OR pycharm bottom CMD install a pip install PyQt5
I just ran into the same problem. For me importing sip in the first line of the programm solved the issue:
from PyQt5 import sip

Cannot open .exe after pyinstaller convert

Running my GUI application created in PyQt5 using any IDLE or the file.py is running perfectly, however, when I converted the .py to .exe using Pyinstaller
I get an error every time I try to run the .exe file for some reason a small command window pops with an error and immediately disappear I screenshot the error before it closes. Any Idea Thanks in advance
Error image.
I tried to execute different commands for pyinstaller but no luck.
<pyinstaller filename -F >
<pyinstaller filename -onefile >
<pyinstaller filename >
It's an app over 900 lines and I cannot upload all of that but I think according to the error first lines.
The error occurs so here are the lines of code.
The problem is within importing modules I believe.
from PyQt5.QtWidgets import QWidget
from PyQt5 import QtCore, QtGui, QtWidgets
from datetime import datetime
import time
import os, sys #importing system modules
class Ui_MyTrophiesWindow(object):
class save_txt_file(QWidget):
def GetSaveFile(self):
path = QFileDialog.getSaveFileName(self,"Save MyTrophies.txt here", "MyTrophies", "*.txt")
working_path = os.path.abspath(__file__)[0:-13]
file = open(str(working_path) + "Txtpath.dat", "w+")
for i in path:
file.write(str(i))
file.close()
It is very common that sometimes PyInstaller won't recognize all Qt5 dependencies especially QT core DLLs. A simple way is to just locate that file on your current Python path and feed it with add-data flag in PyInstaller. Also, I suggest you not to use upx with PyQt as it may corrupt some DLLs:
pyinstaller --noupx -F --add-data "<Python_path>/Lib/site-packages/PyQt5/Qt/bin/Qt5Core.dll;./PyQt5/Qt/bin" script.py
To verify the answer suppose below example:
import traceback
import os
import sys
def func():
from PyQt5.QtWidgets import QWidget
from PyQt5 import QtCore, QtGui, QtWidgets
try:
if getattr(sys, 'frozen', False):
print(sys._MEIPASS)
func()
print("Import OK!")
except Exception:
traceback.print_exc()
input()
After you run the executable you would see the path for Pyinstaller (something like C:\Users\User\AppData\Local\Temp\_MEI90202), go to this path and search for the Qt5Core.dll and check if it is there.
I had look your error and according to me, I think you need to (re)install Qt5core.dll module and to add it in the site-package/PyQt5/init.py path. You can download the dll file here:
http://www.telecharger-dll.fr/dll-Qt5Core.dll.html
Good evening
Make sure that you have all the items of that app in the correct folder. Let me put an example that happened to me days ago:
I had an app with a folder named "options" that had 3 files (2 icons for my buttons ui and a .ini file). When I created the pyinstaller version of my program I assumed that it would somehow copy those files and pack them inside the --onefile file or into the dist folder (if not --onefile command was used). Nope, it didn't.
After scratching my head for hours, I just copied the options folder from my source files and pasted it next to my --onefile file (or inside the dist folder).
After that, my app works without issues. So... make sure it has all the files it needs in the correct folders.

PyInstaller - How do you handle environmental variables?

Background:
I am trying to convert a python script to an executable file that can be used on other computers. I decided to use PyInstaller. I am using Python 2.7.13/Anaconda 2.2.0 (64-bit). I have of course seen many examples and I can achieve this for basic examples. However, the script I am now working on uses environmental variables. The following block of code appears at the start of my python script:
import os
# force qt4
os.environ['ETS_TOOLKIT'] = 'qt4'
os.environ['QT_API'] = 'pyqt'
from traits.api import HasTraits, Range, Instance, Button, on_trait_change, Bool, Str, Enum, Float, Int
from traitsui.api import View, Item, Group, HGroup, spring, Handler, Action, InstanceEditor, Menu, MenuBar, message, \
Tabbed
from mayavi.core.ui.api import MayaviScene, SceneEditor, MlabSceneModel
from pyface.api import FileDialog, OK
import yaml
from mayavi import mlab
import numpy as np
from collections import namedtuple
import gdal
Problem:
Running pyinstaller --onefile filename.py on the command line produces an .exe, but it doesn't run because of the error: ImportError: No module named qt4."qt4" isn't a module, so I am assuming the problem is with the line " os.environ['ETS_TOOLKIT'] = 'qt4'".
After looking at various questions related to PyInstaller, I know how to use 'hiddenimports', but I have no idea how to handle environmental variables. Obviously something like pyinstaller --onefile --hidden-import qt4 filename.py didn't work.
You should try pyinstaller --onefile --hidden-import "os" filename.py

PyInstaller makes my 4kb python program 163MB. Is this normal?

There are dozens of questions on here asking how to decrease the size of Py2EXE and PyInstaller windows binaries (complaining about executables 10MB in size), but my issue is two orders of magnitude greater, as my PyInstaller binary is over 160MB! I'm importing TK, PyQT4, scipy, numpy, and a few other doozies. I understand each of these binary packages is huge, so my question is if this sheer size is to be expected. Do I just have to suck it up and deal with it, or is there something I can do to shave off 100+ MB?
My imports are:
from PyQt4 import QtGui,QtCore
import sys
import numpy as np
import pyqtgraph
import time
import pyqtgraph.exporters
import webbrowser
import pyaudio
import time
import threading
import scipy
import scipy.fftpack
import scipy.io.wavfile
I'm building my primary script (go.py) with PyInstaller using:
pyinstaller.exe -y -F --distpath="./build" -p "C:\python3\Lib\site-packages\PyQt4" go.py
Is 160+ MB expected? Thanks for your advice!

Categories