Importing tkinter on local python installation: If this fails your Python may not be configured for Tk

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I need to run a python code using a local python 3.5 installation (I have no access to the system administration and the main system uses python 2.7). I managed to install python and I also downloaded the latest version tcl/tk from here http://www.tcl.tk/software/tcltk/download.html which I managed to configure and install correctly on a local path.

After installing tcl/tk I run the python configure again and installed again since I read somewhere that that should fix it but I'm still getting this error.

File "/local/path/to/python3.5/python/lib/python3.5/tkinter/__init__.py", line 35, in <module> import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter' 

Any ideas what I need to do to make it work?

回答1:

For me the solution was to install the python3-tk package through the Ubuntu package manager:

sudo apt-get install python3-tk 

Before this, import tkinter raised the same error you are seeing. Afterwards, it worked without issue.



回答2:

I worked around this issue by using this small Arch Linux distro that you can run locally. Very useful for when you don't have root access!

https://github.com/fsquillace/junest



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!