Conda doesn't recognize -add channels command - anaconda

I am new to Anaconda notebook hosted on the Anaconda Cloud.
I have set up the new environment (python_programming) and have changed from base to the new environment. But when I enter the -add channels command, I get an error response from conda that it does not recognize the arguments. Screenshot attached.
How to fix this?
Thank you.
Entered conda -add channels command but it was not recognized by the Anaconda Terminal.

Instead use
conda config -add channels conda-forge
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html

You need to use
conda config --add channels conda-forge
Example:
example_1
But using --append is better than --add, otherwise the defaults channel get lesser priority than the added one, conda-forge in this case.
conda config --append channels conda-forge
Exmaple:
example_2

Related

conda creation NGS environment, sra-tools fastqc multiqc samtools bowtie2 hisat2 subread

I cannot easily create an environment with conda containing the NGS tools I want. I reinstalled conda to get a fresh start since I had many python packages in the base env. I also took the occasion to install the full anaconda3 instead of miniconda I had before now I have way enough space.
Although all the packages are available via bioconda the only 2 i can add to my env are fastqc and multiqc. Before that I could install sra-tools and fastqc in the base env with miniconda3.
Config: MacOS Monterey 12.1 M1 chip. migration from my old macbook air with the lastest time machine bkp. I uninstalled miniconda with the anaconda-clean procedure and after that I also removed a python 3.9.5 I had in the apps folder I had initially installed to start learning 1yr ago before knowing about conda.
Also to be mentioned in case it may help: anaconda-navigator was not installed by the Anaconda3-2022.05-MacOSX-arm64.pkg (sha256 integrity check was ok)
in following the check installation/navigator troubleshooting on anaconda website I came across an error upon launching spyder:
```(ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets')```
Does somebody know where this unability to find the packages comes?
Thank you for your help!
best, Daniel
Env creation command and console output:
(base) mymac:~ D________$ conda create --name ngstools fastqc multiqc sra-tools samtools bowtie2 hisat2 subread -c conda-forge -c bioconda -c bioconda/label/cf201901
Terminal output:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
hisat2
subread
bowtie2
samtools
sra-tools
Current channels:
https://conda.anaconda.org/conda-forge/osx-arm64
https://conda.anaconda.org/conda-forge/noarch
https://conda.anaconda.org/bioconda/osx-arm64
https://conda.anaconda.org/bioconda/noarch
https://conda.anaconda.org/bioconda/label/cf201901/osx-arm64
https://conda.anaconda.org/bioconda/label/cf201901/noarch
https://repo.anaconda.com/pkgs/main/osx-arm64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/osx-arm64
https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
Prefatory Comments
That is not a configuration I would recommend to bioinformatics users with M1 machines at the moment. There is no support yet for osx-arm64 in Bioconda. I expect one would find the least configuration issues by having everything in emulation (osx-64) from the base. Or you can continue with the osx-arm64 base (as you have now), but create new environments with the subdir setting. The answer below shows steps in this direction.
Also, I would very much avoid Anaconda/Miniconda. Mambaforge base is what I recommend to all bioinformaticians. And set the Bioconda channels globally.
Lastly, only advanced users should use channel labels (e.g., bioconda/label/cf201901). I realize they automatically show up on Anaconda Cloud, but they are only ever applicable in specialized circumstances, which most users will never encounter.
Immediate workaround
If you want to keep the osx-arm64 base, then you'll need to create a osx-64 environment for the NGS tools. I recommend the following protocol for best practice:
## create empty environment
conda create -n ngstools
## activate environment
conda activate ngstools
## configure architecture
conda config --env --set subdir osx-64
## configure channels for Bioconda
conda config --env --add channels defaults
conda config --env --add channels bioconda
conda config --env --add channels conda-forge
## install packages
conda install fastqc multiqc sra-tools samtools bowtie2 hisat2 subread
It's convoluted and, until osx-arm64 sees full support, you'd have to do this for every environment that requires emulation and Bioconda. Hence, why I recommend instead that you reinstall a osx-64 base (Mambaforge), which would just work.

dyld: Library not loaded: #rpath/libdeflate.so

