小编典典

Virtualenv中的TKinter

python

尝试使用来自virtualenv的基于TKinter的小部件运行python代码。

    user@computer:~/myproject$ env/bin/python Python
    2.7.3 (default, Sep 26 2012, 21:51:14)  [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.
    >>> import Tkinter 
Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
        raise ImportError, str(msg) + ', please install the python-tk package' ImportError: No module named _tkinter, please install the python-tk package

将TK安装到virtualenv的正确方法是什么?


阅读 210

收藏
2020-12-20

共1个答案

小编典典

activate脚本中设置环境变量TCL_LIBRARY 。在Windows(带有Tcl 8.5的Python
2.7)上,只需将此行添加到Scripts\activate.bat

set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"

@Jasper van den Bosch的编辑:在Ubuntu上,对脚本的修改activate如下:

TK_LIBRARY=/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/site-packages/PIL:/usr/lib
TKPATH=/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/site-packages/PIL:/usr/lib 
TCL_LIBRARY=/usr/lib 
export TCL_LIBRARY TK_LIBRARY TKPATH

可以在askubuntu上的此问题上找到此参考

2020-12-20