I'm still a beginner with coding so maybe this question will be trivial for some of you. My apologies in advance.
For a project, i made a webcrawler using python and selenium, with an user interface made with Tkinter. I use a chromedriver to open chrome for the webcrawling part.
I converted my Tkinter file with pyinstaller into an executable file. When doing so, i typed the following flags: --onefile -w
I was told that the latter one prevents opening a command prompt when running the file, however, when i run the executable, my pc opens the command prompt for the chromedriver. How can i fix this?
-w will prevent the creation of a console for the main exe, not for the execution of the chromedriver.
You should have a look at ChromeDriver console application hide thread for removing the console created by chromedriver
Related
I've written a little GUI with tkinter for my own purposes on my Mac. I've written a two-line bash script to run it, and I can launch it from my desktop by double-clicking an icon. This is fine, but it pops up a terminal window, which I find annoying.
I would like to have it run as an app, without opening a terminal window. I followed the instructions in ccpizza's answer to create an app with Automator. I chose /usr/bin/python as the shell, and pasted in my python code. When I click on the desktop icon, I get an error box that says,
The action “Run Shell Script" encountered an error.
The console log has the error,
LaunchServices: Could not store lsd-identifiers file at /private/var/db/lsd/com.apple.lsdschemes.plist
I saw that /private/var/db/lsd is owned by root and I am the owner of the app. I tried
sudo chown root <appname>
and it doesn't give an error, but I am still shown as the owner of the app.
I've also tried choosing usr/local/bin/bash as the shell script, pasting in my bash script. When I run click the icon, I don't even get an error box, but the same error shows up in the console log.
Is there an easy fix for this? I'm just interested in getting this method to work. I'd rather not do anything more elaborate, like installing py2app or platypus.
I ended up getting platypus. It was trivial to do what I wanted. Just pick "None" for the interface.
If you just want to write a python script and run as a app, you can try pyinstaller.
This is my first post, thanks for viewing in advance.
I wanted to convert test.py to test.exe using pyinstaller. Everything worked fine until I tried to use -w option to get rid of the console window. It says-
'Failed to execute script test'
Below is the code -
from selenium import webdriver
browser = webdriver.Firefox()
I guess when using '-w' option for script with external applications like browser it will pop up with this error?
Thanks guys
your script is fine, it's the way you are using pyinstaller. to get rid of the console window you need pyinstaller added to your system path and then type this in a regular command prompt:
pyinstaller script.py --windowed
I want to make my program executable.
I used TkInter to write the GUI, and I read somewhere that you have to save your file as .pyw to hide the console when the program is executed.
The problem is that after making it an executable with PyInstaller, the console shows up again, even though the file converted was .pyw.
How can I hide the console also in the .exe file?
Did you try --windowed command line flag ?
You can just save the file with .pyw extension and you can just use pyinstaller --onefile Filename.pyw
I think you renamed it. You save it as .pyw don't rename it.
The screenshot are below:
Output:
But it takes a while to open.
Thank you
-Levers
What are you using to make the executable?
If you use py2exe and you use:
setup(windows=[pythonscriptnamehere])
in the setup script instead of:
setup(console=[pythonscriptnamehere])
it will run the executable without launching a terminal in the background.
From The PyInstaller Documentation:
Using a Console Window
By default the bootloader creates a command-line console (a terminal
window in GNU/Linux and Mac OS, a command window in Windows). It gives
this window to the Python interpreter for its standard input and
output. Your script’s use of print and input() are directed here.
Error messages from Python and default logging output also appear in
the console window.
An option for Windows and Mac OS is to tell PyInstaller to not provide
a console window. The bootloader starts Python with no target for
standard output or input. Do this when your script has a graphical
interface for user input and can properly report its own diagnostics.
As noted in the CPython tutorial Appendix, for Windows a file
extention of .pyw suppresses the console window that normally appears.
Likewise, a console window will not be provided when using a
myscript.pyw script with PyInstaller.
Rather than saving/renaming/changing the extension to .pyw, you can just add --noconsole to the command line and use the standard .py file with it and this would hide that console window.
Example:
We have a file named GUI_name.py in our folder that uses Tkinter. Now we could easily create .exe file that doesn't show the console window by typing pyinstaller --onefile --noconsole GUI_name.py in cmd.
I am trying to open a file through python that once it is open takes you to a GUI. The link works fine when i just click on it and python seems to locate the file and open it, but the GUI doesn't appear. Please help. This is whay i have been using.
import subprocess
subprocess.Popen("C:/full/path")
I get no track back errors, but the GUI doesn't appear. Thoughts of how I can get it to appear, or what the problem might be?
Thanks
The file you're trying to 'start' is a cmd script. Use this code:
subprocess.Popen("cmd.exe /k C:\full\path\to\file.cmd")
.cmd files are not executable by themselves - you need to invoke cmd.exe to execute them. This is also what windows does when you double-click the file on the desktop.
I am running python 2.7.1. I can't figure out how to launch the IDLE IDE. I am told it comes already installed with python, but I can't find it using spotlight.
In the stock Mac OS X python installation, idle is found in /usr/bin, which is not (easily) accessible from Finder and not indexed by Spotlight. The quickest option is to open the Terminal utility and type 'idle' at the prompt. For a more Mac-like way of opening it, you'll have to create a small app or shortcut to launch /usr/bin/idle for you (an exercise left to the reader).
When you open up a new terminal window, just type in
idle
Then you will see a little rocket icon show up as IDLE loads
Then the Python shell opens up for you to edit
I think the shell command is
python -m idlelib.idle
but i am not a mac user so i can't test.
One way to run IDLE from spotlight or an icon in the Applications folder is to build a quick Automation for it. As mentioned by other commentators, this probably isn't necessary for Python 3, as it creates a shortcut automatically, and some hand-installed versions have tools to do this automatically. But if you want to roll your own:
You'll need to know the terminal command to open your version of IDLE. On my Mac right now (early 2016), running python 2.7.10, it is "idle2.7"
Using spotlight, or in the Utilities folder, open "Automator"
Choose an "Application" type document.
Make sure "Actions" is selected in the gray bar, upper left.
In the actions column, find "Run Shell Script" and double-click it, or drag it to the workflow area on the right.
Enter the terminal command in the parameters box that appears.
Save your automation (I called mine "IDLE" and put it in the Applications folder, to make it easy).
It's now available (as soon as spotlight indexes it) via all the normal methods. The only side-effect will be that while it's running, your menu bar will have a spinning gear over in the tray area next to the clock. This indicates an automation workflow is running. Once you close IDLE, it will go away.
first to launch the terminal CMD+space
second to input idle3
the idle will be activated automatically.
After you launch idle from the command line (make sure idle shell window has focus), click File, click "New File". A new window opens; this is your editor.
Type your program in the editor. Click "File", click "Save As...". Save your file somewhere with any name you choose, and a ".py" extension to the file name.
Click "Run", click "Run Module" (or, F5). Assuming no errors, the results will appear in the Shell window. Edit your file & repeat as necessary.
The answer of Matthewm1970 works like a charm!
And if you add an & to your shell command, the automation script will end immediately. There is no spinning gear. Like so:
/usr/local/bin/idle3.5&
Note the ampersand.
Cheers.
-melle
open Terminal
type "idle" and press enter
right click on "Python" icon > Options > Keep in Dock
so for python 3.4.3 in applications a folder named "python 3.4" click that and click IDLE.
for python 2.7.9 go here https://www.python.org/downloads/ and get 2.7.9 and a folder named "python 2.7" click that and click IDLE.
As to the earlier questions about starting IDLE: you can certainly start it from the command line. Also, if you installed Python using Homebrew, you can run 'brew linkapps' (from the command line); that will place an app for IDLE (among other things) in Launchpad (Applications folder).