Conda — Troubleshoot “OSError: libiconv.so.2: cannot open shared object file: No such file or directory”
It all happens when trying to update nodejs associated with base conda environment, and it fail, roll back and get conda into this status
Symptom
except “conda — help” or “conda -version”, all other conda command would throw exception with “OSError: libiconv.so.2: cannot open shared object file: No such file or directory”
Online Reference
Some issues report similar behavior while leading no direct answer, e.g.:
https://github.com/conda/conda/issues/8838 ‑ Connect your account to preview links
Trial that failed (feel free to skip)
Following the Anaconda guide of fixing corrupted installation (30 min per trial)
This would lead to failure at last step, as the .sh script hard-coded to use offline installation and when your existing conda env have some package installed already, it would make the installation throw exception
Twist the above by using switch -u (which suggested by the github issue post above)
Exception thrown in the same manner
Working solution (using conda-exec to upgrade conda)
For some lucky reading up, there is something called conda-exec, basically it’s conda executable, once can download from here:
https://repo.anaconda.com/pkgs/misc/conda-execs/
After download, one would need to chmod +x <the file> so it cna execute
Then do:
./conda-exec-downloaded.exe install -p <full path to your corrupted env> conda
Now it might be able to run “conda list”, but once running other conda action, this failed again with same error, turns out, check the base environment in “conda list”, the libiconv is installed as package but with a version 0, so lastly run:
conda udate libiconv
Now this is all set.
End result: conda back, base environment almost need to reinstall all packages(which for my case is only jupyterlab)
2nd thought on why the environment get that messy, I guess is because I mainly use conda-forge package but mixed with some default channel package, and the uninstall with hidden dependency (libiconv) mess things up
Lesson learnt: generate requirement files per virtual environment from time to time, so I can safely ditch the whole conda and setup a new one (it’s not the complete story, as some package have side download [ like spacy language model ] or config that need separate document per environment.
Script created: https://medium.com/@stephencowchau/simple-bash-script-to-export-all-conda-virtual-environments-2e337cd9480