PyWinAuto in exe (PyInstaller) on Citrix can't find window, from python itself works like a charm - pyinstaller

I have a pywinauto application that triggers a search in Notepad (for testing purposes).
This works excellent in a regular Windows enviroment. (both running directly from running the python script stand-alone, as from the pywinauto-packed exe).
When I run this in an Citrix environment, pywinauto seems unable to find the windows when running from the pyinstaller-exe. When running directly from python, it does work correctly.
I couldn't find limitation in the pyinstaller documentation, as that states that it works with pywinauto.
(This is using Python 3.10)
This is the error from the .exe:
Update
Building like this (with splash screen)
pyinstaller.exe --noconfirm --noconsole --paths ./venv/Lib/site packages/ --splash splashscreen.png ./main.py -n notepadopener
Seems to make it fail.
Building without splash-screen works fine:
pyinstaller.exe --noconfirm --noconsole --paths ./venv/Lib/site packages/ ./main.py -n notepadopener
Update 2
It seems this piece of code in the main.py, which should hide the splashscreen, causes it to fail.
# Hide the splash screen after one second
if '_PYIBoot_SPLASH' in os.environ and importlib.util.find_spec("pyi_splash"):
import pyi_splash
sleep(1)
pyi_splash.close()
Update 3
It seems adding a sleep after the .close() also solves the issues..
# Hide the splash screen after one second
if '_PYIBoot_SPLASH' in os.environ and importlib.util.find_spec("pyi_splash"):
import pyi_splash
sleep(1)
pyi_splash.close()
sleep(0.5)

Related

Pyinstaller works on build machines, but not on target machines

I am using pyinstaller to distribute a python program. It's work fine on my build machine, but on my target machines, I am getting a "path not found" error and the path is relative (.e.g. .\mylib). I do modify the sys.path at runtime, but I have taken the steps suggested by pyinstaller to account for that. I've also tried -add-data, but -add-data seems to make things worse and I get errors where files are being created twice.
What's is bizarre to me is that if I run the python script on the target machine once, (i.e. install python), the EXE created by pyinstaller by the build machine will now work on the target machine. I can then remove python from this machine and.... the exe continues to work. My next step is to start a VM and follow the debug steps from the guide, but thought I would reach out and see if anyone had some advice on what my cause this?

How to run qt-creator project with 'sudo nice x' prefixes?

So i have a C program that i made a while back that im going to remake in qt with additional features.
Typically how i ran the program is I open the terminal, navigate to the project folder, and use the command
$ sudo nice --10 ./myprogram
That is not the case anymore, since i am using qt-creator i now just simply click the 'run' button and the program starts. My program works best when it has elevated scheduler priority hence the nice --10.
How do i modify my qt-creator project to run my program with the sudo nice --10 command?
To do that go to
Tools-> Options-> Environment -> System Tab under the terminal option write "/usr/bin/xterm sudo nice --10"
Also if you have not done it already go to Projects -> Build & Run -> Run and check the box Run in terminal.
I never tried, but in the config of your project you can add a user defined executable to be executed.
Maybe creator allows for a shellscript, than you can simply put your sudo nice --10 in a shellscript, or you write a little program which gets a program path as parameter and starts it with the elevated scheduler priority (guess there is a user api in linux for that...)

pyinstaller exe file don't work with pyaudio - speech recognition

Hi i am a intermediate python developer and I made a voice paint app that you can control app with voice , for this app i used speech recognition for my app and speech recognition needs pyaudio .
for installing pyaudio i couldn't use pip or pipwin and i installed it using .whl file downloaded from internet and it works!
now in my app when I run it in python ide or vs code it works but when i use pyinstaller to get exe it gives error ( no module named pyaudio )
i tried lots of ways but none worked.
can anybody help?
Question, when you say "i tried lots of ways but none worked"; did this include adding pyaudio to a pyinstaller hook?
from PyInstaller.utils.hooks import collect_data_files,collect_submodules
#should only require hiddenimports
#datas = collect_data_files('pyaudio')
hiddenimports = collect_submodules('pyaudio')

Creating standalone (exe) viewer from code run on Ipython

