Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 320
biomed Avatar asked May 03 '11 17:05

biomed


2 Answers

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:\env\myenv
C:\> xcopy  c:\python27\tcl t:\env\myenv\tcl /e /i /k
like image 83
Bryan Oakley Avatar answered Nov 14 '22 17:11

Bryan Oakley


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()
like image 43
Steve Phillips Avatar answered Nov 14 '22 17:11

Steve Phillips