python virtualenv idle and tkinter issue

To be able to use idle with my virtualenv python, I created an idle script

#!/myvirtualenv/python 
from idlelib.PyShell import main
if __name__ == '__main__':
  main()

in the bin/ of my virtualenv but it complains about not being able to find Tkinter.

** IDLE can't import Tkinter.  Your Python may not be configured for Tk. **

I checked and Tkinter can be imported in the regular python2.7.1 but I can't import Tkinter from my virtualenv python. How can I make Tkinter available to my virtualenv python ( I have to use no site-packages with the virtualenv for an other reason) Thanks


One simple solution is to copy the tcl folder from your original python installation to the virtual environment. For example, on my machine I did the following:

C:> virtualenv t:envmyenv
C:> xcopy  c:python27tcl t:envmyenvtcl /e /i /k

I'm currently using IDLE in a few Virtual Environments but my script to start it up looks like below. This works for me whether I created my environment using --no-site-packages option or not. For some reason I had to put the full path to my virtual python in the header of the script.

#!/home/steve/virt_idle/bin/python
from idlelib.PyShell import main
if __name__ == '__main__':
    main()
链接地址: http://www.djcxy.com/p/52478.html

上一篇: App Purchase

下一篇: python virtualenv闲置和tkinter问题