dev*_*eek 5 package-management python 14.04 tkinter
我最近在安装最新的 python3.X 时遇到了一个问题。
使用
After 中的Python-3.4.2.tar.xz包安装它python.org,安装我尝试导入tkinter模块但没有成功。
的输出import tkinter是:
>>> 导入 tkinter
回溯(最近一次调用最后一次):
文件“”,第 1 行,在
文件“/usr/local/lib/python3.4/tkinter/__init__.py”,第 38 行,在
import _tkinter # 如果失败,你的 Python 可能没有为 Tk 配置
导入错误:没有名为“_tkinter”的模块
我还尝试了以下解决方案:
但他们都没有帮助。
在尝试这些解决方案时,如果注意到错误显示:
import _tkinter # 如果失败,你的 Python 可能没有为 Tk 配置
然后我用谷歌搜索了一下,发现了这个。
阅读检查您的 Tkinter 支持部分,Step 1失败并卡在这一行
如果您在默认位置安装 Tcl/Tk,只需重新运行“make”即可构建 _tkinter 扩展。
关于上述行,我的问题是:
在哪里可以找到一个 make 文件来运行make命令?
而且,我如何配置tkinter以便 Python3.4.2 接受它?
我忘了提及但import tkinter确实适用于 Ubuntu 14.04.1 中 Python 的默认安装 (Python-3.4.0)
Syl*_*eau 10
为了使用_tkinter模块从源代码构建 python3.4.2,您需要安装以下构建依赖项:
sudo apt-get install tk8.6-dev
Run Code Online (Sandbox Code Playgroud)
然后您所要做的就是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.
[...]
Run Code Online (Sandbox Code Playgroud)
现在你可以在 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
>>>
Run Code Online (Sandbox Code Playgroud)
原答案:
除非你真的需要 python3.4.2,否则我只会在 14.04 ( 3.4.0 )上使用默认的 python3 版本
然后你所要做的就是安装以下软件包:
sudo apt-get install python3-tk tk
Run Code Online (Sandbox Code Playgroud)
并以这种方式启动 python 解释器:
/usr/bin/python3
Run Code Online (Sandbox Code Playgroud)
否则,您将始终获得安装在/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
>>>
Run Code Online (Sandbox Code Playgroud)