Why do I can't run python scripts after installing the conda environment?

I want to run some demo of rivgraph on my jupyter server,however when I try to launch the code, it crashed like this:

Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 from rivgraph.classes import river
2 import matplotlib.pyplot as plt
3 import os

ModuleNotFoundError: No module named ‘rivgraph’

And before this I have installed rivgraph’s conda environment:

(rivgraph) jupyterhub@vm-jupyterhub-server:~/graphs$ conda env list
rivgraph * /home/jupyterhub/.conda/envs/rivgraph
base /opt/conda
db-base /opt/conda/envs/db-base
gis-base /opt/conda/envs/gis-base
lf /opt/conda/envs/lf
ml-base /opt/conda/envs/ml-base
r-base /opt/conda/envs/r-base

So how to solve this problem?

Those instructions look kinda janky. You likely want to install those rivgraph packages into your environment of choice, not create a new environment, as layering envs with GDAL will cause… suffering.

You can potentially make that happen by specifying an env name, e.g. -n gis-base

conda env update -n gis-base --file environment.yml

But much better would be to create a new gis-base-with-rivgraph.yml of whatever packages you want unioned with the rivgraph-provided environment.yml so that the full solve is done at once.

note: you probably want to be using mamba to do these solves to

Otherwise, just for troubleshooting:

From inside your kernel, verify you are in the environment you expect:

import sys
print(sys.executable, sys.prefix)

It may also be worth looking at the output of:

jupyter kernelspec list --json

It’s important the argv all have at least accurate python binaries (not just python or python3).

1 Like

No,I run “conda env create --file environment.yml” rather than “conda env update -n gis-base --file environment.yml” to install this environment,and I don’t use mamba.
And the server tells me this:

if you really have your heart set on multiple kernel environments, you’ll want to get more intimately acquainted with the above list command, and ensure all of them are fully specifiying the location of python or python3, which might require messing with some json files in jupyter --paths.

Alternately, with the rivgraph env activated, install jupyterlab into that, and run from there.

Finally, you could also consider nb_conda_kernels, though I don’t know how much it’s maintained these days.

1 Like