[Solved] Need help setting up Geany for Python (or sublime text)

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
matt7137
Level 1
Level 1
Posts: 28
Joined: Mon May 19, 2014 5:18 pm

[Solved] Need help setting up Geany for Python (or sublime text)

Post by matt7137 » Sat Mar 31, 2018 5:43 pm

*** For me the solution that worked is in my last post. But please read all the posts.***

I'm trying to learn very basic python.

print("Hello World!")
I can do this in Idle, but I can't seem to get it to work in Geany.
I'm lost.
In geany I changed the build commands: python3 -m py_compile "%f" and python3 "%f".
I also sudo into the config filetypes.python and changed it in there.

I have a terminal open, I type python3 get the chevrons, then I open geany type the code, save, then F5, but
nothing happens. Where is it suppose to execute? Am I suppose to get a pop-up window? In the tab that says Terminal?

I thought about Sublime Text, but it's my understanding it doesn't work well if you need user input.
If I copy the code and paste it into another text editor, the indentations look wrong. But idle seems "live",
so if I have an if statement that says print, it does it right a way. I don't like that.

Thanks
Last edited by matt7137 on Mon Apr 02, 2018 2:59 pm, edited 1 time in total.

User avatar
xenopeek
Level 24
Level 24
Posts: 24188
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Need help setting up Geany for Python (or sublime text)

Post by xenopeek » Sun Apr 01, 2018 9:26 am

I think you're doing things you don't need to do. When I write a simple hello world in Geany, I can just click the Run button (the cogwheel icon) to run it in a terminal that pauses after the program completes. No need to configure anything.

py_compile, as per the documentation, can sometimes be useful for compiling modules. It is not used normally and certainly not for programs. Python compiles programs when they are run. You don't need to compile them yourself. It's a scripting language, you can just run programs from their source file (the text file in which you saved the code).

Here's me running hello world without configuring anything in Geany (click to enlarge):
Image

I suggest you reset Geany's configurion by closing the program and then opening a terminal and running this command:
rm -rfv ~/.config/geany

When you write a Python 3 program you must use a hashbang line to indicate what it is. The hashbang for Python 3 is:
#!/usr/bin/python3

So the complete hello world program is:

Code: Select all

#!/usr/bin/python3

print("hello world")
Image

matt7137
Level 1
Level 1
Posts: 28
Joined: Mon May 19, 2014 5:18 pm

Re: Need help setting up Geany for Python (or sublime text)

Post by matt7137 » Sun Apr 01, 2018 2:22 pm

I thought it was because I forget the shebang. That didn't help. I did as you said, I even uninstalled Geany, then used software manager to install Geany, but I still get nothing.
I saw a video where the guy imported sys, then print(sys.version), and got some feedback. I still get nothing after clicking the cog wheel or F5, repeatedly.
which python3 in Terminal says /usr/bin/python3
Screenshot
GeanyScreenshot.png

User avatar
xenopeek
Level 24
Level 24
Posts: 24188
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Need help setting up Geany for Python (or sublime text)

Post by xenopeek » Sun Apr 01, 2018 4:04 pm

Did you reset the configuration as I suggest you do with the command for that? Uninstalling and reinstalling programs, unlike on Windows, doesn't do anything for user settings on Linux. User settings are never touched by uninstalling or installing programs. So if you need to reset the settings of some program you need to manually do that (either by some option the program has it, or as in this case by just deleting its config directory).

If you did run the command I gave to delete the configuration, what Linux Mint version are you using? I tested above with Geany on Linux Mint 18.3.
Image

matt7137
Level 1
Level 1
Posts: 28
Joined: Mon May 19, 2014 5:18 pm

Re: Need help setting up Geany for Python (or sublime text)

Post by matt7137 » Sun Apr 01, 2018 7:42 pm

I did do the force remove config file. Doesn't the v stand for tell me what's it doing? I got nothing. When I do a ls -al ~/config/geany I get no such file. Even after loading a .py file. I do have a geany.conf in that folder. See below.

My built commands are python3 -m py_compile "%f" and python3 "%f".
I'm running Mint 18.3 64 bit.

