Exporting and rebuilding conda virtual environment

Table of Contents


After installing Miniconda on a new Windows 10 PC and setting up a virtual environment for running xhycom, xarray.Dataset.hvPlot does not work. There seems to be a problem with the handling of datetime64; pandas get_loc(key) returns a KeyError in datetimes.py. get_loc(key) seems to take an index and there seems to be a confusion between the index and the integer value of datetime64(ns). Since I do not know the solution, I decide to rebuild the virtual environment that is working well.

This problem has been discussed in this site. It may be associated with some incompatibility between xarray 0.16 and pandas 1.1 (works with pandas 1.05).

Exporting the virtual environment to yaml

Suppose the name of the virtual environment as rs and the name of the yaml file as rs.yaml, and work in the base environment:

conda env export -n rs -f rs.yaml

If you specify > instead of -f, the encode becomes UTF-16, which will result in an error as described in here. A yaml file created with > can be fixed by opening the yaml file with an editor, e.g., Hidemaru Editor, and converting its encode to UTF-8 LT, which works fine.

Rebuilding virtual environment

Install Miniconda (the latest version is fine) on the PC where you want to restore the virtual environment and work in the base environment:

conda env create -n rs -f rs.yaml

You will often get the following errors; then delete the corresponding lines in the yaml file and run it again.


Run Jupyter Lab

When I started Jupyter Lab for the first time in the rebuilt virtual environment, a pop-up of Build recommended appeared, which should be accommodated:

[W 14:30:34.899 LabApp] Build recommended
[W 14:30:34.900 LabApp] jupyter-matplotlib needs to be included in build
[I 14:30:44.529 LabApp] Building jupyterlab assets (build:dev)

In addition, building jupyter labextension for pyviz is required as introduced in this site for xhycom.

jupyter labextension install @pyviz/jupyterlab_pyviz

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.