I am trying to make a command-line application using Python.
I have developed the program, but I see that my program gets executed in cmd.exe, which seems to be the default for that kind of programs.
But I would like a finer GUI, like that of Windows Terminal. But the problem is that, Windows Terminal is not installed in all Windows computers as is cmd.exe.
Because of this I would like to request you that to suggest any methods to make the GUI or a method to bundle up Windows Terminal with my Python program.
So first we need to understand some terminology. You compare Windows Terminal and cmd.exe, but those are actually two entirely different types of applications. CMD is the old Windows shell. It runs inside a terminal emulator (a.k.a. terminal). There are multiple terminals that it can run under in Windows:
By default in Windows 10, it runs in the legacy Windows Console Host. This is the nearly 30 year (maybe more) old terminal for Windows.
CMD can also run inside Windows Terminal, the replacement terminal by Microsoft that is available to install in Windows 10 or Windows 11. Under Windows 11, it can become the default terminal for Windows.
When you ask Windows to run a console/terminal app, like your Python CLI app, Windows always runs it in its default terminal -- Under Windows 10, that is always the Windows Console Host. Under Windows 11, it may be either Windows Console Host or Windows Terminal, depending on the user configuration.
But there are also multiple other terminals that can run your CLI Python app in Windows:
Some of the more popular are:
ConEmu
Cmder
MobaXterm
You can find others listed in this blog post.
So it's really not that your app runs in CMD, but that your app runs in Python (the interpreter), which is running under CMD (the shell), which is running under Windows Console Host (the default terminal emulator).
Note that Python can also run under other shells (PowerShell, Linux shells under WSL, Nushell, etc.). These shells can also run in any of the terminals above. Or your Python CLI app can run as the top-level inside a terminal.
Ok, now that we've established some basics ...
But I would like a finer GUI, like that of Windows Terminal.
It's a bit unclear what you mean by that, but there may be other solutions than trying to package Windows Terminal. Both the legacy Console and Windows Terminal should have similar capabilities for your application. Windows Terminal adds things like tabs for the user, but you won't have control over that in your application. Both Console Host and WT can be configured with the same Windows fonts.
One thing you can do in Windows Terminal that you can't in Console Host is define a Profile for your application, including the themes, background image, etc. that you want it to run under. Perhaps that's what you are asking for, but you don't specify that those capabilities.
suggest any methods to make the GUI
If you are looking to create a GUI in Python, consider building it using a GUI Framework rather than as a CLI application. You can even write a terminal emulator in Python, but that would likely be a bit overkill for this.
or a method to bundle up Windows Terminal with my Python program.
That's probably not a good idea. Windows Terminal works best when it is installed as a Microsoft Store app (a.k.a. UWP, Modern, etc.). It is not possible to bundle Microsoft Store apps with another application; just like you can't install another Apple App Store app automatically from another on iOS. It's also possible to install/run Windows Terminal as a traditional .exe, but that's not the default (or supported) way.
You might consider the following:
Have your main Python app be a "launcher" that checks to see if Windows Terminal is installed, perhaps by looking for the existing of the wt.exe.
If Windows Terminal is installed:
Check for the existence of your applications JSON fragment in the appropriate directory (see link). Install it if it doesn't exist.
Launch your application by calling something like wt.exe new-tab --profile <your_app_profile> to start or open a new tab in Windows Terminal with the profile you defined in your JSON fragment.
If Windows Terminal is not installed:
Recommend that the user install it. Open the Microsoft Store link to it.
If they choose not to, your launcher should still launch the CLI portion of the app -- Windows will use the default terminal, which should be Windows Console Host.
Provide the instructions for running the CLI portion by itself (without the launcher) so that users of other terminal emulators can run it inside their preferred environment.
Related
I have an python GUI application that communicates with a web application, the website generates a link to open the desktop application (python app), so i have bash scripts that modify the system variables to make it ready for the system to recognize the link and open the app,
My question is that i want to make a debian package for that app with the files and bash scripts, how to do it??
I tried to convert the python application into one-file using pyinstaller and put bash scripts in same installer folder then run them using another python application that i compiled also with pyinstaller but the error happened telling that pythonlib3.8 not found on the system (Ubuntu 18) and my app developed on Ubuntu 20.
I would suggest using fpm. This is a tool specifically for creating packages for different Linux distributions such as Debian or RHEL.
Here is the documentation and even specific example for python.
Dev. Box: Windows 7
Remote Box where project should be deployed: Redhat Linux
Project on remote machine does not utilise pip or virtualenv but rather an in house alternative to virtualenv.
I setup my remote interpreter in Pycharm via Ssh to the python interpreter in linux box and see all the modules on remote with version info listed.
Pycharm tries initially to upload Pycharm helpers to remote box but is I guess unable to install them as I imagine it cannot find usual python tools like pip, so I see a banner on the remote interpreter saying Setup tools not present on remote. Regardless when this preference window is closed pycharm initiates indexing I assume the remote interpreter and modules.
When I open a file in the code however after indexing completes I cannot get auto code complete to work for any module even standard library modules i.e. json, sys, os...
I tried to get more info on Pycharm Helpers that try to get installed but all I found was they get used for remote debugging and "scaffolding" which I can't find additional details as to what the latter means or if it is even relevant to get autocomplete to function.
Need help really badly on this, thanks in advance to anyone who can aide me in this matter.
Some collegues got around this by having Devbox be a Mac OS or any other linux distribution, cloning the project locally and then using the local interpreter option in Pycharm but unfortunately I can't utilise local interpreter even though the project is cloned because on windows Pycharm expects the local interpreter to be a .exe
While running Linux versions of python, pip etc. "natively" on windows is amazing, I'd like to do so using a proper IDE. Since SSHD compatibility has not been implemented yet, I'm trying get PyCharm to recognize Linux python as a local interpreter.
After installing the Windows Linux subsystem, typing
bash -c python
from the windows command line will drop you into a python shell.
bash -c "echo \"print 'hello world'\" | python"
works as well, producing "hello world" as output in the windows shell!
I'm trying to wrap this up as a .bat file and present it to PyCharm as a local interpreter, i.e.
python.bat:
C:\Windows\System32\bash.exe -c "echo %1 | python"
But I keep getting "the sdk seems invalid" for any variation I try. Since I'm not sure exactly what PyCharm is doing to "validate" the SDK, this is hard to overcome.
Using PyCharm Professional with WSL Python on Win10
Starting SSH
PyCharm can only be configured to use WSL Python as a Remote Interpreter (this is due to lack of other public API).
Install Win10 build 14361 or later. You also can upgrade your current Insider Preview.
Install wsl (something like lxrun /install` && lxrun /update )
Run bash.exe
Update to latest version sudo apt-get update && sudo apt-get upgrade
Open /etc/ssh/sshd_config
Enable password authentication (unless you want to use public keys). Open /etc/ssh/sshd_config , and set PasswordAuthentication yes.
Since chroot is not implemented in WSL (yet), you also need to set UsePrivilegeSeparation no
Save and close it
Type sudo $(sudo which sshd) -d to run OpenSSH on foreground (it is much easier for debug). You should see something like Server listening on 0.0.0.0 port 22
From another bash.exe session try ssh 127.0.0.1
If you see message about ECDSA finger print, answer y . You should see password prompt. If you see it, then your server works correctly.
Turn it off with CTRL+C, and start server in daemon mode (sudo service ssh start). Looks like upstart is broken on current WSL, so you would need to run bash.exe, start sshd and keep console window opened since WSL stops when the last client disconnects. You may create wsl_ssh.bat file like bash.exe -c "sudo service ssh start &&& sleep 999d" and use it to launch ssh.
Configuring PyCharm
PyCharm should be configured to use WSL as a remote interpreter but without deployment, since each drive on Windows is mapped to an appropriate folder in /mnt/<DRIVE_NAME> in WSL. So, you only need to configure the mapping. For remote interpreters, see configuration-remote-python-interpreters . You should use 127.0.0.1 as hostname, and login and password you entered after first lxrun /install. You also should set C:\ to /mnt/c/ in your mappings. See the video from the previous post.
Author: Ilya Kazakevich
14 Jun 2016, 17:20
https://youtrack.jetbrains.com/issue/PY-19129#comment=27-1469350
I tried working with most solutions but the main issue is that I can't downgrade OpenSSH on Windows to something below 7.5 as is recommended by JetBrains.
Luckily they have solved this issue for us!
I have downloaded the Early Access version of Pycharm 2018.3
https://blog.jetbrains.com/pycharm/2018/10/pycharm-2018-3-eap-7/
This is however only available in the professional version.
I'd like to add the answer of bmjjr by stating that this is only available with the PyCharm Professional Edition. The Remote Interpreter feature is not available with the Community Edition, as I sadly found out:
Supported only in Professional Edition
Cython
Django
AppEngine
Flask
Jinja2
Mako
web2py
Pyramid
Profiler
SQLAlchemy
Diagrams
Remote interpreters, remote debugging, Vagrant, Docker
Duplicate code detection
Code coverage
.po files support
BDD support
Profiler integration
Thread Concurrency Visualization
https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html
Well, I've managed to produce an ugly working hack.
You'll have to install python-setuptools and pip manually under the Linux subsystem. Be sure to use the pip version provided by PyCharm, you'll find it at a path similar to:
C:\Program Files (x86)\JetBrains\PyCharm 2016.1.2\helpers\pip-7.1.0.tar.gz
Then setup the following script as "python.bat" under "c:\Python" and point PyCharm to it as an interpreter:
#echo off
#setlocal enableextensions enabledelayedexpansion
:: Requiers pip and setuptools to already be installed on linux subsystem
Set "Pattern= "
Set "Replace=\ "
Set "cdrive=C:"
Set "linpath=/mnt/c"
:: Iterate over arguments, convert paths to linux format and concatinate
set argCount=0
for %%x in (%*) do (
set /A argCount+=1
set arg=%%x
:: Backward slash to forward slash
SET arg=!arg:\=/!
:: C drive to /mnt/c/ - default linux subsystem mount point
SET arg=!arg:%cdrive%=%linpath%!
:: Space to escaped space
SET arg=!arg:%Pattern%=%Replace%!
:: Parethesis to escaped parenteses
SET arg=!arg:^(=\^(!
SET arg=!arg:^)=\^)%!
:: Deqoute voodoo via http://ss64.com/nt/syntax-dequote.html
SET arg=###!arg!###
SET arg=!arg:"###=!
SET arg=!arg:###"=!
SET arg=!arg:###=!
if "!args!"=="" (
set args=!arg!
) else (
set args=!args! !arg!
)
)
:: Dump it to the interpreter
:: Output is piped inside the Linux subsys, as windows piping for bash seems broken
START "Terrible hack to avoid pipe error" /W /MIN C:\Windows\System32\bash.exe -c "python !args! > /mnt/c/Python/test"
:: Output resulr from piped file
type c:\Python\test
:: echo !args!
EXIT /B > NUL
Forgive the terrible coding style, as I've never really developed windows batch files before.
You may have to tweak the directory structure to match your system. Also note that the output of any python script called by Python.bat is piped to a temp file under the linux subsystem, then typed back out under windows. For some reason, piping the output of bash.exe via windows causes errors.
Hope this helps.
UPDATE: Wrapped the call to "bash" with "START" in order to avoid terrible pipe handling errors (c.f. https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13425768-allow-windows-programs-to-spawn-bash)
Supported via remote int. See last comment: https://youtrack.jetbrains.com/issue/PY-19129
Configure remote interpreter via WSLÂ #
Open the Add Python Interpreter dialog by either way:
When you're in the Editor, the most convenient way is to use the Python Interpreter widget in the Status bar. Click the widget and select Add Interpreter ...
If you are in the Settings/Preferences dialog (Ctrl+Alt+S), select Project | Project Interpreter. Click The Configure project interpreter icon and select Add.
In the left-hand pane of the dialog, click WSL.
Use Anaconda:
.\rootfs\home\$UserName$\anaconda\envs\$Conda_Env$\bin\python3
Use Pyhton:
Adding a WSL interpreter
Select the Linux distribution and specify the path to the python executable in the selected Linux distribution.
Once done, the new interpreter will be added to your project, and the default mnt mappings will be set.
Newly added WSL interpreter
Note that with WSL you cannot create virtual environments: all packages you install will be added to the corresponding system interpreter. You will be asked to enter your sudo password.
Entering your sudo password
Reference:
JetBrains
I used the normal remote ssh intepreter "old method" discussed in this link here:
I used this guide:
critically I was getting an authentication error which was resolved with this:
I'm making Python software using wx GUI library but was wondering how to run this script on different OS's. For example, do I need to create executable installation file or bat file on Windows and sh file in Ubuntu?
I've got #!/usr/bin/env python at the top of the file and I can seem to run it by actually double clicking it and clicking it on "RUN" on prompt window but I would like it to be more professional as the users are not programmers.
Being used to run python scripts on both linux and Windows environments, I know that you can use the same script for both environments.
Keep using your shebang in Linux, it won't be procesed in windows (as it is actually a comment :).
Once Python is installed in Windows, you can actually simply double click on the script (it will run by default in a cmd window), run it using the cmd or launch it in idle.
If you want to develop python scripts on windows however, you'll need some more tools :).
If you want to be more professional (and prevent your users to modify the code :), you can still think about creating an exe file : http://www.lyxia.org/blog/developpement/python/creez-des-executables-46
(warning, french inside), by using pyinstaller http://www.pyinstaller.org/ . Works for windows and linux
I'm making a Python package that gets installed with a setup.py file using setuptools.
The package includes a GUI, and when it's installed on a Windows machine, I want the installation to make a folder in "Programs" in the start menu, and make a shortcut there to a pyw script that will start the GUI. (The pyw think works on all platforms, right?)
On Mac and Linux, I would like it to put this shortcut in whatever Mac and Linux have that is parallel to the start menu.
How do I do this?
Linux systems typically do not use a .pyw extension for executable applications (though you could if you wish). Traditionally, a python (or perl, bash, etc) script on Linux has no file name extension, has execution permissions, and begins with the 'magic' line "#!/usr/bin/python'. The '#!' lets the OS know that this is a script requiring an interpreter and the following path denotes the interpreter to use.
As for adding the desktop shortcut, freedesktop.org hosts the specifications for how menus work for modern Linux desktops. Specifically, the one you'll be most interested in is the one for Desktop Entries though the one on Menu Generation may also be of interest.
InnoSetup allows you to create shorcuts in the windows start menu. You can add even an uninstall icon.
The relevant sections of the innosetup file are:
UninstallDisplayIcon={app}\myico.ico
[Icons]
Name: "{group}\MyPrograms"; Filename: "{app}\miexe.exe" ;WorkingDir: "{app}"; Comment: "miexe program"
for Mac and Linux I can not help
Take a look at how the post-install script for pywin32 does it (search for shortcut). Not sure about Mac/Linux.
Since setuptools doesn't seem to give an easy solution to this, I've decided to give up on this idea until I release my app with py2exe/InnoSetup.
For windows, conda uses menuinst https://github.com/ContinuumIO/menuinst