[英]Warning: PyPlot is using tkagg backend, which is known to cause crashes on MacOS
Does anyone knows how to change the backend
of PyPlot
from "TkAgg"
to Qt5Agg
in Julia?有谁知道如何在PyPlot
的backend
从"TkAgg"
更改为Qt5Agg
?
I got this warning when I try to Using PyPlot
in Julia:当我尝试在 Julia 中Using PyPlot
时收到此警告:
julia> using PyPlot
[ Info: Recompiling stale cache file /Users/tonyspc/.julia/compiled/v1.2/PyPlot/oatAj.ji for PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee]
┌ Warning: PyPlot is using tkagg backend, which is known to cause crashes on MacOS (#410); use the MPLBACKEND environment variable to request a different backend.
└ @ PyPlot ~/.julia/packages/PyPlot/4wzW1/src/init.jl:192
I tried to use the solution posted here: https://github.com/JuliaPy/PyPlot.jl/issues/454我尝试使用此处发布的解决方案: https://github.com/JuliaPy/PyPlot.jl/issues/454
But it failed:但它失败了:
julia> using PyCall
[ Info: Recompiling stale cache file /Users/tonyspc/.julia/compiled/v1.2/PyCall/GkzkC.ji for PyCall [438e738f-606a-5dbb-bf0a-cddfbfd45ab0]
julia> pyimport_conda("PyQt5", "pyqt")
ERROR: PyError (PyImport_ImportModule
The Python package PyQt5 could not be found by pyimport. Usually this means
that you did not install PyQt5 in the Python version being used by PyCall.
PyCall is currently configured to use the Python version at:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the PyQt5 module.
One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.
Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia. As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the PyQt5 module, you can use `pyimport_conda("PyQt5", PKG)`,
where PKG is the Anaconda package the contains the module PyQt5,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).
) <type 'exceptions.ImportError'>
ImportError('No module named PyQt5',)
Stacktrace:
[1] pyimport(::String) at /Users/tonyspc/.julia/packages/PyCall/ttONZ/src/PyCall.jl:544
[2] pyimport_conda(::String, ::String, ::String) at /Users/tonyspc/.julia/packages/PyCall/ttONZ/src/PyCall.jl:702
[3] pyimport_conda(::String, ::String) at /Users/tonyspc/.julia/packages/PyCall/ttONZ/src/PyCall.jl:701
[4] top-level scope at REPL[4]:1
However I already installed PyQt5
using brew install pyqt
但是我已经使用brew install pyqt
PyQt5
And I don't know why my matplot library
is located at python2
directory not the python3
directory:而且我不知道为什么我的matplot library
位于python2
目录而不是python3
目录:
julia> pyimport("matplotlib").matplotlib_fname()
"/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/mpl-data/matplotlibrc"
I have python2
that comes with default on my Mac, and installed python3
using Homebrew
我的 Mac 上有默认的python2
,并使用Homebrew
安装了python3
MacBook-Pro:~ tonyspc$ which python3
/usr/local/bin/python3
MacBook-Pro:~ tonyspc$ which python
/usr/bin/python
Should I set the ENV["PYTHON"]
to "/usr/local/bin/python3"
?我应该将ENV["PYTHON"]
设置为"/usr/local/bin/python3"
吗?
I had a similar problem, and I added this to my.bashrc to run every time:我遇到了类似的问题,我将其添加到 my.bashrc 中以每次运行:
export MPLBACKEND=qt5agg
Then after doing the ]build PyCall PyPlot
and restarting julia, it seemed to find the right backend to plot.然后在执行]build PyCall PyPlot
并重新启动 julia 之后,它似乎找到了 plot 的正确后端。
My relevant issue I opened (and the answer I got): https://github.com/JuliaPy/PyPlot.jl/issues/453#issuecomment-527163934我打开的相关问题(以及我得到的答案): https://github.com/JuliaPy/PyPlot.jl/issues/453#issuecomment-527163934
Try setting ENV["PYTHON"] = "/usr/local/bin/python3"
in a fresh REPL followed by pkg> build PyCall PyPlot
.尝试在新的 REPL 中设置ENV["PYTHON"] = "/usr/local/bin/python3"
然后pkg> build PyCall PyPlot
。 This should make PyCall (and therefore also PyPlot) use your local Python 3.这应该使 PyCall(以及 PyPlot)使用您本地的 Python 3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.