Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

python - TKinter in a Virtualenv

Trying to run python code with TKinter-based widgets from a virtualenv.

    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

What is the proper way to install TK to the virtualenv?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Set the environment variable TCL_LIBRARY in your activate script. On Windows (Python 2.7 with Tcl 8.5), just add this line to Scriptsactivate.bat:

set "TCL_LIBRARY=C:Python27clcl8.5"

@Jasper van den Bosch's edit: On Ubuntu, the modification to the script activate is the following:

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

The reference of this can be found on this question on askubuntu


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...