Skip to content

Matplotlib backend not specified by default in Windows machines [Python: Julia: UndefVarError: Core not defined in PythonCall.Compat] #676

@BoundaryValueProblems

Description

@BoundaryValueProblems

I just updated PythonCall.jl to v0.9.28 and Julia to v1.11.7 on my Window 11 machine. With the previous versions, i.e., v0.9.27 and v1.11.6, respectively, I didn't have to set up the backend of matplotlib.pyplot explicitly. However, with the current new versions, the backend is not specified by default, and got the following error. I don't have any problems on my iMac. Only under Windows, I encountered this problem. What's wrong here?

julia> using PythonCall

julia> plt=pyimport("matplotlib.pyplot")
Python: <module 'matplotlib.pyplot' from 'C:\\Users\\xxx\\.julia\\environments\\v1.11\\.CondaPkg\\.pixi\\envs\\default\\Lib\\site-packages\\matplotlib\\pyplot.py'>

julia> plt.get_backend()
ERROR: Python: Julia: UndefVarError: `Core` not defined in `PythonCall.Compat`
Hint: It looks like two or more modules export different bindings with this name, resulting in ambiguity. Try explicitly importing it from a particular module, or qualifying the name with the module it should come from.
Hint: a global variable of this name also exists in Core.
Stacktrace:
  [1] (::PythonCall.Compat.var"#1#2")()
    @ PythonCall.Compat C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Compat\gui.jl:162
  [2] pyjlany_call(self::PythonCall.Compat.var"#1#2", args_::Py, kwargs_::Py)
    @ PythonCall.JlWrap C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\JlWrap\any.jl:49 
  [3] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
    @ PythonCall.JlWrap C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\JlWrap\base.jl:71
  [4] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})      
    @ PythonCall.JlWrap.Cjl C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\JlWrap\C.jl:63
  [5] PyObject_CallObject
    @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\C\pointers.jl:300 [inlined]        
  [6] macro expansion
    @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\Py.jl:118 [inlined]
  [7] pycallargs(f::Py)
    @ PythonCall.Core C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\builtins.jl:193
  [8] #pycall#21
    @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\builtins.jl:217 [inlined]     
  [9] pycall
    @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\builtins.jl:203 [inlined]     
 [10] (::Py)()
    @ PythonCall.Core C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\Py.jl:334     
 [11] top-level scope
    @ REPL[3]:1
 [12] eval
    @ .\boot.jl:430 [inlined]
 [13] eval
    @ .\Base.jl:130 [inlined]
 [14] repleval(m::Module, code::Expr, ::String)
    @ VSCodeServer c:\Users\xxx\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\repl.jl:229
 [15] #112
    @ c:\Users\xxx\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\repl.jl:192 [inlined]
 [16] with_logstate(f::VSCodeServer.var"#112#114"{…}, logstate::Base.CoreLogging.LogState)   
    @ Base.CoreLogging .\logging\logging.jl:524
 [17] with_logger
    @ .\logging\logging.jl:635 [inlined]
 [18] (::VSCodeServer.var"#111#113"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer c:\Users\xxx\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\repl.jl:193
 [19] #invokelatest#2
    @ .\essentials.jl:1055 [inlined]
 [20] invokelatest(::Any)
    @ Base .\essentials.jl:1052
 [21] (::VSCodeServer.var"#64#65")()
    @ VSCodeServer c:\Users\xxx\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\eval.jl:34
Python stacktrace:
 [1] __call__
   @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\JlWrap\any.jl:262
 [2] find_module
   @ <string>:9
 [3] _find_spec_legacy
   @ <frozen importlib._bootstrap>:1050
 [4] _find_spec
   @ <frozen importlib._bootstrap>:1076
 [5] _find_and_load_unlocked
   @ <frozen importlib._bootstrap>:1140
 [6] _find_and_load
   @ <frozen importlib._bootstrap>:1178
 [7] _setup_pyqt5plus
   @ C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\backends\qt_compat.py:79
 [8] <module>
   @ C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\backends\qt_compat.py:125
 [9] <module>
   @ C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\backends\backend_qtagg.py:9
 [10] _call_with_frames_removed
   @ <frozen importlib._bootstrap>:241
 [11] exec_module
   @ <frozen importlib._bootstrap_external>:940
 [12] _load_unlocked
   @ <frozen importlib._bootstrap>:690
 [13] _find_and_load_unlocked
   @ <frozen importlib._bootstrap>:1149
 [14] _find_and_load
   @ <frozen importlib._bootstrap>:1178
 [15] _gcd_import
   @ <frozen importlib._bootstrap>:1206
 [16] import_module
   @ importlib C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\importlib\__init__.py:126
 [17] load_backend_module
   @ matplotlib.backends.registry C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\backends\registry.py:323
 [18] switch_backend
   @ matplotlib.pyplot C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\pyplot.py:415
 [19] switch_backend
   @ matplotlib.pyplot C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\pyplot.py:400
 [20] __getitem__
   @ matplotlib C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\__init__.py:764
 [21] get_backend
   @ matplotlib C:\Users\xxx\.julia\environments\v1.11\.CondaPkg\.pixi\envs\default\Lib\site-packages\matplotlib\__init__.py:1281
Stacktrace:
 [1] pythrow()
   @ PythonCall.Core C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\err.jl:77      
 [2] errcheck
   @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\err.jl:10 [inlined]
 [3] pycallargs(f::Py)
   @ PythonCall.Core C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\builtins.jl:193
 [4] #pycall#21
   @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\builtins.jl:217 [inlined]      
 [5] pycall
   @ C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\builtins.jl:203 [inlined]      
 [6] (::Py)()
   @ PythonCall.Core C:\Users\xxx\.julia\packages\PythonCall\mkWc2\src\Core\Py.jl:334      
 [7] top-level scope
   @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions