-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment reinitialization if failed #130
Comments
If a Julia module is imported but its You can always do |
That works but is still inconvenient I think. Is there a way to dynamically add/rm a package? For instance, the following steps currently fail because CondaPkg tries to drop the current environment. julia> np = pyimport("numpy")
ERROR: Python: ModuleNotFoundError: No module named 'numpy'
Python stacktrace: none
Stacktrace:
[1] pythrow()
@ PythonCall ~/.julia/packages/PythonCall/Z6DIG/src/err.jl:94
[2] errcheck
@ ~/.julia/packages/PythonCall/Z6DIG/src/err.jl:10 [inlined]
[3] pyimport(m::String)
@ PythonCall ~/.julia/packages/PythonCall/Z6DIG/src/concrete/import.jl:11
[4] top-level scope
@ REPL[2]:1
(@v1.7) pkg> conda add numpy
(@v1.7) pkg> conda resolve -f
CondaPkg Found dependencies: /home/jc/.julia/environments/v1.7/CondaPkg.toml
CondaPkg Found dependencies: /home/jc/.julia/packages/PythonCall/Z6DIG/CondaPkg.toml
CondaPkg Removing environment
│ /home/jc/miniconda3/bin/conda
│ remove
│ -y
│ -p /home/jc/.julia/environments/v1.7/.CondaPkg/env
└ --all
CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again |
You're not supposed to add or remove packages while you've got Python running. This is because the versions of packages installed can become incompatible with the versions you already have loaded. So in the case of PythonCall you should use CondaPkg to get your dependencies right before loading PythonCall, and then not touch them. |
Okay, I see there's no intent to provide another solution than "restarting the entire Julia session" so I'm closing this. Just one last word. I opened this issue because this is something that PyCall allows, e.g., julia> using PyCall
julia> seaborn= pyimport("seaborn")
ERROR: PyError (PyImport_ImportModule
The Python package seaborn could not be imported by pyimport. Usually this means
that you did not install seaborn in the Python version being used by PyCall.
...
# switch to other terminal and install seaborn, then switch back
julia> seaborn = pyimport("seaborn")
PyObject <module 'seaborn' from '/home/jc/miniconda3/envs/conda_jl/lib/python3.9/site-packages/seaborn/__init__.py'> |
Sure you can do that, but it's not recommended for the reasons above. It will probably actually be fine 99% of the time in interactive use, but CondaPkg is intentionally conservative because it's primary purpose is to create Conda environments reproducibly. I'll think about making the interactive experience a bit nicer - maybe a flag somewhere which just adds a package to the environment without reinstalling everything. |
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 thususing PythonCall
fails. I'm wondering if there's a way to quickly fix this in the same Julia session?MWE:
For instance, I'd like to hotfix this via:
but it errors unless I restart a new Julia.
The text was updated successfully, but these errors were encountered: