- How do you run a python script from within notepad++? [duplicate]
- 6 Answers 6
- possible to use pdb too
- Linked
- Related
- Hot Network Questions
- Run Python in Notepad++
- Run Python File Using Run Option in Notepad++
- Run Python File Using PyNPP Plugin in Notepad++
- Related Article — Python Run
- Notepad++ Run Python Script: A Completed Guide – Python Tutorial
- Preliminary
- Create a python file
- Press Run or F5 on the notepad++
- Set the path of python script
- Save command
How do you run a python script from within notepad++? [duplicate]
When I’m using textmate, I simply hit «apple+r» and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for «Run», but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.
Hi Chad, is the top answer acceptable to you? If so, please mark it as such or provide further specs.
6 Answers 6
Plugins NppExec Execute ( F6 ) is much more powerful than plain Run ( F5 ). Install NppExec via Plugins, Plugin Manager. Then in F6 add/save the following:
NPP_SAVE cd "$(FULL_CURRENT_PATH)" C:\Python34\python.exe -u "$(FULL_CURRENT_PATH)"
In Plugins NppExec Console output filters ( Shift + F6 ) add the following HighLight mask:
Make sure it’s checked, and make it e.g. red and underlined.
Upon » F6 /execute» errors will be highlighted and clickable !
This works in NPP568, possibly older.
Works for me (php in my case), and is (double-)clickable, BUT double-clicking only navigates the specified line number in the active file, it doesn’t open the file indicated by %ABSFILE%. This makes clickability almost useless when working on library scripts.
To make this work for syntax errors (as well as runtime errors) use *File «%ABSFILE%», line %LINE% . The , in* part won’t match on syntax errors as they don’t mention the module where the error occurs.
If you want to make this super convenient, you can also set up a console shortcut like so: npe_cmdalias p = python «$(FULL_CURRENT_PATH)» . This means you can simply popup the console view, type p and your script will run.
You need to pass through the FULL_CURRENT_PATH environment variable to the program, as described in the notepad++ wiki:
You can use PyNPP Plugin (https://github.com/mpcabd/PyNPP) to achieve this.
I know this is old but the answer is for people coming from search.
possible to use pdb too
The answers above were very useful to get it working. However, once i could run the python programs, I also needed to interact with them. Two things I found out.
- Use «python -u -i $(FULL_CURRENT_PATH)» if you wish to interact with your program (like giving command line inputs).
- to use the awsome PDB, use «python -u -m pdb $(FULL_CURRENT_PATH)» and then you can easily debug your programs as well. 🙂 loving it!!
if u have the NppExec plugin (is by default) hit F6 and add the command that exec your script
Unless I’m missing something, the other answers discussing NppExec do not provide a way to run the script with a single keystroke or (the execute dialogue box always pops up when F6 is pressed which must be accepted before the script is run).
After completing the steps in bjornhb’s answer the following will allow you to run scripts with just one keystroke:
- Under Plugins->NppExec->Advanced Options create a new Menu Item. I simply named mine Python. Select the script which was saved earlier in the Associated script dropdown box and click Add/Modify . Click OK .
- Restart Notepad++
- Under Settings->Shortcut Mapper click the Plugin commands tab at the top. Scroll down and find your command name on the left hand side. Double click inside the white box in the Shortcut column next to your command name. Select an appropriate key (or combination) and accept. Pressing the shortcut key(s) will run the script without further input.
Linked
Related
Hot Network Questions
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.21.43541
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Run Python in Notepad++
- Run Python File Using Run Option in Notepad++
- Run Python File Using PyNPP Plugin in Notepad++
As we all know, Notepad++ is a great editor. Many people prefer this text editor for writing and executing their code. It supports various programming languages, including the Python programming language. But many people face challenges or get stuck while running the Python file inside the notepad++ text editor. So, Let’s see how to execute or run a Python file inside the notepad++.
Run Python File Using Run Option in Notepad++
To run the Python file from the notepad++ text editor, you have to click on the Run option from the menu and then choose the first option — Run. from the dropdown menu.
It will open a new window on the screen, as shown below. Alternatively, You can also press the F5 key on the keyboard to open this window.
In the The Program to Run dialog box, enter the below command and click on Run .
C:\Python39\python.exe -i "$(FULL_CURRENT_PATH)"
The First parameter, C:\Python39\python.exe , is the location where Python is installed on the system. And the last parameter is the current path of the file which you want to run. You don’t have to specify the file path; Python will automatically detect the file path you are currently running with $(FULL_CURRENT_PATH) .
Here, -i is optional. If you want to keep the command line window open even after the execution of the file, then use this option.
After that, it will open a command line window inside which your file will be executed, as shown below.
Run Python File Using PyNPP Plugin in Notepad++
You can also run Python programs with the help of a plugin provided by a notepad++ text editor called PyNPP. For that, first, go to Plugins and select Plugins Admin. from the dropdown.
A dialog box will open, as shown below. Now in the search box, search for PyNPP plugin. Below you will see a list that will contain the plugin’s name and their version number. Just check the checkbox beside the PyNPP plugin name.
After that, click on the Install button present at the top right corner of the dialog box.
Now another dialog box will open up, so click Yes . This will restart the notepad++ editor and install the PyNPP plugin.
Now that we have successfully installed the plugin, we can run the file by pressing the Alt + Shift + F5 keys simultaneously on the keyboard. As soon as you press these buttons, a terminal window will be opened up, which will show you the output of the file as shown below.
Sahil is a full-stack developer who loves to build software. He likes to share his knowledge by writing technical articles and helping clients by working with them as freelance software engineer and technical writer on Upwork.
Related Article — Python Run
Notepad++ Run Python Script: A Completed Guide – Python Tutorial
Notepad++ is a powerful editor, it is also a python editor for python programmers. In this tutorial, we will introduce how to edit and run python script by it.
Preliminary
You should install Notepad++ and python first.
To install python, you can read this tutorial:
Create a python file
You should open notepad++ and create a python script, here is an example:
import time text = 'this is https://www.tutorialexample.com' print(text) time.sleep(5)
Then we will introduce how to run this python script by notepad++.
Press Run or F5 on the notepad++
You can start to clicking run or press F5 to start to run python script.
Set the path of python script
As to our python environment, the absolute path of python.exe is:
Then you can add this string in the input box below:
C:\Users\fly165\.conda\envs\py3.6\python.exe $(FULL_CURRENT_PATH)
Where $(FULL_CURRENT_PATH) represents the current file, which means if you want to run a python script, you should foucs on this file.
Moreover, if the type of current file is not .py , you will can not run it.
Save command
We can save our command that runs python script with the name: Run Python .
Then you can Press Alt+F7 to run python script on notepad++.
In this tutorial, the resutl of python script is: