"conda init" prevents anaconda-navigator from working on all but base environment - linux

After running conda init from the terminal I am only able to run from the terminal anaconda-navigator from the base environment of anaconda. I want to make it so that I can run anaconda-navigator from any environment including no environment.
I started down this because conda activate myenv would not work. It recommended running conda init; so I did. Previously I could run anaconda-navigator from any anaconda environment and it would pop up but now if I try from anything but base it doesn't work and I get this error message "anaconda-navigator: command not found". However if I enter conda activate into the terminal to bring on the base environment the command works.
I just got done with a clean install of anaconda3 using the recommended steps https://docs.anaconda.com/anaconda/install/linux/
If I delete what conda init added to my .bashrc and add in
export PATH=/home/yourUserName/anaconda3/bin:$PATH
then anaconda-navigator works again from any environement but conda activate myenv stops working.
FYI: I ran conda config --set auto_activate_base False after installing anaconda3
I expect to be able to run anaconda-navigator from any anaconda environment and to be able to use conda activate myenv. Right now I can do one or the other by modifying my .bashrc

Related

Cannot connect to rust kernel from a jupyter server in a conda env

I have been trying to install a Rust kernel for a Jupyter server inside a dedicated conda environment but I get errors.
Slighty adjusting steps from:
https://depth-first.com/articles/2020/09/21/interactive-rust-in-a-repl-and-jupyter-notebook-with-evcxr/
conda create -n rusttest
conda activate rusttest
conda install -c conda-forge rust jupyterlab
conda install -c anaconda cmake -y
cargo install evcxr_jupyter
Add $HOME/.cargo/bin to my PATH variable (export PATH)
evcxr_jupyter --install (here I already see the kernel is installed outside the env)
jupyter lab
The kernel is visible on the dashboard however when I try to start a notebook with it the connection fails and I get:
Error: Failed to find sysroot for Cargo.toml file /tmp/.tmpbZ0Pkw/Cargo.toml. Is rust-src installed?
I have tried manually:
jupyter kernelspec install {MY_PATH_DURING_PKG_INSTALLATION}/Jupyter/kernels/rust --sys-prefix
And I get:
[InstallKernelSpec] Installed kernelspec rust in {MY_PATH}/miniconda3/envs/rusttest/share/jupyter/kernels/rust
Which seems OK (inside the correct conda env) but the error persists.
Is there any way to add a working kernel just to this one jupyter server inside that env?
(I want Rust to be gone when I start jupyter lab from another conda env)
EDIT
After digging into this I think the first thing is to get rust-src installed inside that conda environment... I don't know how...
Solved:
I needed to download https://static.rust-lang.org/dist/2022-05-19/rust-src-1.61.0.tar.gz manually and extract it under the env dir such that XXX/miniconda3/envs/rusttest/lib/rustlib/src/rust exists.

Start Anaconda from specific env

Having trouble to start Ananconda from particular env
I use zsh shell on macOS Monterey
Create env: conda create -n DC python=3
(DC) conda activate DC
(DC) anaconda navigator
zsh: command not found: anaconda
Before that i did install some packages via: (DC) conda install numpy
Anaconda easy start from base at the same time.
Maybe i do not understand how it works? Maybe it Anaconda Navigator can only start from base.
In your third line, you are missing -. It should be like this.
anaconda-navigator

How to create new Anaconda Environments within JupyterHub and bind a Environment to a new Jupyter- Notebook?

