Skip to content

Environment reinitialization if failed #130

Closed
@johnnychen94

Description

@johnnychen94

Because CondaPkg doesn't verify the name/version when pkg> conda add xxx, it is very likely that users hit a broken CondaPkg.toml file and thus using PythonCall fails. I'm wondering if there's a way to quickly fix this in the same Julia session?

MWE:

julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 12th Gen Intel(R) Core(TM) i9-12900K
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, goldmont)
Environment:
  JULIA_CONDAPKG_EXE = /home/jc/miniconda3/bin/conda

(@v1.7) pkg> activate --temp
  Activating new project at `/tmp/jl_UJo19L`

julia> using CondaPkg

(jl_UJo19L) pkg> conda add nothingness

(jl_UJo19L) pkg> conda status
CondaPkg Status /tmp/jl_UJo19L/CondaPkg.toml
Not Resolved (resolve first for more information)
Packages
  nothingness

(jl_UJo19L) pkg> add PythonCall
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_UJo19L/Project.toml`
  [6099a3de] + PythonCall v0.6.1
  ...

julia> using PythonCall
    CondaPkg Found dependencies: /tmp/jl_UJo19L/CondaPkg.toml
    CondaPkg Found dependencies: /home/jc/.julia/environments/v1.7/CondaPkg.toml
    CondaPkg Found dependencies: /home/jc/.julia/packages/PythonCall/Z6DIG/CondaPkg.toml
    CondaPkg Creating environment
             │ /home/jc/miniconda3/bin/conda
             │ create
             │ -y
             │ -p /tmp/jl_UJo19L/.CondaPkg/env
             │ --override-channels
             │ --no-channel-priority
             │ nothingness
             │ python >=3.5,<4-c conda-forge
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - nothingness

julia> shutil = pyimport("shutil")
ERROR: UndefVarError: pyimport not defined
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

For instance, I'd like to hotfix this via:

(jl_UJo19L) pkg> conda rm nothingness

(jl_UJo19L) pkg> conda status
CondaPkg Status /tmp/jl_UJo19L/CondaPkg.toml (empty)
Not Resolved (resolve first for more information)

julia> using PythonCall

julia> shutil = pyimport("shutil")
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] PyUnicode_DecodeUTF8
   @ ~/.julia/packages/PythonCall/Z6DIG/src/cpython/pointers.jl:297 [inlined]
 [2] pystr_fromUTF8
   @ ~/.julia/packages/PythonCall/Z6DIG/src/concrete/str.jl:1 [inlined]
 [3] pystr_fromUTF8
   @ ~/.julia/packages/PythonCall/Z6DIG/src/concrete/str.jl:2 [inlined]
 [4] pystr
   @ ~/.julia/packages/PythonCall/Z6DIG/src/concrete/str.jl:10 [inlined]
 [5] Py
   @ ~/.julia/packages/PythonCall/Z6DIG/src/Py.jl:138 [inlined]
 [6] macro expansion
   @ ~/.julia/packages/PythonCall/Z6DIG/src/Py.jl:128 [inlined]
 [7] pyimport(m::String)
   @ PythonCall ~/.julia/packages/PythonCall/Z6DIG/src/concrete/import.jl:11
 [8] top-level scope
   @ REPL[14]:1

but it errors unless I restart a new Julia.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions