PyPlot ArgumentError: haskey of NULL PyObject error

1,961 views
Skip to first unread message

Kai Xin Thia

unread,
Mar 3, 2016, 2:18:52 AM3/3/16
to julia-users
Using the sample code below, Version 0.4.3 on Mac, I keep getting the error. Is there a way to fix it?:

using PyPlot
n = 50
srand(1)
x = rand(n)
y = rand(n)
area = pi .* (15 .* rand(n)).^2 # 0 to 15 point radiuses
scatter(x, y, s=area, alpha=0.5)

LoadError: ArgumentError: haskey of NULL PyObject
while loading In[12], in expression starting on line 8
 in haskey at /Users/admin/.julia/v0.4/PyCall/src/PyCall.jl:249
 in scatter at /Users/admin/.julia/v0.4/PyPlot/src/PyPlot.jl:457

For reference, Pkg.status()

4 required packages:

 - IJulia                        1.1.8

 - Plots                         0.5.2

 - PyCall                        1.4.0              master

 - PyPlot                        2.1.1

17 additional packages:

 - BinDeps                       0.3.21

 - ColorTypes                    0.2.1

 - Colors                        0.6.3

 - Compat                        0.7.12

 - Conda                         0.1.9

 - Dates                         0.4.4

 - FixedPointNumbers             0.1.2

 - Homebrew                      0.2.0

 - JSON                          0.5.0

 - LaTeXStrings                  0.1.6

 - MacroTools                    0.3.0

 - Nettle                        0.2.2

 - Reexport                      0.0.3

 - Requires                      0.2.2

 - SHA                           0.1.2

 - URIParser                     0.1.2

 - ZMQ                           0.3.1 

Josef Heinen

unread,
Mar 3, 2016, 4:02:18 AM3/3/16
to julia-users
Works find on my machines. Does you example work in the Python environment you are using within Julia?

cdm

unread,
Mar 3, 2016, 3:40:41 PM3/3/16
to julia-users

this also works on JuliaBox, https://www.juliabox.org/, although with the 0.4 and 0.5 kernels,

users will need to add the PyPlot package themselves ...



result:



In [9]:
scatter(x, y, s=area, alpha=0.5)
Out[9]:
PyObject <matplotlib.collections.PathCollection object at 0x7ff61063aa90>
Auto Generated Inline Image 1

Steven G. Johnson

unread,
Mar 3, 2016, 8:54:25 PM3/3/16
to julia-users
It sounds like "using PyPlot" probably threw an error that you ignored?

To make sure that Python and Matplotlib are properly installed, the easiest thing is to have PyCall install its own Miniconda Python distro:

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

You only need to do this once, then re-launch Julia "using PyPlot" will install Matplotlib if needed.
Reply all
Reply to author
Forward
0 new messages