I installed JupyterHub using Docker container.
When I log in the web interface, I see the following environment options:
After a while of loading, I see the Launcher tab as follows:
Now, I would like to create some new Anaconda Environments (MyDevEnvPy3.7, MyTestEnvPy3.7, MyDevEnvPy3.8, MyTestEnvPy3.8), and start a new JupyterNotebook that uses exactly one of these Anaconda Environments mentioned above.
The idea is, that I'd be able to configure each Anaconda Environment with different packages and python versions (i.e. 3.7 or 3.8).
Especially in the case, if I need to upgrade some Python packages, i.e. in my MyDevEnvPy3.7, I would like to upgrade the Python packages first in MyTestEnvPy3.7, to see if my code is still running. Then I would like to do like this using MyDevEnvPy3.7.
How can I do this?
Or is it even possible?
I've only worked with the Anaconda Navigator So far. Anaconda Navigator was my starting point, where I configured my Environments in the "Environment" tab first, and then switched to the "Home" tab, selected the Anaconda Environment to be used and launched the Jupyter Notebook (using this Environment). But now in JupyterHub, I don't have a clue, what's the best practice to start a Jupyter Notebook using a specific Anaconda Environment ...
This is pretty much a standard functionality provided by Jupyter/IPython, which technically is called 'adding new kernel'. Please follow these steps (in a shell terminal):
Say you have a conda env named MyTestEnvPy3.8. Activate this env.
Install ipykernel in the conda env you want to add to Jupyter:
$ conda install ipykernel
Install the kernel
$ python -m ipykernel install --user --name test --display-name "MyTestEnvPy3.8"
You can always change the name (how this kernel appears in your jupyter directory) and display-name (how it appears in the JupyterLab's 'Select Kernel' window).
Check if you installed the kernel successfully:
$ jupyter kernelspec list
And now you can find the kernel you installed in JupyterLab's 'Select Kernel' window. To interface you called 'launcher' is the start window of JupyterLab. JupyterHub hosts multiple Jupyter server, once you launch the JupyterLab from it, you are in the world of JupyterLab!
There's no such thing as 'bind a kernel with the notebook', notebook is just a file format, when you open it in JupyterNotebook or JupyterLab interface, you can switch between the kernels anytime.
I finally managed to create differenct Anaconda Environments:
Open "Terminal" in Launcher tab
Paste in the following commands:
# Creates a new Anaconda Environment called "MyDevEnvPy3.7" using Python Version 3.7
# in silent mode (parameter "-y")
conda create -n MyDevEnvPy3.7 python=3.7 -y
# Activates the new created Anaconda Environment "MyDevEnvPy3.7"
conda activate MyDevEnvPy3.7
# Installs "ipykernel" in active Anaconda Environment "MyDevEnvPy3.7" in silent mode
conda install ipykernel -y
# Installs new Kernel called "MyDevEnvPy3.7" in Anaconda Environment "MyDevEnvPy3.7"
python -m ipykernel install --user --name MyDevEnvPy3.7 --display-name="MyDevEnvPy3.7"
# Deactivates the new created Anaconda Environment "MyDevEnvPy3.7"
conda deactivate
# Creates a new Anaconda Environment called "MyTestEnvPy3.7" using Python Version 3.7
# in silent mode (parameter "-y")
conda create -n MyTestEnvPy3.7 python=3.7 -y
# Activates the new created Anaconda Environment "MyTestEnvPy3.7"
conda activate MyTestEnvPy3.7
# Installs "ipykernel" in active Anaconda Environment "MyTestEnvPy3.7" in silent mode
conda install ipykernel -y
# Installs new Kernel called "MyTestEnvPy3.7" in Anaconda Environment "MyTestEnvPy3.7"
python -m ipykernel install --user --name MyTestEnvPy3.7 --display-name="MyTestEnvPy3.7"
# Installs "numpy" in active Anaconda Environment "MyTestEnvPy3.7" in silent mode
conda install numpy -y
# Deactivates the new created Anaconda Environment "MyTestEnvPy3.7"
conda deactivate
# Creates a new Anaconda Environment called "MyDevEnvPy3.8" using Python Version 3.8
# in silent mode (parameter "-y")
conda create -n MyDevEnvPy3.8 python=3.8 -y
# Activates the new created Anaconda Environment "MyDevEnvPy3.8"
conda activate MyDevEnvPy3.8
# Installs "ipykernel" in active Anaconda Environment "MyDevEnvPy3.8" in silent mode
conda install ipykernel -y
# Installs new Kernel called "MyDevEnvPy3.8" in Anaconda Environment "MyDevEnvPy3.8"
python -m ipykernel install --user --name MyDevEnvPy3.8 --display-name="MyDevEnvPy3.8"
# Deactivates the new created Anaconda Environment "MyDevEnvPy3.8"
conda deactivate
# Creates a new Anaconda Environment called "MyTestEnvPy3.8" using Python Version 3.8
# in silent mode (parameter "-y")
conda create -n MyTestEnvPy3.8 python=3.8 -y
# Activates the new created Anaconda Environment "MyTestEnvPy3.8"
conda activate MyTestEnvPy3.8
# Installs "ipykernel" in active Anaconda Environment "MyTestEnvPy3.8" in silent mode
conda install ipykernel -y
# Installs new Kernel called "MyTestEnvPy3.8" in Anaconda Environment "MyTestEnvPy3.8"
python -m ipykernel install --user --name MyTestEnvPy3.8 --display-name="MyTestEnvPy3.8"
# Installs "numpy" in active Anaconda Environment "MyTestEnvPy3.8" in silent mode
conda install numpy -y
# Deactivates the new created Anaconda Environment "MyTestEnvPy3.8"
conda deactivate
Select "File" --> "New Launcher"
Now, you should see the 4 new Anaconda Environments:
By selecting the desired Anaconda Environment in the Notebook section, a new Jupyter Notebook will be launched, and is bound to the selected Anaconda Environment.
Let's check this:
As you can see on the upper right side, the current selected Anaconda Environment is MyDevEnvPy3.7. We expect the Python version 3.7, and that numpy can't be imported, as it wasn't installed in this Anaconda Environment before.
As you can see on the upper right side, the current selected Anaconda Environment is MyTestEnvPy3.7. We expect the Python version 3.7, and that numpy can be imported, as it was installed in this Anaconda Environment before.
As you can see on the upper right side, the current selected Anaconda Environment is MyDevEnvPy3.8. We expect the Python version 3.8, and that numpy can't be imported, as it wasn't installed in this Anaconda Environment before.
As you can see on the upper right side, the current selected Anaconda Environment is MyTestEnvPy3.8. We expect the Python version 3.8, and that numpy can be imported, as it was installed in this Anaconda Environment before.

Creating a new environment once virtualenv has been installed

I have successuly installed virtualenv using pip install virtualenv. Then i created a new environment under
(base) C:\Users\xxxxxx\PythonScripts\TwitterTutorial>
using the command virtualenv myenv
then as expected a new environment is created under
C:\Users\xxxx\PythonScripts\TwitterTutorial\myenv
The next step is to activate this environment using this command
(base) C:\Users\xxxx\PythonScripts\TwitterTutorial>.\myenv\Scripts\activate
My issue is that the response is as follows:
(myenv) (base) C:\Users\XXXXXX\PythonScripts\TwitterTutorial>
As you can see, the myenv environment is activated on top of the base one. I found that weird because i expected a response similar to this
(myenv) C:\Users\XXXXXX\PythonScripts\TwitterTutorial>
Maybe the command .\myenv\Scripts\activate is wrong?
On a different note, i have created environments in the past and to activate them i usually do conda activate env and it worked successfully for that particular task (not for this one unfortunately)
Many Thanks for your help

Using a Conda Environment in Jupyter via Miniconda

Has anyone found a way to successfully set up an environment for a jupyter notebook without having the full version of Anaconda installed on your system? I am using Miniconda and have been unable to use a conda environment with the jupyter notebook platform. Note that with Miniconda source activate myenv will not work.
I also tried using ipykernel which did successfully get an environment to appear in my notebook (via the command: python -m ipykernel install --user --name myenv). However, this environment is still made as a copy of my base environment. Commands similar to conda create -n test_env python=3.7 don't seem to be compatible with ipykernel unless I am missing something.
You don't need to run ipython from the environment you are adding.
Since you've got an environment with jupyter, lets call that Jenv.
go to your miniconda install location
Scripts/activate Jenv
conda create -n SomeOther_vEnv python=3.6.8 whateverPackagesYouWant
python -m ipykernel install --sys-prefix --name SomeOther_vEnv --display-name "foo"
Now jupyter when started from your Jenv should see "foo". You can't start jupyter from foo, but you can use it in a jupyter server started from Jenv. (unless whateverPackagesYouWant included jupyter of course)

Resources