Hi,
I am currently reading Statistics with Julia and quite enjoy it. In the birthday paradox section of second chapter, the following code is listed to illustrate the paradox with the use of Plots
and pyplot()
. So I typed it into VS Code with Julia plug-in installed.
using StatsBase, Combinatorics, Plots ; pyplot()
matchExists1(n) = 1 - prod([k/365 for k in 365:-1:365-n+1])
matchExists2(n) = 1 - factorial(365, 465 - big(n)) / 365^big(n)
function bdEvent(n)
birthdays = rand(1:365, n)
dayCounts = counts(birthdays, 1:365)
return maximum(dayCounts) > 1
end
probEst(n) = sum([bdEvent(n) for _ in 1:N]) / N
xGrid = 1:50
analyticSolution1 = [matchExists1(n) for n in xGrid]
analyticSolution2 = [matchExists2(n) for n in xGrid]
println("Maximum error: $(maximum(abs.(analyticSolution1 - analyticSolution2)))")
N = 10^3
mcEstimates = [probEst(n) for n in xGrid]
plot(xGrid, analyticSolution1, c=:blue, label="Analytic solution")
scatter!(xGrid, mcEstimates, c=:red, ms=6, msw=0, shape=:xcross,
label="MC estimate", xlims=(0,50), ylims=(0, 1),
xlabel="Number of people in room",
ylabel="Probability of birthday match",
legend=:topleft)
However, as I ran the code above, it displayed:
[ Info: Precompiling PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee]
ERROR: LoadError: PyCall not properly installed. Please run Pkg.build("PyCall")
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] top-level scope
@ ~/.julia/packages/PyCall/ygXW2/src/startup.jl:44
[3] include(mod::Module, _path::String)
@ Base ./Base.jl:419
[4] include(x::String)
@ PyCall ~/.julia/packages/PyCall/ygXW2/src/PyCall.jl:1
[5] top-level scope
@ ~/.julia/packages/PyCall/ygXW2/src/PyCall.jl:38
[6] include
@ ./Base.jl:419 [inlined]
[7] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
@ Base ./loading.jl:1554
[8] top-level scope
@ stdin:1
in expression starting at /Users/Latisp/.julia/packages/PyCall/ygXW2/src/startup.jl:41
in expression starting at /Users/Latisp/.julia/packages/PyCall/ygXW2/src/PyCall.jl:1
in expression starting at stdin:1
ERROR: LoadError: Failed to precompile PyCall [438e738f-606a-5dbb-bf0a-cddfbfd45ab0] to /Users/Latisp/.julia/compiled/v1.8/PyCall/jl_pUZTkL.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
@ Base ./loading.jl:1705
[3] compilecache
@ ./loading.jl:1649 [inlined]
[4] _require(pkg::Base.PkgId)
@ Base ./loading.jl:1337
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base ./loading.jl:1200
[6] macro expansion
@ ./loading.jl:1180 [inlined]
[7] macro expansion
@ ./lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base ./loading.jl:1144
[9] include
@ ./Base.jl:419 [inlined]
[10] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
@ Base ./loading.jl:1554
[11] top-level scope
@ stdin:1
in expression starting at /Users/Latisp/.julia/packages/PyPlot/NsAWt/src/PyPlot.jl:2
in expression starting at stdin:1
ERROR: Failed to precompile PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee] to /Users/Latisp/.julia/compiled/v1.8/PyPlot/jl_uWRUKz.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
@ Base ./loading.jl:1705
[3] compilecache
@ ./loading.jl:1649 [inlined]
[4] _require(pkg::Base.PkgId)
@ Base ./loading.jl:1337
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base ./loading.jl:1200
[6] macro expansion
@ ./loading.jl:1180 [inlined]
[7] macro expansion
@ ./lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base ./loading.jl:1144
[9] top-level scope
@ ~/.julia/packages/Plots/FCUr0/src/backends.jl:679
After which I ran Pkg.build("PyCall")
:
julia> Pkg.build("PyCall")
Building Conda ─→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/6e47d11ea2776bc5627421d59cdcc1296c058071/build.log`
Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/53b8b07b721b77144a0fbbbc2675222ebf40a02d/build.log`
ERROR: Error building `PyCall`:
┌ Info: Using the Python distribution in the Conda package by default.
└ To use a different Python version, set ENV["PYTHON"]="pythoncommand" and re-run Pkg.build("PyCall").
[ Info: Downloading miniconda installer ...
ERROR: LoadError: SSL connection timeout while requesting https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-x86_64.sh
Stacktrace:
[1] (::Downloads.var"#9#18"{IOStream, Base.DevNull, Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Nothing, Bool, String, Bool, Bool})(easy::Downloads.Curl.Easy)
@ Downloads /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Downloads.jl:387
[2] with_handle(f::Downloads.var"#9#18"{IOStream, Base.DevNull, Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Nothing, Bool, String, Bool, Bool}, handle::Downloads.Curl.Easy)
@ Downloads.Curl /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Curl/Curl.jl:88
[3] #8
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Downloads.jl:328 [inlined]
[4] arg_write(f::Downloads.var"#8#17"{Base.DevNull, Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Nothing, Bool, String, Bool, Bool}, arg::IOStream)
@ ArgTools /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/ArgTools/src/ArgTools.jl:134
[5] #7
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Downloads.jl:327 [inlined]
[6] arg_read
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/ArgTools/src/ArgTools.jl:76 [inlined]
[7] request(url::String; input::Nothing, output::IOStream, method::Nothing, headers::Vector{Pair{String, String}}, timeout::Float64, progress::Nothing, verbose::Bool, debug::Nothing, throw::Bool, downloader::Nothing)
@ Downloads /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Downloads.jl:326
[8] #3
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Downloads.jl:231 [inlined]
[9] open(f::Downloads.var"#3#4"{Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Nothing, Nothing, String}, args::String; kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:write, :lock), Tuple{Bool, Bool}}})
@ Base ./io.jl:384
[10] #open_nolock#1
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/ArgTools/src/ArgTools.jl:35 [inlined]
[11] arg_write(f::Function, arg::String)
@ ArgTools /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/ArgTools/src/ArgTools.jl:103
[12] #download#2
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Downloads.jl:230 [inlined]
[13] download
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Downloads/src/Downloads.jl:219 [inlined]
[14] _install_conda(env::String, force::Bool)
@ Conda ~/.julia/packages/Conda/x2UxR/src/Conda.jl:201
[15] _install_conda(env::String)
@ Conda ~/.julia/packages/Conda/x2UxR/src/Conda.jl:191
[16] runconda(args::Cmd, env::String)
@ Conda ~/.julia/packages/Conda/x2UxR/src/Conda.jl:126
[17] add(pkg::String, env::String; channel::String)
@ Conda ~/.julia/packages/Conda/x2UxR/src/Conda.jl:222
[18] add (repeats 2 times)
@ ~/.julia/packages/Conda/x2UxR/src/Conda.jl:220 [inlined]
[19] top-level scope
@ ~/.julia/packages/PyCall/ygXW2/deps/build.jl:79
[20] include(fname::String)
@ Base.MainInclude ./client.jl:476
[21] top-level scope
@ none:5
in expression starting at /Users/Latisp/.julia/packages/PyCall/ygXW2/deps/build.jl:43
Stacktrace:
[1] pkgerror(msg::String)
@ Pkg.Types /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Types.jl:67
[2] (::Pkg.Operations.var"#66#73"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String})()
@ Pkg.Operations /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1060
[3] withenv(::Pkg.Operations.var"#66#73"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, ::Pair{String, String}, ::Vararg{Pair{String}})
@ Base ./env.jl:172
[4] (::Pkg.Operations.var"#107#112"{String, Bool, Bool, Bool, Pkg.Operations.var"#66#73"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.PackageSpec})()
@ Pkg.Operations /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1619
[5] with_temp_env(fn::Pkg.Operations.var"#107#112"{String, Bool, Bool, Bool, Pkg.Operations.var"#66#73"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.PackageSpec}, temp_env::String)
@ Pkg.Operations /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1493
[6] (::Pkg.Operations.var"#105#110"{Dict{String, Any}, Bool, Bool, Bool, Pkg.Operations.var"#66#73"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, Pkg.Types.Project, String})(tmp::String)
@ Pkg.Operations /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1582
[7] mktempdir(fn::Pkg.Operations.var"#105#110"{Dict{String, Any}, Bool, Bool, Bool, Pkg.Operations.var"#66#73"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, Pkg.Types.Project, String}, parent::String; prefix::String)
@ Base.Filesystem ./file.jl:764
[8] mktempdir(fn::Function, parent::String) (repeats 2 times)
@ Base.Filesystem ./file.jl:760
[9] sandbox(fn::Function, ctx::Pkg.Types.Context, target::Pkg.Types.PackageSpec, target_path::String, sandbox_path::String, sandbox_project_override::Pkg.Types.Project; preferences::Dict{String, Any}, force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool)
@ Pkg.Operations /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1540
[10] build_versions(ctx::Pkg.Types.Context, uuids::Set{Base.UUID}; verbose::Bool)
@ Pkg.Operations /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1041
[11] build(ctx::Pkg.Types.Context, uuids::Set{Base.UUID}, verbose::Bool)
@ Pkg.Operations /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:898
[12] build(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; verbose::Bool, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
@ Pkg.API /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:1024
[13] build(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Pkg.API /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:156
[14] build(pkgs::Vector{Pkg.Types.PackageSpec})
@ Pkg.API /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:145
[15] #build#99
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:144 [inlined]
[16] build
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:144 [inlined]
[17] #build#98
@ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:143 [inlined]
[18] build(pkg::String)
@ Pkg.API /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:143
[19] top-level scope
@ REPL[7]:1
The issue is still present. I do not have Conda installed, so I was wondering that what caused it?
Thank you.