JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
469 stars 85 forks source link

Unable to install PyPlot (ResolvePackageNotFound conda error) #568

Closed Octogonapus closed 11 months ago

Octogonapus commented 11 months ago

I'm trying to install the latest version of PyPlot on Julia v1.9.1 on Ubuntu 22.04 and getting this error:

julia> using PyPlot
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
Collecting package metadata (current_repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
Solving environment: unsuccessful attempt using repodata from current_repodata.json, retrying with next repodata source.

ResolvePackageNotFound: 
  - conda==23.1.0

Here's a Dockerfile you can build to reproduce the error:

FROM ubuntu:22.04

RUN apt-get update -y && \
    apt-get upgrade -y && \
    apt-get install -y wget && \
    rm -rf /var/lib/apt/lists/*

RUN wget -nv https://julialang-s3.julialang.org/bin/linux/x64/1.9/julia-1.9.1-linux-x86_64.tar.gz && \
    tar xf julia-1.9.1-linux-x86_64.tar.gz && \
    rm julia-1.9.1-linux-x86_64.tar.gz && \
    ln -s /julia-1.9.1/bin/julia /usr/local/bin/julia

ENV PYTHON=""
RUN julia -e 'import Pkg; Pkg.add("PyPlot")'
RUN julia -e 'using PyPlot'

And here is the full error:

 > [5/5] RUN julia -e 'using PyPlot':                                                                                                                                                                               
#0 1.709 [ Info: Installing matplotlib via the Conda matplotlib package...                                                                                                                                          
#0 1.709 [ Info: Running `conda install -y matplotlib` in root environment                                                                                                                                          
#0 2.245 Collecting package metadata (current_repodata.json): ...working... done                                                                                                                                    
#0 21.68 Solving environment: ...working... unsuccessful initial attempt using frozen solve. Retrying with flexible solve.                                                                                          
#0 29.68 Solving environment: ...working... unsuccessful attempt using repodata from current_repodata.json, retrying with next repodata source.
#0 34.31 
#0 34.31 ResolvePackageNotFound: 
#0 34.31   - conda==23.1.0
#0 34.31 
#0 35.52 ERROR: InitError: failed process: Process(setenv(`/root/.julia/conda/3/x86_64/bin/conda install -y matplotlib`,["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "CONDA_PREFIX=/root/.julia/conda/3/x86_64", "PWD=/", "HOME=/root", "CONDARC=/root/.julia/conda/3/x86_64/condarc-julia.yml", "OPENBLAS_MAIN_FREE=1", "PYTHONIOENCODING=UTF-8", "OPENBLAS_DEFAULT_NUM_THREADS=1"]), ProcessExited(1)) [1]
#0 37.01 
#0 37.01 Stacktrace:
#0 37.01   [1] pipeline_error
#0 37.01     @ ./process.jl:565 [inlined]
#0 37.01   [2] run(::Cmd; wait::Bool)
#0 37.17     @ Base ./process.jl:480
#0 37.17   [3] run
#0 37.17     @ ./process.jl:477 [inlined]
#0 37.17   [4] runconda(args::Cmd, env::String)
#0 37.17     @ Conda ~/.julia/packages/Conda/xMClC/src/Conda.jl:128
#0 37.17   [5] add(pkg::String, env::String; channel::String, satisfied_skip_solve::Bool, args::Cmd)
#0 37.17     @ Conda ~/.julia/packages/Conda/xMClC/src/Conda.jl:229
#0 37.17   [6] add (repeats 2 times)
#0 37.17     @ ~/.julia/packages/Conda/xMClC/src/Conda.jl:222 [inlined]
#0 37.17   [7] pyimport_conda
#0 37.17     @ ~/.julia/packages/PyCall/ilqDX/src/PyCall.jl:721
#0 37.17   [8] pyimport_conda
#0 37.17     @ ~/.julia/packages/PyCall/ilqDX/src/PyCall.jl:715 [inlined]
#0 37.17   [9] __init__()
#0 37.17     @ PyPlot ~/.julia/packages/PyPlot/H01LC/src/init.jl:173
#0 37.17  [10] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
#0 37.17     @ Base ./loading.jl:1115
#0 37.17  [11] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
#0 37.17     @ Base ./loading.jl:1061
#0 37.17  [12] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
#0 37.17     @ Base ./loading.jl:1506
#0 37.17  [13] _require(pkg::Base.PkgId, env::String)
#0 37.17     @ Base ./loading.jl:1783
#0 37.17  [14] _require_prelocked(uuidkey::Base.PkgId, env::String)
#0 37.17     @ Base ./loading.jl:1660
#0 37.17  [15] macro expansion
#0 37.17     @ ./loading.jl:1648 [inlined]
#0 37.17  [16] macro expansion
#0 37.17     @ ./lock.jl:267 [inlined]
#0 37.17  [17] require(into::Module, mod::Symbol)
#0 37.17     @ Base ./loading.jl:1611
#0 37.17 during initialization of module PyPlot
#0 37.18 
#0 37.18 caused by: PyError (PyImport_ImportModule
#0 37.26 
#0 37.26 The Python package matplotlib could not be imported by pyimport. Usually this means
#0 37.26 that you did not install matplotlib in the Python version being used by PyCall.
#0 37.26 
#0 37.26 PyCall is currently configured to use the Julia-specific Python distribution
#0 37.26 installed by the Conda.jl package.  To install the matplotlib module, you can
#0 37.26 use `pyimport_conda("matplotlib", PKG)`, where PKG is the Anaconda
#0 37.26 package that contains the module matplotlib, or alternatively you can use the
#0 37.26 Conda package directly (via `using Conda` followed by `Conda.add` etcetera).
#0 37.26 
#0 37.26 Alternatively, if you want to use a different Python distribution on your
#0 37.26 system, such as a system-wide Python (as opposed to the Julia-specific Python),
#0 37.26 you can re-configure PyCall with that Python.   As explained in the PyCall
#0 37.26 documentation, set ENV["PYTHON"] to the path/name of the python executable
#0 37.26 you want to use, run Pkg.build("PyCall"), and re-launch Julia.
#0 37.26 
#0 37.26 ) <class 'ModuleNotFoundError'>
#0 37.26 ModuleNotFoundError("No module named 'matplotlib'")
#0 37.26 
#0 37.26 Stacktrace:
#0 37.26   [1] pyimport(name::String)
#0 37.26     @ PyCall ~/.julia/packages/PyCall/ilqDX/src/PyCall.jl:558
#0 37.26   [2] pyimport_conda
#0 37.26     @ ~/.julia/packages/PyCall/ilqDX/src/PyCall.jl:716
#0 37.26   [3] pyimport_conda
#0 37.26     @ ~/.julia/packages/PyCall/ilqDX/src/PyCall.jl:715 [inlined]
#0 37.26   [4] __init__()
#0 37.26     @ PyPlot ~/.julia/packages/PyPlot/H01LC/src/init.jl:173
#0 37.26   [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
#0 37.26     @ Base ./loading.jl:1115
#0 37.26   [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
#0 37.26     @ Base ./loading.jl:1061
#0 37.26   [7] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
#0 37.26     @ Base ./loading.jl:1506
#0 37.26   [8] _require(pkg::Base.PkgId, env::String)
#0 37.26     @ Base ./loading.jl:1783
#0 37.26   [9] _require_prelocked(uuidkey::Base.PkgId, env::String)
#0 37.26     @ Base ./loading.jl:1660
#0 37.26  [10] macro expansion
#0 37.26     @ ./loading.jl:1648 [inlined]
#0 37.26  [11] macro expansion
#0 37.26     @ ./lock.jl:267 [inlined]
#0 37.26  [12] require(into::Module, mod::Symbol)
#0 37.26     @ Base ./loading.jl:1611
------
Dockerfile:15
--------------------
  13 |     ENV PYTHON=""
  14 |     RUN julia -e 'import Pkg; Pkg.add("PyPlot")'
  15 | >>> RUN julia -e 'using PyPlot'
  16 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c julia -e 'using PyPlot'" did not complete successfully: exit code: 1
stevengj commented 11 months ago

If you don't want PyPlot to install its own Conda distro and use that to install matplotlib, then you shouldn't use ENV PYTHON="".

Octogonapus commented 11 months ago

That's fair, my mistake. Here is our actual use case:

FROM ubuntu:22.04

RUN apt-get update -y && \
    apt-get upgrade -y && \
    apt-get install -y wget python3-venv && \
    rm -rf /var/lib/apt/lists/*

RUN wget -nv https://julialang-s3.julialang.org/bin/linux/x64/1.9/julia-1.9.1-linux-x86_64.tar.gz && \
    tar xf julia-1.9.1-linux-x86_64.tar.gz && \
    rm julia-1.9.1-linux-x86_64.tar.gz && \
    ln -s /julia-1.9.1/bin/julia /usr/local/bin/julia

RUN python3 -m venv venv
RUN . venv/bin/activate && \
    pip install -U pip && \
    pip install -U matplotlib==3.7.0
ENV PYTHON="/root/venv/bin/python"
RUN julia -e 'import Pkg; Pkg.add("PyPlot")'
RUN julia -e 'using PyPlot'

The same error occurs:

 > [7/7] RUN julia -e 'using PyPlot':                                                                                                                                                                               
#0 1.434 [ Info: Installing matplotlib via the Conda matplotlib package...                                                                                                                                          
#0 1.435 [ Info: Running `conda install -y matplotlib` in root environment                                                                                                                                          
#0 1.892 Collecting package metadata (current_repodata.json): ...working... done                                                                                                                                    
#0 17.04 Solving environment: ...working... unsuccessful initial attempt using frozen solve. Retrying with flexible solve.                                                                                          
#0 23.96 Solving environment: ...working... unsuccessful attempt using repodata from current_repodata.json, retrying with next repodata source.
#0 27.86 
#0 27.86 ResolvePackageNotFound: 
#0 27.86   - conda==23.1.0