<strike id="5ntnv"><i id="5ntnv"><del id="5ntnv"></del></i></strike>
<strike id="5ntnv"></strike><ruby id="5ntnv"></ruby><del id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></del><strike id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></strike>
<strike id="5ntnv"></strike>
<strike id="5ntnv"></strike>
<span id="5ntnv"><dl id="5ntnv"></dl></span>
<strike id="5ntnv"><i id="5ntnv"><del id="5ntnv"></del></i></strike><th id="5ntnv"><noframes id="5ntnv"><span id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></span>
<span id="5ntnv"></span>
<strike id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></strike>
<strike id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></strike><strike id="5ntnv"><i id="5ntnv"></i></strike><span id="5ntnv"></span>
<strike id="5ntnv"></strike>
<strike id="5ntnv"></strike>
<th id="5ntnv"><noframes id="5ntnv">
<ruby id="5ntnv"></ruby>
<strike id="5ntnv"><dl id="5ntnv"></dl></strike>

貴州網站建設公司貴州網站建設公司

解決Julia使用PyPlot庫出現ERROR: ArgumentError: hasproperty of NULL PyObject問題

解決Julia使用PyPlot庫出現ERROR: ArgumentError: hasproperty of NULL PyObject問題

    • 問題描述
    • 問題定位
    • 嘗試方法
    • 解決方法
    • The解決 end

問題描述

Julia安裝完成PyPlot后,在使用時遇到如下問題:

$ juliajulia> using Pkgjulia> Pkg.add("PyPlot")using PyPlot,出現Random[ Info: Precompiling PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee]ERROR: InitError: PyError (PyImport_ImportModuleThe Python package matplotlib could not be imported by pyimport. Usually this meansthat you did not install matplotlib in the Python version being used by PyCall.PyCall is currently configured to use the Python version at:/usr/bin/python3and you should use whatever mechanism you usually use (apt-get, pip, conda,etcetera) to install the Python package containing the matplotlib module.One alternative is to re-configure PyCall to use a different Pythonversion on your system: set ENV["PYTHON"] to the path/name of the pythonexecutable you want to use, run Pkg.build("PyCall"), and re-launch Julia.Another alternative is to configure PyCall to use a Julia-specific Pythondistribution via the Conda.jl package (which installs a private AnacondaPython distribution), which has the advantage that packages can be installedand 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 matplotlib module, you can use `pyimport_conda("matplotlib", PKG)`,where PKG is the Anaconda package that contains the module matplotlib,or alternatively you can use the Conda package directly (via`using Conda` followed by `Conda.add` etcetera).) <class 'ModuleNotFoundError'>ModuleNotFoundError("No module named 'matplotlib'",)Stacktrace: [1] pyimport(::String) at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/src/PyCall.jl:550 [2] pyimport_conda(::String, ::String, ::String) at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/src/PyCall.jl:708 [3] pyimport_conda at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/src/PyCall.jl:707 [inlined] [4] __init__() at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyPlot/XHEG0/src/init.jl:179 [5] _include_from_serialized(::String, ::Array{ Any,1}) at ./loading.jl:697 [6] _require_from_serialized(::String) at ./loading.jl:749 [7] _require(::Base.PkgId) at ./loading.jl:1040 [8] require(::Base.PkgId) at ./loading.jl:928 [9] require(::Module, ::Symbol) at ./loading.jl:923during initialization of module PyPlot

如不解決此問題,會在后續使用PyPlot時,解決報“ERROR: ArgumentError: hasproperty of NULL PyObject”錯誤:
解決Julia使用PyPlot庫出現ERROR: ArgumentError: hasproperty of NULL PyObject問題 _ JavaClub全棧架構師技術筆記

具體描述如下:

julia> using Random,出現 PyPlotjulia> function f()	       Random.seed!(1)	       r = rand(50)	       @show sum(r)	       display(transpose(r))	       print(transpose(r))	       plot(r)       endf (generic function with 1 method)julia> f()sum(r) = 23.1342094837073941×50 LinearAlgebra.Transpose{ Float64,Array{ Float64,1}}: 0.236033  0.346517  0.312707  0.00790928  …  0.524975  0.241591  0.884837[0.23603334566204692 0.34651701419196046 0.3127069683360675 0.00790928339056074 0.4886128300795012 0.21096820215853596 0.951916339835734 0.9999046588986136 0.25166218303197185 0.9866663668987996 0.5557510873245723 0.43710797460962514 0.42471785049513144 0.773223048457377 0.2811902322857298 0.20947237319807077 0.25137920979222494 0.02037486871266725 0.2877015122756894 0.859512136087661 0.07695088688120899 0.6403962459899388 0.8735441302706854 0.27858242002877853 0.7513126327861701 0.6448833539420931 0.07782644396003469 0.8481854810000327 0.0856351682044918 0.5532055454580578 0.46335024592359875 0.18582130997265378 0.11198087695816716 0.976311881619359 0.051614620674327094 0.5380295812064833 0.4556920516275036 0.2793951106725605 0.17824610354168602 0.5489828719625274 0.37097066286146885 0.8941659192657594 0.6480537482231894 0.4170393538841062 0.14456554241360564 0.6224031828206811 0.8723344353741975 0.5249746566167794 0.24159060827129641 0.8848369255734128]ERROR: ArgumentError: hasproperty of NULL PyObjectStacktrace: [1] pyhasproperty(::PyCall.PyObject, ::String) at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/src/PyCall.jl:363 [2] hasproperty at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/src/PyCall.jl:369 [inlined] [3] plot(::Array{ Float64,1}; kws::Base.Iterators.Pairs{ Union{ },Union{ },Tuple{ },NamedTuple{ (),Tuple{ }}}) at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyPlot/XHEG0/src/PyPlot.jl:174 [4] plot at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyPlot/XHEG0/src/PyPlot.jl:174 [inlined] [5] f() at ./REPL[10]:7 [6] top-level scope at REPL[11]:1

