1

I'm trying to import the tkinter module into my script. I have it installed since the interpreter is able to import it with no problems:

C:\Users\Nacht\Dropbox\Scripts>python
Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> 

Imports fine, no problem. But now when I try to run a script that has the line import tkinter....

C:\Users\Nacht\Dropbox\Scripts>t ls
Traceback (most recent call last):
  File "C:\Users\Nacht\Dropbox\Scripts\t.py", line 5, in <module>
    import tkinter
ImportError: No module named tkinter

where t is the name of the script and ls a command (it is a command-line interface).

How can the interpreter see it but not the script? Thanks.

EDIT:

The sys.path says, for the interpreter:

C:\Python32\lib\site-packages\distribute-0.6.24-py3.2.egg
C:\Python32\lib\site-packages\selenium-2.15.0-py3.2.egg
C:\Windows\system32\python32.zip
C:\Python32\DLLs
C:\Python32\lib
C:\Python32
C:\Python32\lib\site-packages
C:\Python32\lib\site-packages\win32
C:\Python32\lib\site-packages\win32\lib
C:\Python32\lib\site-packages\Pythonwin

and for the script:

C:\Users\Nacht\Dropbox\Scripts
C:\Python27\lib\site-packages\distribute-0.6.24-py2.7.egg
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info
Nacht
  • 10,488
  • 8
  • 31
  • 39
  • 3
    what does the import path report (in both cases) i.e. `import sys; print "\n".join(sys.path)` – bjarneh Jan 31 '12 at 00:22
  • Is it possible that t.py is executing under some python 2.*, and not Python 3? Back then it was Tkinter, with a capital T. – DSM Jan 31 '12 at 00:28
  • From the way you are calling your script, I guess it is also possible that `.py` files could be associated with a different interpreter version than the one you have entered interactively. – wim Jan 31 '12 at 00:28
  • No, I'm making sure that it is python 3.2. Looking at the sys.path, it seems the issue is there. But I don't know how to fix it. EDIT: Nvm, it is using python27. But how? How can the rest of my code run when I'm using Python3.2 syntax? – Nacht Jan 31 '12 at 00:30
  • Can someone tell me how to make them automatically be associated with python32 instead of 27? – Nacht Jan 31 '12 at 00:38

2 Answers2

2

The script appears to be running with Python 2.7 but when you run the interpreter directly, it is using Python 3.2. As mentioned by @DSM, the name of Tkinter was different (perhaps there are other differences?).

jdigital
  • 11,926
  • 4
  • 34
  • 51
  • I figured it out. Windows was using python.exe to open python scripts. However, I have both Py27 and 32 installed. But because the python.exe is named the same, scripts were using the first python (27 comes before 32, so they were using 27). While my interpreter was using 32 since I added it to my %path%. I just renamed python.exe to python27.exe and made to make 32 the default to open *.py. – Nacht Jan 31 '12 at 00:48
0

May be there is a problem with path. It can't find the tkinter module. Setting up correct path try to import again.

cola
  • 12,198
  • 36
  • 105
  • 165