我最近在安装最新的python3.X时遇到了问题。
使用After之后的Python-3.4.2.tar.xz
软件包安装了它python.org
,安装时我尝试导入tkinter
模块,但未成功。
输出import tkinter
为:
>>>导入tkinter 追溯(最近一次通话): 文件“”,第1行,在 在第38行的“ /usr/local/lib/python3.4/tkinter/__init__.py”文件中 import _tkinter#如果失败,则可能没有为Tk配置Python ImportError:没有名为“ _tkinter”的模块
我还尝试了以下解决方案:
但他们都没有帮助。
在尝试这些解决方案时,如果注意到错误提示:
import _tkinter#如果失败,则可能没有为Tk配置Python
然后我用谷歌搜索并找到了这个。
阅读“检查您的Tkinter支持”部分,Step 1
失败了,并停留在该行中
如果在默认位置安装Tcl / Tk,只需重新运行“ make”即可构建_tkinter扩展名。
关于上一行,我的问题是:
在哪里可以找到要在其make
上运行命令的make文件?
并且,如何配置tkinter
以便Python3.4.2接受它?
我忘了提一下,但import tkinter
确实适用于Ubuntu 14.04.1中Python的默认安装(Python-3.4.0)
为了使用_tkinter
模块从源代码构建python3.4.2,您需要安装以下构建依赖项:
sudo apt-get install tk8.6-dev
然后,您所要做的就是make
再次运行以添加_tkinter
支持,因为该setup.py
文件将自动检测tk / tcl标头并创建模块:
~/Downloads/Python-3.4.2$ make
running build
running build_ext
building '_tkinter' extension
gcc -pthread -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -DWITH_APPINIT=1 -I/usr/include/tcl8.6 -I/usr/X11/include -I./Include -I. -IInclude -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/home/sylvain/Downloads/Python-3.4.2/Include -I/home/sylvain/Downloads/Python-3.4.2 -c /home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.c -o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.o
gcc -pthread -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -DWITH_APPINIT=1 -I/usr/include/tcl8.6 -I/usr/X11/include -I./Include -I. -IInclude -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/home/sylvain/Downloads/Python-3.4.2/Include -I/home/sylvain/Downloads/Python-3.4.2 -c /home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.c -o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.o
gcc -pthread -shared build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.o -L/usr/X11/lib -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -ltk8.6 -ltcl8.6 -lX11 -o build/lib.linux-x86_64-3.4/_tkinter.cpython-34m.so
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma _sqlite3
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
[...]
现在您可以在python3.4.2中导入tkinter了:
~/Downloads/Python-3.4.2$ ./python
Python 3.4.2 (default, Oct 30 2014, 11:34:17)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
原始答案:
除非您确实需要python3.4.2,否则我将在14.04(3.4.0)上使用默认的python3版本。
然后,您要做的就是安装以下软件包:
sudo apt-get install python3-tk tk
并以这种方式启动python解释器:
/usr/bin/python3
否则,您将始终获得在/usr/local
(3.4.2)中安装的版本。
现在可以在python3中导入tk了:
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句