I am a mac user with operating system, macOS Mojave 10.14.6. I have installed bcftools in my conda environment py3.9 (Python 3.9).
The following code is my installing command line:
conda install -c bioconda bcftools
but when I try to use it, the shell told me there is something wrong with it.
dyld: Library not loaded: #rpath/libdeflate.so
Referenced from: /opt/anaconda3/envs/py3.9/bin/bcftools
Reason: image not found
Abort trap: 6
when I went the path (/opt/anaconda3/envs/py3.9/bin/bcftools), I found there is only a binary file.
I hope that someone can help me, thanks!
Bioconda has very specific channel requirements, namely, it builds packages using Conda Forge builds, not Anaconda (defaults). The correct ad hoc installation command for Bioconda packages is:
conda install -c conda-forge -c bioconda -c defaults bcftools
However, if you have an Anaconda base (as opposed to Miniforge), it is usually not a good idea to prioritize the conda-forge channel when installing in base (can lead to lots of channel switching and long solves). Instead, create a new environment and configure it to use the correct channels:
# create new environment
conda create -n my_env
# activate environment
conda activate my_env
# set channels for environment
conda config --env --add channels defaults
conda config --env --add channels bioconda
conda config --env --add channels conda-forge
# no need to use ad hoc `-c` flags
conda install bcftools

Stuck at Solving Environment on Anaconda

