为什么我运行脚本时找不到这个模块,而是在解释器中?

2024-10-16 20:51:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将tkinter模块导入到脚本中。我安装了它,因为解释器可以毫无问题地导入它:

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
>>> 

进口很好,没问题。但是现在当我尝试运行一个包含import tkinter行的脚本时。。。。在

^{pr2}$

其中t是脚本的名称,ls是一个命令行接口。在

翻译怎么能看到它而不是脚本?谢谢。在

编辑:

在系统路径对口译员说:

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

对于剧本:

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

Tags: import脚本eggtkinterlibpackagesscriptssite
2条回答

可能是路径有问题。它找不到tkinter模块。设置正确的路径尝试再次导入。在

这个脚本似乎是用python2.7运行的,但是当您直接运行解释器时,它使用的是python3.2。正如@DSM所提到的,Tkinter的名字是不同的(也许还有其他的区别?)。在

相关问题 更多 >