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
Related
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.
I downloaded this tool to migrate MySQL to PostgreSQL: https://github.com/philipsoutham/py-mysql2pgsql
Python interactive code works properly so the python path is set in the right way.
When I type "py-mysql2pgsql" being in the directory: C:\Users\me, the downloaded tool doesn't run but ask me to choose the program to open that file. The same situation when I'm in C:\Users\me\py-mysql2pgsql
How can I run this tool properly?
Windows does not understand shebang lines in scripts (#!/usr/bin/env python) like Linux and Unix variants do. So Windows does not understand that this is a python script, you need to execute python yourself.
If python executable is in your path, you should be able to run:
python py-mysql2pgsql
If it is not in your path, you should be able to run:
path_to_python\python py-mysql2pgsql (on my machine C:\Python27\python)
Note that this applies to any python script on Windows, not just this tool.
I've downloaded Eclipse Indigo in preparation of using it to write apps in Python. There doesn’t seem to be an install file. When I double-clicked eclipse.exe the program just ran. Can I move the Eclipse directory anywhere I want it, create a shortcut and place it on my taskbar, and start writing programs?
I put the Eclipse directory in my Path statement, and tried to run it from the command line. It won’t run anywhere but in the Eclipse directory. I already have Python 3.2 installed and it does run anywhere from the command line. Will Eclipse automatically find my Python executable or do I have to do something else?
The instructions are pretty clear ... and pretty simple:
Install your JDK on Win7 (I'd choose the 64-bit JVM for 64-bit Windows, but 32-bit will work on 64-bit Windows equally well)
Unpack the "eclipse" folder from the .zip file anywhere you want. Mine happens to be in c:\eclipse.
Manually create a desktop and/or start menu link to eclipse/eclipse.exe
Here's a great reference on "PyDev":
http://www.vogella.com/articles/Python/article.html
I'd also encourage you to install the latest/greatest Eclipse ("Juno") instead of Indigo.
Okay, I'm completely new to this.
I created a python script that imports tkinter. On my Ubuntu, I can execute the program from the terminal program. Till now there is no problem. However, my friends asked if I could deliver the program to them so that they could use it on their PC. They have 0 knowledge of programming and they use Windows -.-. So my question is, how I can create an executable file from Ubuntu so that it can run under Windows? I've already read something about py2exe, but I could not manage installing it. If
You can't use py2exe on plain Ubuntu. It needs to run from Windows. Right now, py2exe doesn't work well with Wine. Do you not have access to any Windows computers (maybe one of your friends')?
You can also get your friends to install Python on their Windows machines and teach them how to run your programs, if you're willing to put in the extra effort.
Can anyone please tell me an IDE for running python programs? Is it possible to run the program through command line?
Take a look at ActiveState's ActivePython. It's quite a nice implementation of Python on Windows. Another way is using Cygwin's Python port. These two are Python implementations. I don't use an IDE, I write my Python code in Notepad++.
To run a python program after saving it to C:\Users\vaibhav\Code\myscript.py:
ActivePython: If I remember right, ActiveState updates the path correctly. So it should be a s simple as:
Press "start" in the task bar
In the search field search for "cmd"
In the appearing box navigate to your folder with the python script: dir Users\vaibhav\Code
call python myscript.py and you're done
Cygwin: After installing Cygwin, you have a full-featured bash terminal on your Windows machine.
click on the Cygwin icon on your desktop
In the appearing window navigate to the folder with your python script: cd /cygdrive/c/Users/vaibhav/Code
type python myscript.py
e voila
IDE for running scripts? You can have any IDE you like, but if you need only to run python scripts you go like this:
python.exe pythonScript.py
I like the EasyEclipse for python distribution. You'd need to have python and java installed of course.
PyDev and Komodo Edit are 2 nice Python IDE on Windows.
I also like the SciTE text editor very much.
These 3 solutions make possible to run Python scripts
I tried to run a Python script with multiprocessing on windows. see this tutorial
It does not work on Windows, but on raspian it went very well. Thus I knew that it was a Windows problem. I installed cygwin and followed this tutorial Installing Python inside Cygwin.
After that I additionally installed numpy with the command easy_install numpy and now i can run python scripts with multiprocessing on windows (from cygwin).