問題定位

主要問題在于調用matplotlib問題,導致PyCall庫的解決編譯出現錯誤,使PyPlot不能正常使用。出現

嘗試方法

看到報錯信息中set ENV["PYTHON"] to the path/name of the python executable you want to use,解決 run Pkg.build("PyCall"),因此首先嘗試了此方法:

# 打印PyCall構建DEBUG信息julia> ENV["PYCALL_DEBUG_BUILD"] = "yes"# 修改python執行路徑julia> ENV["PYTHON"]="/home/brainiac/Program/python3.7/bin/python3.7"# 編譯PyCalljulia> Pkg.build("PyCall")

但是出現編譯過程中仍報錯:
解決Julia使用PyPlot庫出現ERROR: ArgumentError: hasproperty of NULL PyObject問題 _ JavaClub全棧架構師技術筆記

這個方法仍沒有解決此問題,報錯信息具體為:

┌ Error: Error building `PyCall`: │ DEBUG is_windows = False│ DEBUG is_apple = False│ DEBUG Candidate: None│ DEBUG Not found.│ DEBUG Candidate: /home/brainiac/Program/python3.7/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a│ DEBUG Found: /home/brainiac/Program/python3.7/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a...│ DEBUG Not found.│ dlopen(/home/brainiac/Program/python3.7/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a) ==> ErrorException("could not load library \"/home/brainiac/Program/python3.7/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a\"\n/home/brainiac/Program/python3.7/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a.so: cannot open shared object file: No such file or directory")│ dlopen(/home/brainiac/Program/python3.7/lib/libpython3.7m.a) ==> ErrorException("could not load library \"/home/brainiac/Program/python3.7/lib/libpython3.7m.a\"\n/home/brainiac/Program/python3.7/lib/libpython3.7m.a.so: cannot open shared object file: No such file or directory")│ dlopen(libpython3.7m) ==> ErrorException("could not load library \"libpython3.7m\"\nlibpython3.7m.so: cannot open shared object file: No such file or directory")│ dlopen(libpython3.7m) ==> ErrorException("could not load library \"libpython3.7m\"\nlibpython3.7m.so: cannot open shared object file: No such file or directory")│ dlopen(libpython3.7) ==> ErrorException("could not load library \"libpython3.7\"\nlibpython3.7.so: cannot open shared object file: No such file or directory")│ dlopen(libpython3) ==> ErrorException("could not load library \"libpython3\"\nlibpython3.so: cannot open shared object file: No such file or directory")│ dlopen(libpython) ==> ErrorException("could not load library \"libpython\"\nlibpython.so: cannot open shared object file: No such file or directory")│ ERROR: LoadError: Couldn't find libpython; check your PYTHON environment variable.│ │ The解決 python executable we tried was /home/brainiac/Program/python3.7/bin/python3.7 (= version 3.7).│ Re-building with│     ENV["PYCALL_DEBUG_BUILD"] = "yes"│ may provide extra information for why it failed.│ │ Stacktrace:│  [1] error(::String) at ./error.jl:33│  [2] find_libpython(::String; _dlopen::typeof(Libdl.dlopen)) at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/deps/buildutils.jl:72│  [3] find_libpython(::String) at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/deps/buildutils.jl:41│  [4] top-level scope at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/deps/build.jl:87│  [5] include(::String) at ./client.jl:457│  [6] top-level scope at none:5│ in expression starting at /home/brainiac/Program/julia/julia-1.5.3/julia-depot/packages/PyCall/BD546/deps/build.jl:43└ @ Pkg.Operations /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Pkg/src/Operations.jl:949

解決方法

再次觀察了初始的報錯信息后,發現需要install the Python package containing the matplotlib module,出現原因在于雖然安裝的解決python3.7存在matplotlib庫,但系統中的出現python3.6未安裝matplotlib,而且在編譯過程中系統路徑的解決問題,雖然設置了ENV["PYTHON"]指向了python3.7的出現安裝位置,但仍不兼容,解決因此為系統預安裝的python安裝matplotlib

# 重置ENV["PYTHON"]julia> ENV["PYTHON"]=""julia> Pkg.build("PyCall")julia> Pkg.add("Conda")julia> import Condajulia> Conda.add("matplotlib")[ Info: Running `conda install -y matplotlib` in root environmentCollecting package metadata (current_repodata.json): doneSolving environment: done## Package Plan ##  environment location: /home/brainiac/Program/julia/julia-1.5.3/julia-depot/conda/3  added / updated specs:    - matplotlib...# 重啟juliajulia> exit()$ juliajulia> using Pkgjulia> Pkg.add("Pyplot")julia> using Random,PyPlotjulia> function f()           Random.seed!(1)           r = rand(50)           @show sum(r)           display(transpose(r))           print(transpose(r))           plot(r)       endf (generic function with 1 method)julia> f()

可以看到彈窗繪圖窗口,問題得到解決。
解決Julia使用PyPlot庫出現ERROR: ArgumentError: hasproperty of NULL PyObject問題 _ JavaClub全棧架構師技術筆記

The end

希望有所幫助,enjoy coding.

作者:盼小輝丶
來源鏈接:https://www.cnblogs.com/for-technology-lover/p/14854813.html

贊(6)
未經允許不得轉載:>貴州網站建設公司 » 解決Julia使用PyPlot庫出現ERROR: ArgumentError: hasproperty of NULL PyObject問題
国产欧美精品