Python 3 editor that works?

About programming and getting involved with Linux Mint development
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Post Reply
Petermint
Level 9
Level 9
Posts: 2990
Joined: Tue Feb 16, 2016 3:12 am

Python 3 editor that works?

Post by Petermint »

Python + GTK basic example script. My first ever attempt at Python. Geany was recommended. Geany has a nice compile button and shows a command line thing in the bottom window. There are no errors shown for the script execution when I include a deliberate error. I have to open terminal and type the compile in by hand to see errors which makes Geany no better than Xed.

Clean Python + GTK code in Terminal shows the execution plus the GTK window. Geany does not show the GTK window. Nothing.

So Geany has a nice compile button on the menu but no output! :(

Bluefish does Python but there is no default compile command. I added a command but cannot add a button to the menu to run the command. When I select the command from the Bluefish Tools option, the GTK window appears but there is no visible terminal log which means no errors displayed. I have to open Terminal and run the code by hand. :evil:

Bluefish is the best editor for all the other things I do. I just want a button on the menu to run the command and a terminal window somewhere to show the errors and any messages I print.

Geany is the next choice because it is the default in the Raspberry Pi OS. I have not tested the config there for Python. I want to do the main dev on my notebook because it is portable and I can sit at the beach tapping away then move the finished code to the Pi. If Geany cannot show the actual terminal session instead of just the fake exec line, Geany is useless.

Is there a way to make either show the terminal session and the GTK window?

Is there a similar editor that works for Python and runs efficiently on both Linux Mint plus the Raspberry Pi OS?

Update: I found the official Bluefish documentation on adding a custom button. You edit the "custom menu" using the "custom menu editor". Neither exists in the Bluefish I use which is the default version in the latest version of Linux Mint. Apparently the custom menu existed a decade ago.
Petermint
Level 9
Level 9
Posts: 2990
Joined: Tue Feb 16, 2016 3:12 am

Re: Python 3 editor that works?

Post by Petermint »

I found a Geany configuration file for Python. (I found several. I forget which one works.) The compile command contains something restricting the compile to just some sort of code test with no actual execution. :shock: Almost useless for an interpreted language. I changed the file by removing the -m py_compile bit. Now Geany works.

I do not know if editing the file that way is official Geany procedure or if there is a reason to run only the compile step. The compile step never showed any errors. Maybe there is another setting to actually show errors.
User avatar
xenopeek
Level 25
Level 25
Posts: 29657
Joined: Wed Jul 06, 2011 3:58 am

Re: Python 3 editor that works?

Post by xenopeek »

How and why are you compiling Python code? Python is an interpreted language so normally there is no compile step, you just run your program after making edits.

In Geany simply click the run button.
Image
User avatar
AndyMH
Level 21
Level 21
Posts: 13858
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Python 3 editor that works?

Post by AndyMH »

I used to use bluefish (and liked it), now I use VScode, it's better. I use it for C++ (for arduino), but there will be extensions you can add to create a python development environment - it's such an obvious target as so many people use it. I don't use python, don't like it.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
spamegg
Level 14
Level 14
Posts: 5298
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Python 3 editor that works?

Post by spamegg »

Geany is just a text editor. Not an IDE. It has a Terminal, it can execute some commands, that's it.

PyCharm works. (probably not on Raspberry Pi)
VS Code + Python extension works.
PyDev for Eclipse works.
Sublime Text + some plugins works.
Spyder works (but installation is a bit tricky).

Thonny comes with Raspberry Pi OS by default I think, in the past it was a bit buggy, maybe better these days.

Hell, you could even use Python's own built-in IDLE, although it does not offer much. But it works.
dave0808
Level 5
Level 5
Posts: 992
Joined: Sat May 16, 2015 1:02 pm

Re: Python 3 editor that works?

Post by dave0808 »

I went through a bunch of offerings when I started looking at Python and it was quite frustrating being used to the likes of Eclipse (in the past) and Android Studio. Many were too simple, didn't have decent code completion, or just didn't run properly. Also because I only use it for hobby projects, once in a blue moon, I didn't want to pay out for any professional IDE, not knowing if it was something that I would continue with.

So I tried, and dismissed, Geany, Thonny, IDLE, Eric, and another I can't remember. Settled on PyCharm, which was quite familiar to me having the same base as Android Studio. It was important to me to have interactive debugging too.
Petermint
Level 9
Level 9
Posts: 2990
Joined: Tue Feb 16, 2016 3:12 am

Re: Python 3 editor that works?

Post by Petermint »

Thank you for the suggestions. I will test one each day then report back.
How and why are you compiling Python code?
Python compiles to an intermediate code then interprets the compiled code. Just like PHP, Java, etc. The compile step might produce some simple code errors on startup. Geany was running just the compile without starting the program. My code errors did not show up in the compile.
Petermint
Level 9
Level 9
Posts: 2990
Joined: Tue Feb 16, 2016 3:12 am

Re: Python 3 editor that works?

Post by Petermint »

Thonny works better than Geany based on a quick test with my simple beginners code. I cannot use it for the other languages but as a raw beginner, the easy to use factor is a winner.

If my prowess at Python was compared to cooking, I am still learning to add water to the pot in preparation for the big lesson, How to boil water. :D
zahlman
Level 1
Level 1
Posts: 28
Joined: Mon Apr 17, 2023 12:46 pm

Re: Python 3 editor that works?

Post by zahlman »

xenopeek wrote: Thu Mar 28, 2024 3:29 am How and why are you compiling Python code? Python is an interpreted language so normally there is no compile step, you just run your program after making edits.
This is... at least inaccurate. In the reference implementation, Python is compiled to bytecode in the same sense that C# and Java are. (While C# on Windows can create a .exe file in PE format, it does not contain machine code). Python persists its bytecode by default, in files with a .pyc extension (roughly equivalent to a Java .class file). While the python program itself provides a statement-by-statement interpreter, it works by compiling and executing (in a shared global scope) each statement on demand. (This uses dynamic compilation features exposed in the standard library.) When a .py file is run as a script, generally the bytecode for that file is not persisted, but the entire file is still compiled before code starts running. It cannot partially execute before reporting a syntax error, the way that a shell script can. (Unless, of course, the code itself invokes compiler services such as by eval or exec or using certain standard library modules like ast.)
Post Reply

Return to “Programming & Development”