14

I just installed graphics.py for python. But when I tried to run the following code:

    from graphics import *

    def main():
        win = GraphWin("My Circle", 100, 100)
        c = Circle(Point(50,50), 10)
        c.draw(win)
        win.getMouse() # Pause to view result
        win.close()    # Close window when done

    main()

my interpreter gave me this strange information:

Traceback (most recent call last):
File "F:\CS 101\Python\projects\packer.py", line 8, in <module>
from graphics import *
File "F:\CS 101\Python\lib\site-packages\graphics.py", line 168, in <module>
_root = tk.Tk()
File "F:\CS 101\Python\lib\tkinter\__init__.py", line 1674, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects,                            useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
{F:\CS 101\Python\tcl\tcl8.5.9} {F:/CS 101/Python/tcl/tcl8.5} {F:/CS        101/Python/lib/tcl8.5} {F:/CS 101/lib/tcl8.5} F:/lib/tcl8.5 {F:/CS 101/library} F:/library     F:/tcl8.5.2/library F:/tcl8.5.2/library

F:/CS 101/Python/tcl/tcl8.5/init.tcl: version conflict for package "Tcl": have 8.5.2,            need exactly 8.5.9
version conflict for package "Tcl": have 8.5.2, need exactly 8.5.9
while executing
"package require -exact Tcl 8.5.9"
(file "F:/CS 101/Python/tcl/tcl8.5/init.tcl" line 20)
invoked from within
"source {F:/CS 101/Python/tcl/tcl8.5/init.tcl}"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $tclfile]"

This probably means that Tcl wasn't installed properly.

What does it mean? What can I do?

PS: I am using Eclipse (PyDev) for coding.

Arsen Khachaturyan
  • 7,904
  • 4
  • 42
  • 42