I have this very basic piece of Python which I use to visualize some data and perform a few interactions with. I launch it from Spyder and it is basically just a function.
In broad terms:
open a file and create a DataFrame from it
plot some data and add a few sliders to interact with the data
I was wondering whether I could make this small code available to other people who do not have Python installed and probably not even the latest Qt5 libs I am using.
Os would be Linux but could also be Windows if it came easier.
Can you tell me how time consuming would it be to create a standalone file which could be double clicked and just show the plot with the interactive bits?
Just followed the (2 line!) instructions on PyInstaller:
$ echo "print 'hello world...'" > helloworld.py
$ pip install pyinstaller
$ pyinstaller helloworld.py
$ dist/helloworld/helloworld
hello world...
Looks pretty automated. It analyses your dependencies as far I can tell and brings everything you need together and then makes a launch script. It works on loads of platforms and even mentions Qt on the front page. I reckon its worth a go!

How to use XULRunner to run SQLite Manager outside of Firefox in Mac OS X Lion?

I have installed XULRunner 11.0 (xr) from here:
Downloads - sqlite-manager - Extension for Firefox and other apps to manage any sqlite database - Google Project Hosting
I have followed the steps listed here:
kiveo - Mac SQLite Manager Standalone App
I have read and tried the suggestions here (though they're for version 6.0):
stackoverflow: How to Install and run a XulRunner Application on Mac OS X?
I am able to get the help listing with this command:
/Library/Frameworks/XUL.framework/xulrunner-bin -h
I am able to run the app from Firefox using this command (after changing the max version in sqlitemanager-xr-0/application.ini to 11.0 from 11.0a1):
/Applications/Firefox.app/Contents/MacOS/firefox --app ~/Downloads/sqlitemanager-xr-0/application.ini
Here are the contents of the application.ini file:
[App]
Name=sqlite-manager
ID=SQLiteManager#mrinalkant.blogspot.com
Version=0.7.7
BuildID=201111132204
Vendor=lazierthanthou
Copyright=Copyright (c) 2008 - 2011 lazierthanthou
[Gecko]
MinVersion=2.0
MaxVersion=11.0
[XRE]
EnableExtensionManager=1
When I run the following command in Terminal, with or without sudo, it just immediately returns to the command prompt. There are no error messages. No application appears under Applications. Nothing seems to happen at all. (And, despite the stackoverflow page above noting that --install-app may not really be supported, it is in the XULRunner help listing - which I guess doesn't necessarily mean it'll work ;)
/Library/Frameworks/XUL.framework/xulrunner-bin --install-app Downloads/sqlitemanager-xr-0/ /Applications
Following a suggestion below, I checked for an exit code. The line above is returning 2.
Help?
Just like you did with Firefox, this command should run your app:
/Library/Frameworks/XUL.framework/xulrunner-bin --app ~/Downloads/sqlitemanager-xr-0/application.ini
Also, the --app switch is optional within XULRunner.
Here's how you can make a self-contained application you can run from the Dock.
Use the xulrunner --install-app command to create the application and then copy all contents of XUL.framework/Versions/Current into the generated application at /Applications/sqlite-manager.app/Contents/MacOS.
You can then create a wrapper script that runs the xulrunner within the generated app with the application.ini file as described here.
For example, put the following into sqlite-manager.app/Contents/MacOS/sqlite-manager and make it executable.
#!/usr/bin/env bash
APP_PATH="/Applications/sqlite-manager.app"
"$APP_PATH/Contents/MacOS/xulrunner" --app "$APP_PATH/Contents/Resources/application.ini"
Now you have to tell OS X to run sqlite-manager instead of xulrunner. You can do that by editing sqlite-manager.app/Contents/info.plist and setting CFBundleExecutable to sqlite-manager like this:
<key>CFBundleExecutable</key>
<string>sqlite-manager</string>
The only limitation of this approach is that it breaks when you move the application or rename it. I'd love suggestions on how to get rid of the absolute path within the sqlite-manager script.
try this:
firefox -chrome chrome://sqlitemanager/content/sqlitemanager.xul
or on OS X
/Applications/Firefox.app/Contents/MacOS/firefox -chrome chrome://sqlitemanager/content/sqlitemanager.xul
(found on http://www.egeek.me/2013/09/07/how-to-run-sqlite-manager-with-a-single-command/)
works fine for me on UBUNTU 12.04 to start sqlite manager without starting firefox first
If the install was successful, I think the app should be available in some usual place for your system (which wasn't mentioned, but I'm guessing OSX :). Have you looked under /Applications?
To see whether the command failed quietly, you could check its return value. Is there a verbose switch?
$ cd narnia
bash: cd: narnia: No such file or directory
$ echo $?
1
$ cd .
$ echo $?
0
$ cd narnia && echo "success"
bash: cd: narnia: No such file or directory
$ cd . && echo "success"
success

Resources