This is a copy from the ~/usr/geany/geany.conf

Code: Select all

[geany]
default_open_path=
cmdline_new_files=true
notebook_double_click_hides_widgets=false
tab_close_switch_to_mru=false
tab_pos_sidebar=2
sidebar_pos=0
symbols_sort_mode=0
msgwin_orientation=1
highlighting_invert_all=false
pref_main_search_use_current_word=true
check_detect_indent=false
detect_indent_width=false
use_tab_to_indent=true
pref_editor_tab_width=4
indent_mode=2
indent_type=1
virtualspace=1
autocomplete_doc_words=false
completion_drops_rest_of_word=false
autocompletion_max_entries=30
autocompletion_update_freq=250
color_scheme=
mru_length=10
disk_check_timeout=30
show_editor_scrollbars=true
brace_match_ltgt=false
use_gtk_word_boundaries=true
complete_snippets_whilst_editing=false
use_atomic_file_saving=false
gio_unsafe_save_backup=false
use_gio_unsafe_file_saving=true
keep_edit_history_on_reload=true
show_keep_edit_history_on_reload_msg=false
indent_hard_tab_width=8
find_selection_type=0
extract_filetype_regex=-\\*-\\s*([^\\s]+)\\s*-\\*-
replace_and_find_by_default=true
show_symbol_list_expanders=true
compiler_tab_autoscroll=true
allow_always_save=false
statusbar_template=line: %l / %L	 col: %c	 sel: %s	 %w      %t      %mmode: %M      encoding: %e      filetype: %f      scope: %S
new_document_after_close=false
msgwin_status_visible=true
msgwin_compiler_visible=true
msgwin_messages_visible=true
msgwin_scribble_visible=true
documents_show_paths=true
sidebar_page=0
pref_main_load_session=true
pref_main_project_session=true
pref_main_project_file_in_basedir=false
pref_main_save_winpos=true
pref_main_confirm_exit=false
pref_main_suppress_status_messages=false
switch_msgwin_pages=false
beep_on_errors=true
auto_focus=false
sidebar_symbol_visible=true
sidebar_openfiles_visible=true
editor_font=Monospace 14
tagbar_font=Sans 12
msgwin_font=Monospace 12
show_notebook_tabs=true
show_tab_cross=true
tab_order_ltr=true
tab_order_beside=false
tab_pos_editor=2
tab_pos_msgwin=0
use_native_windows_dialogs=false
show_indent_guide=false
show_white_space=false
show_line_endings=false
show_markers_margin=true
show_linenumber_margin=true
long_line_enabled=true
long_line_type=0
long_line_column=72
long_line_color=#C2EBC2
symbolcompletion_max_height=10
symbolcompletion_min_chars=4
use_folding=true
unfold_all_children=false
use_indicators=true
line_wrapping=false
auto_close_xml_tags=true
complete_snippets=true
auto_complete_symbols=true
pref_editor_disable_dnd=false
pref_editor_smart_home_key=true
pref_editor_newline_strip=false
line_break_column=72
auto_continue_multiline=true
comment_toggle_mark=~ 
scroll_stop_at_last_line=true
autoclose_chars=0
pref_editor_default_new_encoding=UTF-8
pref_editor_default_open_encoding=None
default_eol_character=2
pref_editor_new_line=true
pref_editor_ensure_convert_line_endings=false
pref_editor_replace_tabs=false
pref_editor_trail_space=false
pref_toolbar_show=true
pref_toolbar_append_to_menu=false
pref_toolbar_use_gtk_default_style=true
pref_toolbar_use_gtk_default_icon=true
pref_toolbar_icon_style=0
pref_toolbar_icon_size=0
pref_template_developer=matt
pref_template_company=
pref_template_mail=matt@matt-desktop
pref_template_initial=m
pref_template_version=1.0
pref_template_year=%Y
pref_template_date=%Y-%m-%d
pref_template_datetime=%d.%m.%Y %H:%M:%S %Z
context_action_cmd=
sidebar_visible=true
statusbar_visible=true
msgwindow_visible=true
fullscreen=false
scribble_text=Type here what you want, use it as a notice/scratch board
scribble_pos=57
treeview_position=217
msgwindow_position=614
geometry=0;0;1920;1001;1;
custom_date_format=