psiovana
  • 149
  • 1
  • 1
  • 3
  • Did you do something funky to your standard python path? I notice you are pointing at some custom project area only. – jdi May 14 '12 at 02:37
  • Related [version conflict for package “Tk”: have 8.5.2, need exactly 8.5.15](http://stackoverflow.com/questions/26706022/version-conflict-for-package-tk-have-8-5-2-need-exactly-8-5-15), link indicated by [belkacem_py](http://stackoverflow.com/users/7324887/belkacem-py) in NAA post. – Petter Friberg May 16 '17 at 13:36

9 Answers9

11

I sloved by modifying my activate script:

set "TCL_LIBRARY=D:\Program Files (x86)\Python3.5\tcl\tcl8.6"
set "TK_LIBRARY=D:\Program Files (x86)\Python3.5\tcl\tcl8.6"
Julien
  • 13,986
  • 5
  • 29
  • 53
shucun GUO
  • 111
  • 1
  • 4
5

Regarding what you can do, you can try editing your init.tcl file to read something like package require Tcl 8.5.0-8.6, or if that doesn't work you can try package require -exact Tcl 8.5.2. I also had to edit my tcl\tk8.5\tk.tcl file in the same way, for Tk instead of Tcl.

If editing the file does not work for you, you can download and install the latest Tcl from:

  • source using the latest version from sourceforge. This will require having an acceptable compiler. For example, see blog.victorjabur.com/2011/06/05/compiling-python-2-7-modules-on-windows-32-and-64-using-msvc-2008-express/ or stackoverflow.com/questions/4218613/building-a-python-module-on-windows-using-ms-compiler.
  • the latest ActiveState community version. This may be the easiest option if you have permission to install. Seeing that this is for CS 101, your lab administrators might not allow you that permission (whether by policy or technology). Of course, that also probably means this answer comes too late to help with your immediate need.

Regarding what it means, without more information, I can only make conjectures right now. I had the reverse problem; I will tell you about it in hopes that it gives you some insight into what it might mean.

I have 8.5.9 installed, but init.tcl was requiring 8.5.2. I'm guessing my problem was caused by installing ActiveState python, then official python (both 2.7, 64-bit), and/or additional packages I installed later. There is a note at the bottom of this download page regarding Tcl/Tk on MacOS that one could interpret to mean there is room for trouble on the PC as well. ActiveState Python 2.7 includes Tcl/Tk 8.5.9, as documented here. Using 7-zip to open the msi files from ActiveState and Python.org, and grepping for "tcl" and then "require", I can see that the init.tcl in the ActiveState msi specifies package require -exact Tcl 8.5.9.

My guess is that the 8.5.2 requirement came from the regular python install (which is apparently less grepable), or some package I installed later. Running the ActiveState msi in repair mode does not fix the issue, nor does running the Python msi in repair mode.

P.S If this isn't timely, why did I still answer? Crafting a decent answer for you helped me understand my issue better.

Jonathan Spooner
  • 7,682
  • 2
  • 34
  • 41
hlongmore
  • 1,603
  • 24
  • 28
2

I am running PyCharm IDE with Python 2.7. Inside c:\Python27\tcl\tcl8.5\init.tcl "package require -exact Tcl 8.5.2" change to

package require -exact Tcl 8.5.9

Inside c:\Python27\tcl\tk8.5\tk.tcl "package require -exact Tk 8.5.2" change to:

package require -exact Tcl 8.5.9

This worked for me.

user914425
  • 16,303
  • 4
  • 30
  • 41
1

I faced the same problem during my last installation of ns2.35 in ubuntu 11.04. After I install ns2.35, got message of successful installation of ns. Then I set path in /.bashrc. Then I gave ns command which gave me same error which you got.

The problem is because, ns executable is also at /usr which is conflicting.

Solution:

  1. Go to location root-usr-local-bin by giving following command in terminal cd /usr/local/bin
  2. There you would find the ns file. We just need to remove it by giving following command rm ns
  3. Thats it, you are done. Now your ns starts running successfully.
Mischa
  • 42,876
  • 8
  • 99
  • 111
1

There maybe a compatibility issue with another program that uses the TCL_Library environment variable. In the attached thread I changed the environment variable path and it fixed my issue. It may be relevant to your problem:

Python IDLE won´t start

Community
  • 1
  • 1
amundell
  • 101
  • 2
  • 8
0

The PATH solution did't work for me. I'm using Win7 python 2.7. Finally I edited 2 files: C:\Python27\tcl\tk8.5\tk.tcl package require -exact Tk 8.5.2 change into package require Tk 8.5.0-8.6

C:\Python27\tcl\tcl8.5\init.tcl package require -exact Tcl 8.5.2 change into package require Tcl 8.5.0-8.6

And this works! Previously my IDLE never pops out, but now it works as well. Cool, thanks @Jonathan Spooner and @hlongmore

Lisa
  • 161
  • 6
0

I think I had the very same problem under windows8/python2.7. It was a hell of installations and env variables setting. All of them worthless. Today I've found a solution:

Downloading and installing python at D: (in order to preserve my installation) and then copying the folder Tcl into my C: installation in the same relative position: C:\Python27

Evandrojs
  • 11
  • 3
0

I had a similar problem when generating a simple scatter plot using mayplotlib.pyplot in Windows 10. I solved by adding the new environment variables in

Control Panel>System and Security>System>Advanced system settings>Environment Variables>User variables for UserName:

Variable Name: TCL_LIBRARY, Variable value=C:\Python27\tcl\tcl8.5

Variable Name: TK_LIBRARY, Variable value=C:\Python27\tcl\tk8.5

Community
  • 1
  • 1
0

To give a more general solution, in the error traceback, you should have something like:

C:/Users/[perso path]/tcl/tcl8.6/init.tcl: version conflict for package "Tcl": have 8.6.6, need exactly 8.6.8 version conflict for package "Tcl": have 8.6.6, need exactly 8.6.8

So just open the file described in the error: C:/Users/[perso path]/tcl/tcl8.6/init.tcl and replace package require -exact Tcl 8.6.8 with the version needed in the error, for me it was 8.6.6: package require -exact Tcl 8.6.6.

Then the same problem will happen with Tk (with another file), I did the same operations and it worked. Maybe you won't have the same versions, just replace them.

Axel Puig
  • 1,304
  • 9
  • 19