I am running OSX Catalina. After downloading Anaconda, I'm having trouble downloading external packages. I tried in both the GUI and the terminal, but the process keeps getting stuck at "Solving environment".
I understand creating a new environment can be a workaround, but I would rather fix the issue at hand.
Any ideas?
The following steps may work to resolve the issue.
conda config --remove channels conda-forge
conda config --add channels conda-forge
if it doesn't work then try this
conda update conda
if nothing works try seeing this github solution, it worked for many.
use this:
conda config --set channel_priority strict
pay attention that it is channel_priority and not priority_channel
running
conda config --set channel_priority flexible
worked for me
Update, still ran into some issues so I found Mamba, and oh my god my life changed conda is the worst package manager ever
all my issues were solved when I used mamba
# install mamba
conda install -n base conda-forge::mamba
# use mamba
mamba install pandas
Please, check that python is actually listed in environment.yml or conda create -n your_environment --file requirements.txt python=3.7.
Otherwise, conda is traversing all versions of python available.
Check that Python is listed.
for updated conda version over 4.12.0 'Libmamba' with advantages like:
Improve conda’s resolving speeds by 50-80%*
Maximize backwards compatibility so as to not break any current
functionality
Build the plugin infrastructure for others to create custom solvers
are mentioned in Anaconda's official blog post, A Faster Solver for Conda: Libmamba
so for making libmamba your default solver(make sure your conda version is 4.12):
conda install -n base conda-libmamba-solver
and to try it temporarily:conda create -n demo --experimental-solver=libmamba --dry-run install <some package>
It might be taking long because of package version conflicts. My solution was to install some packages using pip instead of conda install.
For example:
pip install tensorflow
Try this in a new environment so it doesn't mess up your existing ones.
conda config --remove channels conda-forge
conda config --set channel_priority flexible
This fixed the problem with the solving environment step. After that I was able to update packages (such as conda and anaconda) and sort out various dependency issues.
I've had this issue running macOS Monterey, with conda taking an age to solve the environment, failing, and causing immense frustration.
My first suggestion would be to install Mamba [1], of which you have two options. If conda does work, but just takes a long time, you can try
conda install mamba -n base -c conda-forge
If conda won't install anything at all, you can try uninstalling anaconda3 using conda install anaconda-clean, then anaconda-clean --yes, then rm -rf anaconda3,rm -rf ~/anaconda3 and rm -rf ~/opt/anaconda3. From there, download the Mambaforge .sh file [1], and run
bash ~/Downloads/Mambaforge-MacOSX-x86_64.sh
Follow the install, and treat mamba exactly how you would treat conda. Then it's simply a matter of selecting your interpreter in your IDE of choice! You'll find that mamba is way faster.
Failing this, you can try using which pip, and then pip install [your package]. I wouldn't advise this one for lots of packages, as you are essentially bypassing the dependancy check, however for small things, it should work fine. Try it, and uninstall it if you get any clashes. Happy fixing!
I had similar problems trying to install external packages such as graph-tools and I solved it by creating a new environment. I know you prefer other options but it's the only thing that worked for me.
I was having the same issue while creating my conda environment using environment.yml file.
conda env create -f environment.yml
My issue was fixed by updating conda and setting channel priority to strict:
conda update conda
conda config --set channel_priority strict
set conda-forge highest priority, remove defaults channel
conda config --add channels bioconda
conda config --add channels conda-forge
conda config --remove channels defaults
conda config --set channel_priority strict
make sure most your package from conda-forge, not defaults.
If it doesn't work, try
conda update --all
conda clean -a //use with caution
The following works for me.
Spin-off on https://github.com/conda/conda/issues/11919
Instead of waiting (maybe hours) to resolve SAT (A well-known NP-Complete problem) environment, it would be helpful for you to install the faster Conda resolver (https://www.anaconda.com/blog/a-faster-conda-for-a-growing-community). Just so you know, the resolver is not installed by default with Anaconda, so you need to install it manually.
sudo conda update -n base conda
sudo conda install -n base conda-libmamba-solver
conda config --set solver libmamba
Rerun conda install
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 \
-c pytorch -c nvidia
I hope you find it useful.
you may also want to check your ~/.conda directory permissions. I installed conda on my MacOS using Homebrew and for some reason this directory had only read/write permissions for root. After changing the permissions and following the instructions from above, everything works smooth and fast now
upgrading conda base package has fixed it.
ref : https://docs.conda.io/projects/conda/en/latest/user-guide/install/rpm-debian.html
Sounds very simple but make sure you're in your environment
conda activate <Your Environment>
i had the same problem when i tried to install packages for my env i tried the conda env update -f environment.yml even doesn't worked (in yml file i have name: tf2 that i point to update my env still doesnt upgraded)
but now which i tried this it worked :d
conda activate tf2
conda env update -n tf2 -f environment.yml --prune
After some reading I found out the .condarc file is not created by default (is stated by the official Anaconda documentation. So what I did is delete de .condarc file and then used the following command
conda config --set channel_priority flexible
And then it got unstuck
Then I tried conda update conda just to test it, and everything worked again.
For other weary travelers: if you find conda taking hours to solve an environment, try install packages one at a time. Works like a miracle.
Another solution that may not have been mentioned is that the dependencies that you may want to install within your conda env are already installed.
Using conda-list within your env you may confirm.
With a package such as tethys platform they did not mentioned this and i was left wondering why my conda install process kept getting stuck at the solving stage. Late into the night bingo checked into my env and sure enough the dependencies where already installed. Now can progress to my next phase.
I faced the same issue for tensorflow and solved it by doing the next:
create new environment conda create -n tf tensorflow
moved to the new environemnt conda activate tf
downloaded my package there.
it worked and solved the issue, I think this happened due to not completing a previous install and got stuck in the middle.
Try installing ANACONDA3 2019-3.
I had similar issues but after installing the above version of anaconda they were all fixed.
Choose one:
Start fresh with a new Anaconda installation. Pay attention during
installation to make sure that your install path is a subfolder of
your home folder, such as /Users/me/anaconda3
Start fresh using the
.sh installer instead of the .pkg installer. This installer makes it
simpler to choose the destination path, and gives you more choice on
how you want your shell to behave.
check out the link for more details
This is another answer for environment failure, but for windows OS
This fixed the hang for me. Although the install went on to fail.
conda config --set priority_channel strict

The environment is inconsistent, please check the package plan carefully

I tried to update or install new packages from anaconda and lately, this message has appeared:
The environment is inconsistent, please check the package plan carefully
The following package are causing the inconsistency:
- defaults/win-32::anaconda==5.3.1=py37_0
done
I tried with conda clean --all and then conda update --all but it persists.
Conda Info
active environment : base
active env location : C:\Users\NAME\Continuum
shell level : 1
user config file : C:\Users\NAME\.condarc
populated config files : C:\Users\NAME\.condarc
conda version : 4.6.11
conda-build version : 3.17.7
python version : 3.7.3.final.0
base environment : C:\Users\NAME\Continuum (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-32
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/win-32
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/win-32
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-32
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\NAME\Continuum\pkgs
C:\Users\NAME\.conda\pkgs
C:\Users\NAME\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\NAME\Continuum\envs
C:\Users\NAME\.conda\envs
C:\Users\NAME\AppData\Local\conda\conda\envs
platform : win-32
user-agent : conda/4.6.11 requests/2.21.0 CPython/3.7.3 Windows/10 Windows/10.0.17763
administrator : False
netrc file : None
offline mode : False
I had faced the same problem. Simply running
conda install anaconda
solved the problem for me.
saw this on Google Groups
This message was added in conda 4.6.9, previously there was no indication when conda detected an inconsistent environment unless conda was run in debug mode. It is likely that your environment was inconsistent for some time but the upgrade to conda made it visible. The best option it to run "conda install package_name" for the inconsistent packages to let conda try to restore consistency.
and it really works for me.
Maybe you should try conda install anaconda in your situation.
The inconsistencies are caused due to different versions of the packages, and their clashing dependencies.
conda update --all
This command updates all the packages, and then conda solves the inconsistency on its own.
Had this same problem and none of the other solutions worked for me. Ended up having to uninstall and reinstall conda, then reinstall all of my libraries.
Ultimate solutions:
conda activate base
conda install anaconda
conda update --all
Works on Windows 10 and Ubuntu 18.04 (credits to #MF.OX for ubuntu).
Removed following problems for me:
The environment is inconsistent
WARNING conda.base.context:use_only_tar_bz2(632)
If the other solutions don't work, reverting the environment can fix this.
Use conda list --revisions, pick a revision number, and use conda install --revision [#] going back step-by-step until everything works again.
Given a situation like the following,
> conda update -c intel --all
Collecting package metadata: done
Solving environment: |
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- intel/win-64::ipython==6.3.1=py36_3
- intel/win-64::prompt_toolkit==1.0.15=py36_2
done
As mentioned in other answers, the idea is to have some sort of re-installation to occur for the inconsistent packages.
Thus, with a few copy-&-paste's, you could:
> conda install intel/win-64::ipython==6.3.1=py36_3
Collecting package metadata: done
Solving environment: /
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- intel/win-64::ipython==6.3.1=py36_3
- intel/win-64::prompt_toolkit==1.0.15=py36_2
done
## Package Plan ##
environment location: c:\conda
added / updated specs:
- ipython
The following NEW packages will be INSTALLED:
jedi intel/win-64::jedi-0.12.0-py36_2
parso intel/win-64::parso-0.2.0-py36_2
pygments intel/win-64::pygments-2.2.0-py36_5
wcwidth intel/win-64::wcwidth-0.1.7-py36_6
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(and you would have to repeat for all the packages)
My “Shortcut”
Alternatively, cook up an (ugly) one-liner (this should work for Windows as well as other platforms)
Note: by "ORIGINAL_COMMAND", I'm referring to any command that gives you the error message (without any other side-effects, ideally)
<ORIGINAL_COMMAND> 2>&1 | python -c "import sys,re,conda.cli; conda.cli.main('conda','install','-y',*re.findall(r'^\s*-\s*(\S+)$',sys.stdin.read(),re.MULTILINE))"
Expanding the above one-liner:
from re import findall, MULTILINE
from sys import stdin
from conda.cli import main
main(
"conda", "install", "-y",
"--force", # Maybe add a '--force'/'--force-reinstall' (I didn't add it for the one-liner above)
*findall(r"^\s*-\s*(\S+)$", stdin.read(), MULTILINE) # Here are the offenders
)
I was getting an environment is inconsistent error when I tried to update my base conda environment. I'm using miniconda. Unfortunately, none of the answers above worked for me.
What did work for me was:
conda activate base
conda install conda --force-reinstall
conda install conda --force-reinstall
conda update --all
(Yes, for some reason it was necessary to run conda install conda --force-reinstall twice!)
The command conda install -c anaconda anaconda did the trick for me. For my setup, I need to specify the channel otherwise it would not work. After running the command in the terminal, I was prompted to update a list of packages that was found to be inconsistent. Without this step, I was not able to install or update any packages with conda install <package_name> or conda update <package_name respectively.
What worked for me was to
`conda remove <offending_packagename>`,
`conda update --all`
and then finally
`conda install <offending_packagename>`.
I had this problem for ages. The conda install anaconda might work, but it takes just way too long -- more than 24 hours on my machine.
Here is a solution that worked for me in under 5 minutes:
Remove all the unneeded packages -- being careful to leave the ones that are essential for conda to operate.
Then, use conda install anaconda.
But how?? there is a lot of them!
This is what I have done:
Make a fresh envinroment with python, fairly bare-bone. then, list the packages in there:
conda create -n fresh python
conda activate fresh
conda list
Save the output, you will need it.
1b. go back to the base envinroment:
conda deactivate
use the following snippet to generate a conda command that will remove all the inconsistent packages:
(good packages are)
exclusion_text = '''
_libgcc_mutex 0.1 main
_openmp_mutex 4.5 1_gnu
anyio 2.2.0 py39h06a4308_1
argon2-cffi 20.1.0 py39h27cfd23_1
async_generator 1.10 pyhd3eb1b0_0
...
... and more! get this from a good environment.
Note the usage of triple quotes (''') to use a multiline-string in python.
bad_packages_text = '''
- https://repo.continuum.io/pkgs/main/linux-64/networkx-2.1-py36_0.tar.bz2/linux-64::networkx==2.1=py36_0
- https://repo.continuum.io/pkgs/main/linux-64/spyder-3.2.6-> py36_0.tar.bz2/linux-64::spyder==3.2.6=py36_0
py36h4c697fb_0.tar.bz2/linux-64::jdcal==1.3=py36h4c697fb_0
- defaults/noarch::jupyterlab_server==1.1.4=py_0
- defaults/linux-64::argh==0.26.2=py37_0
...
... and more! get this by copy-pasting the "The following packages are causing the inconsistency." message.
then, in python, process this:
exclusions = [line.split(' ')[0] for line in exclusion_text_lines if line !='']
bad_packages_lines = bad_packages_text.split('\n')
bad_packages = [line.split('::')[1].split('==')[0] for line in bad_packages_lines if line!='']
exclusions.append('conda') # make sure!
exclusions.append('tqdm')
finally, construct the life-saving command:
command_line = 'conda remove '
for bad_package in bad_packages:
if bad_package not in exclusions:
command_line = f'{command_line} {bad_package}'
command_line
Since in solving the environment, all the packages on the remove list can be ignored, conda no longer needs to consider their versions, and the process is fast.
Possibly someone can refactor this method to make it easier -- or better yet, upgrade conda to enable quick reset base command.
This worked for me -- it took me longer to write this post than to execute these actions.
Good luck!
To those of us who have miniconda and can't/don't want to install anaconda: the accepted answer works when adapted.
conda install conda
conda update --all
Would have commented, but my rep is too low.
conda install anaconda
conda clean --all
conda update --all
fix the problem for me
To solve this message I had to run conda update --all in my base environment three times after each other.
Every time the number of inconsistent packages decreased until conda said:
# All requested packages already installed.
I'm on macOS Big Sur 11.6 using conda version 4.10.3.
In my case, none of the above worked. But this did the trick in less than a minute:
1- I downloaded again the lastest installer (miniconda in my case)
2- Run the installer with the -u option:
bash Miniconda3-py39_xxxx-Linux-x86_64.sh -u
3- Answer yes to all questions and let the installer finish
4- Then I could run conda update conda -all
Hope this helps...
You probably installed anaconda with python 2.7 but later you used python 3.x. Thus, you are getting an error message. In my case, I solved the problem by activating anaconda with python 2.7:
conda create --name py2 python=2.7
Try to have a look to the environment management
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
By using something along the lines
conda create --name astra python=3.5
conda activate astra
conda install -c astra-toolbox astra-toolbox
You can see that you can even specify target python version. Now play with the new packages installed. When unsatisfied, you can always do
conda deactivate
conda env remove -n astra
If you install everything to the base env and something gets broken, then probably better is not to install conda at all and go with default python managing it through pip.
In my environment.
1.
conda install anaconda
conda update --all
Then it works correctly.

Conda environments not showing up in Jupyter Notebook

I installed Anaconda (with Python 2.7), and installed Tensorflow in an environment called tensorflow. I can import Tensorflow successfully in that environment.
The problem is that Jupyter Notebook does not recognize the new environment I just created. No matter I start Jupyter Notebook from the GUI Navigator or from the command line within the tensorflow env, there is only one kernel in the menu called Python [Root], and Tensorflow cannot be imported. Of course, I clicked on that option multiple times, saved file, re-opened, but these did not help.
Strangely, I can see the two environments when I open the Conda tab on the front page of Jupyter. But when I open the Files tab, and try to new a notebook, I still end up with only one kernel.
I looked at this question:
Link Conda environment with Jupyter Notebook
But there isn't such a directory as ~/Library/Jupyter/kernels on my computer! This Jupyter directory only has one sub-directory called runtime.
I am really confused. Are Conda environments supposed to become kernels automatically? (I followed https://ipython.readthedocs.io/en/stable/install/kernel_install.html to manually set up the kernels, but was told that ipykernel was not found.)
I don't think the other answers are working any more, as conda stopped automatically setting environments up as jupyter kernels. You need to manually add kernels for each environment in the following way:
source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
As documented here:http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments
Also see this issue.
Addendum:
You should be able to install the nb_conda_kernels package with conda install nb_conda_kernels to add all environments automatically, see https://github.com/Anaconda-Platform/nb_conda_kernels
If your environments are not showing up, make sure you have installed
nb_conda_kernels in the environment with Jupyter
ipykernel and ipywidgets in the Python environment you want to access (note that ipywidgets is to enable some Juptyer functionality, not environment visibility, see related docs).
Anaconda's documentation states that
nb_conda_kernels should be installed in the environment from which
you run Jupyter Notebook or JupyterLab. This might be your base conda
environment, but it need not be. For instance, if the environment
notebook_env contains the notebook package, then you would run
conda install -n notebook_env nb_conda_kernels
Any other environments you wish to access in your notebooks must have
an appropriate kernel package installed. For instance, to access a
Python environment, it must have the ipykernel package; e.g.
conda install -n python_env ipykernel
To utilize an R environment, it must have the r-irkernel package; e.g.
conda install -n r_env r-irkernel
For other languages, their corresponding kernels must be installed.
In addition to Python, by installing the appropriatel *kernel package, Jupyter can access kernels from a ton of other languages including R, Julia, Scala/Spark, JavaScript, bash, Octave, and even MATLAB.
Note that at the time originally posting this, there was a possible cause from nb_conda not yet supporting Python 3.6 environments.
If other solutions fail to get Jupyter to recognize other conda environments, you can always install and run jupyter from within a specific environment. You may not be able to see or switch to other environments from within Jupyter though.
$ conda create -n py36_test -y python=3.6 jupyter
$ source activate py36_test
(py36_test) $ which jupyter
/home/schowell/anaconda3/envs/py36_test/bin/jupyter
(py36_test) $ jupyter notebook
Notice that I am running Python 3.6.1 in this notebook:
Note that if you do this with many environments, the added storage space from installing Jupyter into every environment may be undesirable (depending on your system).
The annoying thing is that in your tensorflow environment, you can run jupyter notebook without installing jupyter in that environment. Just run
(tensorflow) $ conda install jupyter
and the tensorflow environment should now be visible in Jupyter Notebooks started in any of your conda environments as something like Python [conda env:tensorflow].
I had to run all the commands mentioned in the top 3 answers to get this working:
conda install jupyter
conda install nb_conda
conda install ipykernel
python -m ipykernel install --user --name mykernel
Just run conda install ipykernel in your new environment, only then you will get a kernel with this env. This works even if you have different versions installed in each envs and it doesn't install jupyter notebook again. You can start youe notebook from any env you will be able to see newly added kernels.
Summary (tldr)
If you want the 'python3' kernel to always run the Python installation from the environment where it is launched, delete the User 'python3' kernel, which is taking precedence over whatever the current environment is with:
jupyter kernelspec remove python3
Full Solution
I am going to post an alternative and simpler solution for the following case:
You have created a conda environment
This environment has jupyter installed (which also installs ipykernel)
When you run the command jupyter notebook and create a new notebook by clicking 'python3' in the 'New' dropdown menu, that notebook executes python from the base environment and not from the current environment.
You would like it so that launching a new notebook with 'python3' within any environment executes the Python version from that environment and NOT the base
I am going to use the name 'test_env' for the environment for the rest of the solution. Also, note that 'python3' is the name of the kernel.
The currently top-voted answer does work, but there is an alternative. It says to do the following:
python -m ipykernel install --user --name test_env --display-name "Python (test_env)"
This will give you the option of using the test_env environment regardless of what environment you launch jupyter notebook from. But, launching a notebook with 'python3' will still use the Python installation from the base environment.
What likely is happening is that there is a user python3 kernel that exists. Run the command jupyter kernelspec list to list all of your environments. For instance, if you have a mac you will be returned the following (my user name is Ted).
python3 /Users/Ted/Library/Jupyter/kernels/python3
What Jupyter is doing here is searching through three different paths looking for kernels. It goes from User, to Env, to System. See this document for more details on the paths it searches for each operating system.
The two kernels above are both in the User path, meaning they will be available regardless of the environment that you launch a jupyter notebook from. This also means that if there is another 'python3' kernel at the environment level, then you will never be able to access it.
To me, it makes more sense that choosing the 'python3' kernel from the environment you launched the notebook from should execute Python from that environment.
You can check to see if you have another 'python3' environment by looking in the Env search path for your OS (see the link to the docs above). For me (on my mac), I issued the following command:
ls /Users/Ted/anaconda3/envs/test_env/share/jupyter/kernels
And I indeed had a 'python3' kernel listed there.
Thanks to this GitHub issue comment (look at the first response), you can remove the User 'python3' environment with the following command:
jupyter kernelspec remove python3
Now when you run jupyter kernelspec list, assuming the test_env is still active, you will get the following:
python3 /Users/Ted/anaconda3/envs/test_env/share/jupyter/kernels/python3
Notice that this path is located within the test_env directory. If you create a new environment, install jupyter, activate it, and list the kernels, you will get another 'python3' kernel located in its environment path.
The User 'python3' kernel was taking precedence over any of the Env 'python3' kernels. By removing it, the active environment 'python3' kernel was exposed and able to be chosen every time. This eliminates the need to manually create kernels. It also makes more sense in terms of software development where one would want to isolate themselves into a single environment. Running a kernel that is different from the host environment doesn't seem natural.
It also seems that this User 'python3' is not installed for everyone by default, so not everyone is confronted by this issue.
To add a conda environment to Jupyter:
In Anaconda Prompt :
run conda activate <env name>
run conda install -c anaconda ipykernel
run python -m ipykernel install --user --name=<env name>
** tested on conda 4.8.3 4.11.0
$ conda install nb_conda_kernels
(in the conda environment where you run jupyter notebook) will make all conda envs available automatically. For access to other environments, the respective kernels must be installed. Here's the ref.
This worked for me in windows 10 and latest solution :
1) Go inside that conda environment ( activate your_env_name )
2) conda install -n your_env_name ipykernel
3) python -m ipykernel install --user --name build_central --display-name "your_env_name"
(NOTE : Include the quotes around "your_env_name", in step 3)
The nb_conda_kernels package is the best way to use jupyter with conda. With minimal dependencies and configuration, it allows you to use other conda environments from a jupyter notebook running in a different environment. Quoting its documentation:
Installation
This package is designed to be managed solely using conda. It should be installed in the environment from which you run Jupyter Notebook or JupyterLab. This might be your base conda environment, but it need not be. For instance, if the environment notebook_env contains the notebook package, then you would run
conda install -n notebook_env nb_conda_kernels
Any other environments you wish to access in your notebooks must have an appropriate kernel package installed. For instance, to access a Python environment, it must have the ipykernel package; e.g.
conda install -n python_env ipykernel
To utilize an R environment, it
must have the r-irkernel package; e.g.
conda install -n r_env r-irkernel
For other languages, their corresponding kernels must be installed.
Then all you need to do is start the jupyter notebook server:
conda activate notebook_env # only needed if you are not using the base environment for the server
# conda install jupyter # in case you have not installed it already
jupyter
Despite the plethora of answers and #merv's efforts to improve them, it still hard to find a good one. I made this one CW, so please vote it to the top or improve it!
This is an old thread, but running this in Anaconda prompt, in my environment of interest, worked for me:
ipython kernel install --name "myenvname" --user
We have struggle a lot with this issue, and here's what works for us. If you use the conda-forge channel, it's important to make sure you are using updated packages from conda-forge, even in your Miniconda root environment.
So install Miniconda, and then do:
conda config --add channels conda-forge --force
conda update --all -y
conda install nb_conda_kernels -y
conda env create -f custom_env.yml -q --force
jupyter notebook
and your custom environment will show up in Jupyter as an available kernel, as long as ipykernel was listed for installation in your custom_env.yml file, like this example:
name: bqplot
channels:
- conda-forge
- defaults
dependencies:
- python>=3.6
- bqplot
- ipykernel
Just to prove it working with a bunch of custom environments, here's a screen grab from Windows:
I ran into this same problem where my new conda environment, myenv, couldn't be selected as a kernel or a new notebook. And running jupter notebook from within the env gave the same result.
My solution, and what I learned about how Jupyter notebooks recognizes conda-envs and kernels:
Installing jupyter and ipython to myenv with conda:
conda install -n myenv ipython jupyter
After that, running jupter notebook outside any env listed myenv as a kernel along with my previous environments.
Python [conda env:old]
Python [conda env:myenv]
Running the notebook once I activated the environment:
source activate myenv
jupyter notebook
hides all my other environment-kernels and only shows my language kernels:
python 2
python 3
R
This has been so frustrating, My problem was that within a newly constructed conda python36 environment, jupyter refused to load “seaborn” - even though seaborn was installed within that environment. It seemed to be able to import plenty of other files from the same environment — for example numpy and pandas but just not seaborn. I tried many of the fixes suggested here and on other threads without success. Until I realised that Jupyter was not running kernel python from within that environment but running the system python as kernel. Even though a decent looking kernel and kernel.json were already present in the environment. It was only after reading this part of the ipython documentation:
https://ipython.readthedocs.io/en/latest/install/kernel_install.html#kernels-for-different-environments
and using these commands:
source activate other-env
python -m ipykernel install --user --name other-env --display-name "Python (other-env)"
I was able to get everything going nicely. (I didn’t actually use the —user variable).
One thing I have not yet figured is how to set the default python to be the "Python (other-env)" one. At present an existing .ipynb file opened from the Home screen will use the system python. I have to use the Kernel menu “Change kernel” to select the environment python.
I had similar issue and I found a solution that is working for Mac, Windows and Linux. It takes few key ingredients that are in the answer above:
To be able to see conda env in Jupyter notebook, you need:
the following package in you base env:
conda install nb_conda
the following package in each env you create:
conda install ipykernel
check the configurationn of jupyter_notebook_config.py
first check if you have a jupyter_notebook_config.py in one of the location given by jupyter --paths
if it doesn't exist, create it by running jupyter notebook --generate-config
add or be sure you have the following: c.NotebookApp.kernel_spec_manager_class='nb_conda_kernels.manager.CondaKernelSpecManager'
The env you can see in your terminal:
On Jupyter Lab you can see the same env as above both the Notebook and Console:
And you can choose your env when have a notebook open:
The safe way is to create a specific env from which you will run your example of envjupyter lab command. Activate your env. Then add jupyter lab extension example jupyter lab extension. Then you can run jupyter lab
While #coolscitist's answer worked for me, there is also a way that does not clutter your kernel environment with the complete jupyter package+deps.
It is described in the ipython docs and is (I suspect) only necessary if you run the notebook server in a non-base environment.
conda activate name_of_your_kernel_env
conda install ipykernel
python -m ipykernel install --prefix=/home/your_username/.conda/envs/name_of_your_jupyter_server_env --name 'name_of_your_kernel_env'
You can check if it works using
conda activate name_of_your_jupyter_server_env
jupyter kernelspec list
First you need to activate your environment .
pip install ipykernel
Next you can add your virtual environment to Jupyter by typing:
python -m ipykernel install --name = my_env
Follow the instructions in the iPython documentation for adding different conda environments to the list of kernels to choose from in Jupyter Notebook. In summary, after installing ipykernel, you must activate each conda environment one by one in a terminal and run the command python -m ipykernel install --user --name myenv --display-name "Python (myenv)", where myenv is the environment (kernel) you want to add.
Possible Channel-Specific Issue
I had this issue (again) and it turned out I installed from the conda-forge channel; removing it and reinstalling from anaconda channel instead fixed it for me.
Update: I again had the same problem with a new env, this time I did install nb_conda_kernels from anaconda channel, but my jupyter_client was from the conda-forge channel. Uninstalling nb_conda_kernels and reinstalling updated that to a higher-priority channel.
So make sure you've installed from the correct channels :)
I encountered this problem when using vscode server.
In the conda environment named "base", I installed the 1.2.0 version of opennmt-py, but I want to run jupyter notebook in the conda environment "opennmt2", which contains code using opennmt-py 2.0.
I solved the problem by reinstalling jupyter in conda(opennmt2).
conda install jupyter
After reinstalling, executing jupyter notebook in the opennmt2 environment will execute the newly installed jupyter
where jupyter
/root/miniconda3/envs/opennmt2/bin/jupyter
/root/miniconda3/bin/jupyter
For conda 4.5.12, what works for me is (my virtual env is called nwt)
conda create --name nwt python=3
after that I need to activate the virtual environment and install the ipykernel
activate nwt
pip install ipykernel
then what works for me is:
python -m ipykernel install --user --name env_name --display-name "name of your choosing."
As an example, I am using 'nwt' as the display name for the virtual env. And after running the commands above. Run 'jupyter notebook" in Anaconda Prompt again. What I get is:
Using only environment variables:
python -m ipykernel install --user --name $(basename $VIRTUAL_ENV)
I just wanted to add to the previous answers: in case installing nb_conda_kernels, ipywidgets and ipekernel dosen't work, make sure your version of Jupyter is up to date. My envs suddenly stopped showing up after a period of everything working fine, and it resumed working after I simply updated jupyter through the anaconda navigator.
In my case, using Windows 10 and conda 4.6.11, by running the commands
conda install nb_conda
conda install -c conda-forge nb_conda_kernels
from the terminal while having the environment active didn't do the job after I opened Jupyter from the same command line using conda jupyter notebook.
The solution was apparently to opened Jupyter from the Anaconda Navigator by going to my environment in Environments: Open Anaconda Navigator, select the environment in Environments, press on the "play" button on the chosen environment, and select 'open with Jupyter Notebook'.
Environments in Anaconda Navigator to run Jupyter from the selected environment

Resources