ImportError: no module named Tkinter (Running python with NotePad++'s NppExec)

Sam Westrick picture Sam Westrick · Nov 6, 2011 · Viewed 17.3k times · Source

I'm trying to run a python file using Notepad++'s NppExec plugin. My file attempts to import Tkinter using the line "from Tkinter import * ". With NppExec, I run the following script:

python "$(FULL_CURRENT_PATH)"

or sometimes

python -i "$(FULL_CURRENT_PATH)"

In either case, I get the error "ImportError: No module named Tkinter". I find this odd, because if I run my python file using any other method (IDLE, directly from command line, or even with Npp's built in Run function), I get no errors, and Tkinter imports correctly.

I'm running Windows 7, if it makes a difference.

Thanks in advance for your help! -Sam

Answer

Bryan Oakley picture Bryan Oakley · Nov 6, 2011

The problem is simple -- the python command you are running does not have a module named Tkinter. The cause of the problem is more difficult to understand without more information. My first guess would be that NppExec is running a different version of python than you think it is running, and this version of python either doesn't have tkinter installed, or has it installed under a different name (python 2 is Tkinter and python 3 is tkinter).

Try using NppExec to run a script that does the following:

import sys
print sys.executable
print sys.path

The output from those commands should give you enough information to debug the problem.