[build-menu]
number_ft_menu_items=0
number_non_ft_menu_items=0
number_exec_menu_items=0

[search]
pref_search_hide_find_dialog=false
pref_search_always_wrap=false
pref_search_current_file_dir=true
find_all_expanded=false
replace_all_expanded=false
position_find_x=-1
position_find_y=-1
position_replace_x=-1
position_replace_y=-1
position_fif_x=-1
position_fif_y=-1
fif_regexp=false
fif_case_sensitive=true
fif_match_whole_word=false
fif_invert_results=false
fif_recursive=false
fif_extra_options=
fif_use_extra_options=false
fif_files=
fif_files_mode=0
find_regexp=false
find_regexp_multiline=false
find_case_sensitive=false
find_escape_sequences=false
find_match_whole_word=false
find_match_word_start=false
find_close_dialog=true
replace_regexp=false
replace_regexp_multiline=false
replace_case_sensitive=false
replace_escape_sequences=false
replace_match_whole_word=false
replace_match_word_start=false
replace_search_backwards=false
replace_close_dialog=true

[plugins]
load_plugins=true
custom_plugin_path=
active_plugins=;

[tools]
terminal_cmd=/bin/bash
browser_cmd=/usr/bin/firefox
grep_cmd=grep

[printing]
print_cmd=lpr '%f'
use_gtk_printing=true
print_line_numbers=true
print_page_numbers=true
print_page_header=true
page_header_basename=false
page_header_datefmt=%c

[VTE]
load_vte=true
emulation=xterm
send_selection_unsafe=false
send_cmd_prefix=
font=Monospace 12
scroll_on_key=true
scroll_on_out=true
enable_bash_keys=true
ignore_menu_bar_accel=false
follow_path=false
run_in_vte=false
skip_run_script=false
cursor_blinks=false
scrollback_lines=500
image=
shell=/bin/bash
colour_fore=#FFFFFF
colour_back=#000000
last_dir=/home/matt

[project]
session_file=
project_file_path=/home/matt/projects

[files]
recent_files=/home/matt/Desktop/Linux_PDFs/AAA do this first/HelloWorldinGeany.py;/home/matt/Desktop/Linux_PDFs/AAA do this first/user_input.py;/home/matt/Desktop/Linux_PDFs/AAA do this first/HelloWorldTestInSublimeText3.py;/home/matt/Desktop/Linux_PDFs/AAA do this first/GuessTheNumber.py;/home/matt/Desktop/Linux_PDFs/AAA do this first/tryingHelloWorldSublimeText.py;/home/matt/environments/hello.py;/home/matt/Desktop/Linux_PDFs/AAA do this first/spiral.py;
recent_projects=
current_page=0
FILE_NAME_0=73;Python;0;EUTF-8;1;1;0;%2Fhome%2Fmatt%2FDesktop%2FLinux_PDFs%2FAAA%20do%20this%20first%2FHelloWorldinGeany.py;0;4

User avatar
xenopeek
Level 24
Level 24
Posts: 24188
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Need help setting up Geany for Python (or sublime text)

Post by xenopeek » Mon Apr 02, 2018 3:10 am

By default I see Geany has those build commands set for Python scripts. As noted, you don't normally ever use the build command on Python scripts. You should just run your program directly. The path to remove isn't ~/config/geany, it's ~/.config/geany. Mind the dot before config. -v on the rm command should indeed tell you which files it removes. Perhaps it already did so earlier?

I have no idea why you would have a directory ~/usr/geany/geany.conf in your home directory. Did you install Geany by downloading it from somewhere manually perhaps?

Going back to your earlier screenshot I see the Terminal tab (bottom left) is trying to catch your attention. What did it say there after running the program?

If all else fails it's perhaps time to switch to an alternative. You can just use your system's default text editor (xed) to write Python scripts. After saving it for the first time, open your file manager and right-click the file there and go to Properties > Permissions and set to allow executing the file as a program. After you've done that you can when you want to test your script just open a terminal on the directory where you have the file and run it with the command: ./filename
Image

glitchathon
Level 2
Level 2
Posts: 85
Joined: Thu Mar 17, 2011 12:27 pm

Re: Need help setting up Geany for Python (or sublime text)

Post by glitchathon » Mon Apr 02, 2018 3:24 am

Just curious what happens if you go to Preferences > Terminal > and click "Execute programs in the VTE".

Does it execute in the virtual terminal?

What is your terminal setting in Tools? Mine is: x-terminal-emulator -e "/bin/sh %c"
And my Terminal Shell setting is /bin/bash

Might want to check those settings.

matt7137
Level 1
Level 1
Posts: 28
Joined: Mon May 19, 2014 5:18 pm

Re: Need help setting up Geany for Python (or sublime text)

Post by matt7137 » Mon Apr 02, 2018 12:15 pm

I'm making some progress. You were right, I did not see the dot in front of config. After doing that I got:

rm -rfv ~/.config/geany
removed directory '/home/matt/.config/geany/tags'
removed '/home/matt/.config/geany/templates/templates.README'
removed directory '/home/matt/.config/geany/templates/files'
removed directory '/home/matt/.config/geany/templates'
removed '/home/matt/.config/geany/filedefs/filetypes.python'
removed '/home/matt/.config/geany/filedefs/filetypes.README'
removed directory '/home/matt/.config/geany/filedefs'
removed '/home/matt/.config/geany/geany.conf'
removed '/home/matt/.config/geany/keybindings.conf'
removed directory '/home/matt/.config/geany'

I had the other file in my home directory because I wanted the latest and greatest and downloaded and installed from the net and not the software manager. :(

I then went into my folder, right clicked the HelloWorld script, Geany opened, then I clicked the clog and got a pop up terminal(?), it said "Unable to find a shell."
I added the 3 after python in the build, but that didn't help.
My terminal settings in Tools is: x-terminal-emulator -e "/bin/sh %c"
and the Terminal Shell setting is : /bin/bash
When I tried Pref > Terminal > checked the box to run in VTE I got:
------------------
(program exited with code: 0)
matt@matt-desktop ~/Desktop/Linux_PDFs/AAA do this first $

My status tab just says: 11:09:36: File /home/matt/Desktop/Linux_PDFs/AAA do this first/HelloWorldinGeany.py opened(1).

If you can figure this out, remember I would like to use python3. I have both 2 and 3 installed apparently.

I'm still lost.

Thanks

User avatar
xenopeek
Level 24
Level 24
Posts: 24188
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Need help setting up Geany for Python (or sublime text)

Post by xenopeek » Mon Apr 02, 2018 12:21 pm

Have you tried it with Geany from Software Manager as well? It just works, not needing to do anything. Is a newer version of Geany that critical for learning Python 3?
Image

glitchathon
Level 2
Level 2
Posts: 85
Joined: Thu Mar 17, 2011 12:27 pm

Re: Need help setting up Geany for Python (or sublime text)

Post by glitchathon » Mon Apr 02, 2018 2:07 pm

Ah, didn't realize he installed Geany from somewhere else. I agree, the one in the software manager just works, and has worked through multiple versions of Linux Mint for as long as I remember. When I install Mint, one of the first things I do is go into Geany's build settings and change python to python3, and it always just works.

matt7137
Level 1
Level 1
Posts: 28
Joined: Mon May 19, 2014 5:18 pm

Re: Need help setting up Geany for Python (or sublime text)

Post by matt7137 » Mon Apr 02, 2018 2:57 pm

I think I solved it! I was looking on the web for solutions, someone posted change the terminal to gnome. I got my usual nice gray terminal but no output. So I fooled around some more and changed Edit > Pref > Tools > gnome-terminal -x /bin/sh %c
No quotes, and it works!
ScreenShotItWorks.png

Post Reply

Return to “Software & Applications”