Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tk library conflict on MacOS X #164

Closed
mkborregaard opened this issue Sep 15, 2015 · 21 comments
Closed

Tk library conflict on MacOS X #164

mkborregaard opened this issue Sep 15, 2015 · 21 comments

Comments

@mkborregaard
Copy link

When trying to print, we get

julia> x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x));

julia> plot(x, y, color="red", linewidth=2.0, linestyle="--")
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1532, in __call__
    return self.func(*args)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 278, in resize
    self.show()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 350, in draw
    tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 24, in blit
    tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
TclError
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1532, in __call__
    return self.func(*args)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 583, in callit
    func(*args)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 365, in idle_draw
    self.draw()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 350, in draw
    tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 24, in blit
    tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
TclError
1-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0x3161117d0>
@mkborregaard
Copy link
Author

I meant, when typing the plot command

@stevengj
Copy link
Member

Can you try

Pkg.checkout("PyCall")
Pkg.build("PyCall")

to see if the latest PyCall fixes it?

@mkborregaard
Copy link
Author

It does not, unfortunately. I should add that I installed dependencies via the Homebrew method.

@stevengj
Copy link
Member

What is the output of versioninfo(true)?

What Python distro are you using? (I recommend Anaconda Python.)

@stevengj
Copy link
Member

(Possibly a dup of #103?)

@mkborregaard
Copy link
Author

I tried to reinstall XQuartz as suggested in that thread (although my error message is different, my problem seems to be with TKinter. I should mention that I also have problems getting another package to work (SFML) whereas the rest of my packages work great.

When I call using PyPlot it gives the following warning:

WARNING: Method definition copy!(PyCall.PyObject, PyCall.PyObject) in module PyCall at /Users/michael/.julia/PyCall/src/PyCall.jl:98 overwritten in module PyPlot at /Users/michael/.julia/PyPlot/src/PyPlot.jl:102.
objc[34729]: Class TKApplication is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[34729]: Class TKMenu is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[34729]: Class TKContentView is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[34729]: Class TKWindow is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.

The output is

Julia Version 0.4.0-rc1+5
Commit 9103ebe (2015-09-10 03:30 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
  WORD_SIZE: 64
  uname: Darwin 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64 i386
Memory: 8.0 GB (24.92578125 MB free)
Uptime: 642330.0 sec
Load Avg:  2.1953125  2.17236328125  1.92626953125
Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz: 
       speed         user         nice          sys         idle          irq
#1  2900 MHz     359636 s          0 s     207085 s    2057168 s          0 s
#2  2900 MHz     110267 s          0 s      59459 s    2454087 s          0 s
#3  2900 MHz     346871 s          0 s     147898 s    2129046 s          0 s
#4  2900 MHz     116745 s          0 s      63721 s    2443346 s          0 s

  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
Environment:
  PATH = /usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/Users/michael/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin:/Users/michael/bin:/Library/Frameworks/R.framework/Resources/bin/:/Applications/MRT/bin
  HOME = /Users/michael
  TERM = xterm-256color
  XPC_FLAGS = 0x0
  MRT_HOME = /Applications/MRT

Package Directory: /Users/michael/.julia
22 required packages:
 - Atom                          0.1.1
 - Bootstrap                     0.3.1
 - Cairo                         0.2.30
 - Color                         0.4.8
 - DataFrames                    0.6.9
 - FactCheck                     0.4.0
 - Gadfly                        0.3.16
 - Homebrew                      0.1.16
 - IJulia                        1.0.3
 - ImageView                     0.1.16
 - Images                        0.4.46
 - Jewel                         1.0.6
 - NamedArrays                   0.4.4
 - Phylogenetics                 0.0.2
 - PyPlot                        2.0.1
 - RCall                         0.2.1
 - RDatasets                     0.1.2
 - Shapefile                     0.0.3
 - StatsBase                     0.7.2
 - TestImages                    0.0.8
 - Yeppp                         0.0.8
 - ZMQ                           0.2.0
63 additional packages:
 - ArrayViews                    0.6.3
 - BinDeps                       0.3.15
 - Bio                           0.0.0-             Ward9250PhyloV1 (unregistered)
 - Calculus                      0.1.10
 - CodeTools                     0.1.0
 - Codecs                        0.1.4
 - ColorTypes                    0.1.4
 - ColorVectorSpace              0.0.3
 - Colors                        0.5.3
 - Compat                        0.7.0
 - Compose                       0.3.15
 - Contour                       0.0.7
 - DataArrays                    0.2.18
 - DataStructures                0.3.12
 - Dates                         0.4.4
 - Distances                     0.2.0
 - Distributions                 0.8.6
 - Docile                        0.5.18
 - DualNumbers                   0.1.3
 - FixedPointNumbers             0.0.10
 - GZip                          0.2.17
 - Graphics                      0.1.3
 - Grid                          0.3.10
 - Hexagons                      0.0.4
 - Hiccup                        0.0.1
 - HttpCommon                    0.2.3
 - ImmutableArrays               0.0.10
 - IniFile                       0.2.4
 - IntervalTrees                 0.0.4
 - Iterators                     0.1.8
 - JSON                          0.4.5
 - JuliaParser                   0.6.2+             master
 - KernelDensity                 0.1.1
 - LNR                           0.0.1
 - LaTeXStrings                  0.1.4
 - Lazy                          0.10.0
 - Lexicon                       0.1.15
 - LightXML                      0.2.0
 - Loess                         0.0.3
 - MacroTools                    0.2.0
 - Media                         0.1.1
 - NaNMath                       0.1.0
 - Nettle                        0.1.10
 - Optim                         0.4.2
 - PDMats                        0.3.5
 - PyCall                        0.8.2+             master
 - RasterIO                      0.0.0-             master (unregistered)
 - Reexport                      0.0.3
 - Requires                      0.2.0
 - SHA                           0.1.1
 - SIUnits                       0.0.5
 - Showoff                       0.0.4
 - SortingAlgorithms             0.0.5
 - StatsFuns                     0.1.3
 - Switch                        0.0.1
 - TexExtensions                 0.0.2
 - Tk                            0.3.6
 - URIParser                     0.1.0
 - Winston                       0.11.12
 - WoodburyMatrices              0.1.1
 - ZipFile                       0.2.4
 - Zlib                          0.1.9
 - lib                           0.0.0-             non-repo (unregistered)

@mkborregaard
Copy link
Author

Also, I followed your suggestion in that thread:

julia> using PyCall

julia> matplotlib = pyimport("matplotlib")
PyObject <module 'matplotlib' from '/usr/local/lib/python2.7/site-packages/matplotlib/__init__.pyc'>

julia> matplotlib[:use]("tkagg")

julia> pltm = pyimport("matplotlib.pyplot")
PyObject <module 'matplotlib.pyplot' from '/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.pyc'>


@mkborregaard
Copy link
Author

Sorry - it works when I am in IJulia - but when I am in my console it opens a new window and throws the error message. Am I being stupid and the package is only supposed to work in IJulia?

@stevengj
Copy link
Member

No, it should work in the terminal, too, but you need an appropriate GUI environment installed. I'm guessing you are using the python that ships with MacOS, which comes with a broken version of Tk. That's why I recommended installing Anaconda Python (which is nice for other reasons as well).

@mkborregaard
Copy link
Author

I did not use the built-in Python, but the one from Homebrew, which must then be broken too. I did not want the Anaconda install, as I am on a small SSD and jealously guard my disk space (Anaconda is 3GB). I tried installing miniconda instead, but that gives the error 'no module site' (similar to JuliaPy/PyCall.jl#42) .

@stevengj
Copy link
Member

You can use Miniconda via the Conda.jl package now. Just do:

ENV["PYTHON"]=""
Pkg.update()
Pkg.build("PyCall")
using PyPlot

and it should install and use matplotlib in the "private" Julia miniconda distribution set up by Conda.

@lewisl
Copy link

lewisl commented Nov 2, 2015

I tried to do this and Julia crashes when there are two tk installation on the system.

@krzakala
Copy link

krzakala commented Jul 1, 2016

Anything new here ? I seem to get this problem if I use miniconda OR anaconda... Still got the unfamous

using PyPlot
INFO: Recompiling stale cache file /Users/krzakala/.julia/lib/v0.4/PyCall.ji for module PyCall.
INFO: Recompiling stale cache file /Users/krzakala/.julia/lib/v0.4/PyPlot.ji for module PyPlot.
objc[23674]: Class TKApplication is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Users/krzakala/anaconda/lib/libtk8.5.dylib. One of the two will be used. Which one is undefined.
objc[23674]: Class TKMenu is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Users/krzakala/anaconda/lib/libtk8.5.dylib. One of the two will be used. Which one is undefined.
objc[23674]: Class TKContentView is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Users/krzakala/anaconda/lib/libtk8.5.dylib. One of the two will be used. Which one is undefined.
objc[23674]: Class TKWindow is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Users/krzakala/anaconda/lib/libtk8.5.dylib. One of the two will be used. Which one is undefined.

@darwindarak
Copy link

Not a permanent fix, but the Qt4Agg backend works just fine. You just have to add backend : Qt4Agg to ~/.matplotlib/matplotlibrc.

@stevengj
Copy link
Member

Seems like a problem caused by your anaconda installation. You probably have an LD_LIBRARY_PATH or DYLD_LIBRARY_PATH environment variable that is confusing the runtime linker. Remove /Users/krzakala/anaconda/lib from the path and try again with the Conda.jl Matplotlib as I suggested above.

@krzakala
Copy link

krzakala commented Jul 11, 2016

I solved it using instead the homebrew distribution for python.

@stevengj stevengj changed the title PyPlot fails at 'Plot', Julia-0.4, Mac OS X Tkinter library conflict on MacOS X Jul 13, 2016
@stevengj stevengj changed the title Tkinter library conflict on MacOS X Tk library conflict on MacOS X Jul 13, 2016
@stevengj stevengj mentioned this issue Jul 24, 2016
@stevengj
Copy link
Member

@Luthaf, many people seem to be running into this with Conda on MacOS X... some conflict between Conda and OSX's Tk libraries.

@stevengj
Copy link
Member

stevengj commented Aug 4, 2016

I've partially worked around the problem by defaulting to the Qt backend (rather than Tk) if we seem to be using Anaconda Python.

(I don't want to default to Qt unconditionally on Mac because it might not be installed. However, if we are using Anaconda then pyimport_conda should be able to auto-install it if needed.)

@goretkin
Copy link
Contributor

goretkin commented Apr 6, 2017

This is the fix that worked for me: python-pillow/Pillow#950 (comment)

@stevengj
Copy link
Member

It seems like this is no longer an issue with recent Conda versions.

stevengj added a commit that referenced this issue Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants