2017-07-14 73 views
0

我想运行一些使用Tkinter的绘图库。我使用Python 2.7,并且我得到确切的错误(大写重要的:))Python 2.7无法找到与大写T模块Tkinter T

 
ImportError: No module named Tkinter 

好像很多人都遇到了由务必使用大写的Tkinter对所有解决了类似的问题小写tkinter。我不相信这是我的问题,因为它实际上是大写的。

当我运行:

 
python --version 

我得到:

 
Python 2.7.5 

有没有我可以检查,以确保安装正确的Tkinter的地方吗?有没有其他人看过Python 2.7的这个特殊问题?

+0

你使用Windows,因为Tkinter只针对Windows的python文件标准。如果使用linux,那么'apt install python-tk'会安装它。 – SolarFactories

回答

0

首先,从您要使用它的目录运行pip freeze。如果您使用虚拟环境,请确保它处于活动状态。这将显示您当前安装

更精确的方法是检查它们会安装在站点包所有包(我用IPython中):

How do I find the location of my Python site-packages directory?

$ ipython 

In [1]: import site 

In [2]: site.getsitepackages() 
Out[2]: 
['/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages', 
'/Library/Python/3.6/site-packages'] 

然后去那里:

cchilders:/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages 
$ ls 
IPython     jupyter_client    python_dateutil-2.6.0.dist-info 
Jinja2-2.9.6.dist-info   jupyter_client-5.0.1.dist-info  pytz 
MarkupSafe-1.0.dist-info  jupyter_console    pytz-2017.2.dist-info 
Pygments-2.2.0.dist-info  jupyter_console-5.1.0.dist-info  pyzmq-16.0.2.dist-info 
__pycache__    jupyter_core    qtconsole 
appnope     jupyter_core-4.3.0.dist-info  qtconsole-4.3.0.dist-info 
...etc... 

您在pip freeze上看到的相同内容应显示在此处。

确保你有正确版本的python包。如果使用python 3,你不得不说:

pip3 freeze

但显然是为了安装使用apt如果你有Linux的最安全的办法:

sudo apt-get install python-tk 

Install tkinter for Python