尝试从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的正确方法是什么?
最佳答案
在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
可以在this question on askubuntu上找到此引用
关于python - Virtualenv中的TKinter,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15884075/