Install python (2.7.3)
- Download the python 2.7.3 windows installer from http://www.python.org/download/
- Run through the installer using the default settings for everything. It should install python in the folder: C:\Python27. If you're using a different version of python, just substitute out the version number wherever you see 27.
Install Notepad++
- From http://notepad-plus-plus.org/download, download the Notepad++ installer.
- Run through the installer using the default settings for everything.
- Open Notepad++
Configure Notepad++ to run a python script
- Open up a command prompt
- Run the following command:
set PATH=%PATH%;C:\Python27
You can use the following command to make sure the python path was added to the PATH variable:
echo %PATH%
You should see the location of the python directory at the end of the output.
- Switch back to Notepad++, and go up to the menu bar, select Run, and then select Run... (F5)
- Insert the following in the text box that appears:
C:\Python27\python.exe -i "$(FULL_CURRENT_PATH)"
- Click Save...
- Configure CTRL+R to be the command. Give it a name, and press OK.
Now whenever you want to run the python script you're working on, press CTRL+R and it will be executed. Also you should see the window stay opened after command execution for debugging purposes because of the -i flag. Remove it if you don't want that feature.
I have a little problem -- I am loading an image from "data/img.png". If I run this in IDLE, it works. But when I try it in N++, it require full path ("C:/python27/pjcts/data/img.png"). Can u help me please?
ReplyDeletePathing on windows is a little off. I typically use the following code to navigate to the current directory, and then locate a file:
Deleteimport os
mypath = os.path.dirname( os.path.realpath( __file__) )
image_path = os.path.join(mypath, 'data/img.png')
Ok, I will try it. Thanks :)
DeleteCORRECTION:
Deleteset PATH=%PATH%;C:\Python33
is the correct command line. You forgot the "=". Thanks for your post.
Edited! Thanks for the correction.
DeleteYou're welcome. Looked all over Google. Yet I can't seem to make it work. I did all you said. I'm trying to run a simple search/replace script called scriptest.py containing only
Delete# Python regular expressions search and replace
editor.pyreplace(r"old", r"new")
on a textfile.txt file opened in Notepad++.
I just don't find out how to make it work. if my script is correct, which notepad tab I should let open, if i should call for
notepad.open('textfile.txt') in the script.
if Full_CURRENT_PATH is a variable and should be changed by the exact path and to what? the script? or leave it litteral as is. If you can help. thanks a lot.
Full_CURRENT_PATH should be literally entered as shown, and try to run it on a simple print statement to see if it works.
DeleteI've never tried using it to edit the current open document. I would create a path to that text file like I mentioned to the other guy above.
Thanks. simple print statement? I don't understand anything after. It is really not clear what is variable and depending on our case or not. and the "-i" parameter does not let the debug log window opened so I don't know squat of what's going on. It closed instantly. My test.py and textfile.txt are in their own folders. (I don't like to put my files in the program directories). I just can't manage to make anything work. my case seems so trivial. I'm disappointed by the complexity of this. this is a nightmare. I just want the trivial change/replace script for a document with notepad. noone seems able to explain such trivial task. desperate!
DeleteThere is a solution here: http://npppythonscript.sourceforge.net/
Deleteuse FULL_CURRENT_PATH instead of Full_CURRENT_PATH
DeleteThanks, simple typo. It's fixed now.
DeleteWorks, 10x!!
ReplyDeleteThis works, but it opens a new instance of python.exe every time I run the code. I want it to run the code within the same black box...Any ideas please?
ReplyDeletekhave, use the cool IDE PyScripter.
ReplyDeleteThank you very much!
ReplyDeleteFor some reason my Notepad forgets this saved path each time - would entering "set PATH=%PATH%;C:\Python27" into the CMD prmopt make any difference?
ReplyDeleteIt should stay in your environment path unless that's getting cleared somehow. I'm not sure, but I've since switched from notepad++ to Sublime Text.
DeleteThanks guy, being new in python this post has really helped me. KUDOS!
ReplyDeletewhen I hit the button ctrl + R to run, the output screen comes and goes off in a flash. Can't look at the output.
ReplyDeleteGreat, never knew Notepad++ does this!
ReplyDeleteThanks. I wish I would've decided to look this up before doing over a half of course on Python.
ReplyDeleteIs there a way to add the save command before executing the program?
ReplyDeleteI have a problem with my editor. When I run a python code, my command line pops up for a second and then automatically gets closed.
ReplyDeleteThanks so much, it is working
ReplyDeleteWhenever i run it a black box comes up and then vanishes so fast any help please?
ReplyDeleteBet365 Casino | Claim Your Bonus Now | Deposit £10
ReplyDeleteAs a result, titanium hair we know that you can win at edc titanium bet365 Casino in 2021! Find out if w88 the casino titanium tools has 벳 인포 an exclusive sign up bonus and you can get up to £30 free