I really like Geany for writing Python code. When I click F5, it opens system's default terminal window and executes the code there.
There is also a terminal inside Geany window, the bottom pane and the last tab. What I want is the code to be executed there. Is it possible?
After fiddling with the options, I found the way:
Right-click on terminal area and select "Preferences". It opens the general preferences window with Terminal tab opened.
There is an option: "Execute programs in the VTE". Checking this option does what I want.
if you are at the location of your file, just type python in that terminal.
Related
I had saved a python file after working on it for sometime, but now when I open it, Python 3.9.1 opens a window then immediately closes. I had done lots of work on this and don't want it to go to waste. I'm on Windows 10.
If you’re using the Open option when you right-click or you are simply double-clicking the script, the program will run and close so fast you won’t even see it.
Here are two options I use:
Open up the Command Prompt. You can easily do this by going to the address bar of your File Explorer and enter ‘cmd’. If you’re in the directory where your script is, the current working directory of the Command Prompt will be set to that. From there, run python my_script.py.
Edit your script with IDLE. If you’re using an IDE, it should be nearly the same process, but I don’t use one so I wouldn’t know. From the editor, there should be a method for running the program. In IDLE, you can just using Ctrl + F5.
Right click on it and clicken "open with". Then choose Python IDLE.
You are trying to run the file instead of editing it.
You have to right-click the file and you should the "edit with idle" option.
Is there a way to differentiate between a .py file launched by double-clicking its icon in Windows versus typing myscript.py in an existing command prompt window? My code ends with os.system("pause") so that I can see the results when double-clicking to launch, but that line should be ignored when running it in a persistent window.
I would first recommend you to go to advanced settings of your Windows Explorer and activate the "show extensions" options if that can help.
For more information about your question, you can also check this link :
https://automatetheboringstuff.com/appendixb/
I have a python file named "python_file.py" and I want to run it with a command line such as "python python_file.py" by typing it in the terminal, and not in the python console. I succeed one time, but when I change my working directory, it no longer works.
When I tried, it displays something like "python isn't known as a intern program, a runnable program or a command file".
And I'm using Python 3.7.
Can someone help me ?
You need to create a run/debug configuration, as explained in the official help:
Click on the button left of the green arrow symbol (the green arrow might be greyed out, but that's fine):
Click on Edit Configurations.
Click on the + symbol
Click on Python.
On the right side, enter/activate the following:
Name (a string that describes your according project)
Single instance only (this is less complicated for you)
Click on the Configuration tab.
Select a type of target from the Script path/Module name
Enter the path to your Python script in the according box.
Select the Python interpreter (Python 3.x will be fine).
In the Execution section, select either Emulate terminal in output console or Run with Python console.
Apply the changes and close the dialog.
Click on the button left of the green arrow symbol to run your program from the internal command line.
I have installed Python and written a program in Notepad++.
Now when I try to type the Python file name in the Run window, all that I see is a black window opening for a second and then closing.
I cant run the file at all, how can run this file?
Also I want to tell that I also tried to be in the same directory as a particular Python file but no success.
I assume you are running the script with command python file_name.py.
You can prevent closing of the cmd by getting a character from user.
use raw_input() function to get a character (which probably could be an enter).
It sounds like you are entering your script name directly into the Windows Run prompt (possibly Windows XP?). This will launch Python in a black command prompt window and run your script. As soon as the script finishes, the command prompt window will automatically close.
You have a number of alternatives:
First manually start a command prompt by just typing cmd in the Run window. From here you can change to the directory you want and run your Python script.
Create a Windows shortcut on the desktop. Right click on the desktop and select New > Shortcut. Here you can enter your script name as python -i script.py, and a name for the shortcut. After finishing, right click on your new shortcut on the desktop and select Properties, you can now specify the folder you want to run the script from. When the script completes, the Python shell will remain open until you exit it.
As you are using Notepad++, you could consider installing the Notepad++ NppExec plugin which would let you run your script inside Notepad++. The output would then be displayed in a console output window inside Notepad++.
As mentioned, you can add something to your script to stop it completing (and automatically closing the window), adding the line raw_input() to the last line in your script will cause the Window to stay open until Enter is pressed.
Try to open in Command Prompt instead of run window. The syntax is:
py filename.py
If it doesn't work, try to reconfigure Python. Did you set environment variables? If not, this could help you
I'm using Geany 0.18 for python developing and am in general really satisfied, but there is one little thing, that's still bugging me:
I usually use the F5 (Build-->Execute) option to test my scripts, the appearing window is rather small, and if my script prints lines which are too long they are hard to read. I would like to change the default-window size of the little one popping up if I hit F5, but I haven't found anything to accomplish this.
Is this possible at all ?
Thanks
Mischa
To solve that problem I added additional parameters to terminal command that geany runs.
In Geany go to preferences (Edit->Preferences).
Open Tools tab.
There is an input field named Terminal where you can specify terminal program to use.
I changed that to "gnome-terminal --maximize" to open terminal maximized.
For Gnome-Terminal you can find more window options running "gnome-terminal --help-window-options" from terminal.
In the window that pops up (if using windows) click on the white bar at the top (right click) this will open a menu, choose defaults then change font/font size etc.