Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

python - conda list packages not from active environment in Jupyter

I would like to run a Jupyter notebook (on a distant server) using packages installed in a environment crocoanalysis

conda create crocoanalysis
conda activate crocoanalysis
conda install netcdf4

Worked perfectly, package installed :

(crocoanalysis) conda list
# packages in environment at /home6/datahome/abarboni/.conda/envs/crocoanalysis:
[...]
netcdf4                   1.5.3            py38hbf33ddf_0

Now I shared this environment with Jupyter notebook kernel, and run the notebook (changing the port to access it on my local computer, but this is a priori not an issue here):

(crocoanalysis) python -m ipykernel install --user --name=crocoanalysis
(crocoanalysis) nohup jupyter notebook --no-browser --port=8090

Running the notebook, the environment is available and active, but packages listed are not the ones of the active environment, instead it keeps using the base environment... What is missing ?

Jupyter notebook output

I also tried to put the environment directory to the PYTHONPATH but 1) it did not work , 2) this is not exactly what I'm looking for : (adding into the .bashrc)

export PYTHONPATH="${PYTHONPATH}:/home6/datahome/abarboni/.conda/envs/crocoanalysis"

I also tried running the notebook outside this new environment but does not work either


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are two popular ways to open Jupyter notebook in particular environment.

  1. Simple If you are using Anaconda Navigator then open Anaconda Navigator and select Environment from dropdown Manu. Finally, open Jupyter Notebook if it's not install first install then open. enter image description here

  2. Preferable you can use Anaconda Prompt for opening environment and then open jupuyter notebook.

First you can check if the environment you want is there or not. you can check by this command,

conda env list

Then if environment is available then use activate command for activate particular environment,

conda activate Tensorflow

For installing Jupyter notebook you can simply use,

pip3 install Jupyter 

Finally, for opening Jupyter notebook,

jupyter notebook

After all this if any of these solution is not showing your packages then you can use one last method,

  1. Bonus Do not install any packages while creating environment. Use given method for creating environment or see the documentation for Jupyter notebook and Anaconda prompt
    For How to create envrionment and how to install Jupyter notebook in anacodna prompt.

After everything open Jupyter notebook and type installation command in chunk with '!' to install package in particular environment. such as,

!pip install numpy 

That should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...