Can't Find Jupyter Notebook Kernel - python

I currently use a Mac. I recently created a new python virtual environment and installed jupyter. When I activate jupyter notebook within the virtual environment, it says it cannot find any python kernels. I have another virtual environment that also has jupyter installed and it works perfectly fine. Can anyone help? Also, I'm not sure where the Kernels are even located on my machine. Library/Jupyter only has a runtime folder.

I need to do 2 things to get this to work:
conda install -y ipykernel
python -m ipykernel install --user --name myenv
Kind of frustrating and I never see it mentioned much in the docs. Jupyter set up remains a pretty painful process in my opinion. This is from beginning to end, if it helps anyone:
conda create -n myenv python=3.7
conda activate myenv
conda install -y -c conda-forge jupyterlab
conda install -y -c anaconda jupyter
conda install -y ipykernel
python -m ipykernel install --user --name myenv

Try installing nb_conda in your environment, by going to your command line conda activate your environment and conda install nb_conda. Make sure you also have ipykernel installed in your environment, then deactivate and reactivate your environment and try again.

Related

ipykernel required error after installing it in VS code

I get an error when running Jupyter Notebooks in VS code due to: ipykernel not installed in my_env
.
Running cells with 'Python 3.7.7 ('my_env')' requires ipykernel package.
Run the following command to install 'ipykernel' into the Python environment.
Command: 'conda install -n my_env ipykernel --update-deps --force-reinstall'
But I already have installed ipykernel in both base and my_env, and have already installed a new kernel in my_env following.
(base) user#username folderA % pip show ipykernel
Name: ipykernel
Version: 6.9.1
(my_env) user#username folderA % pip show ipykernel
Name: ipykernel
Version: 6.9.1
(my_env) user#username folderA % python -m ipykernel install --user --name=my_env
Also, when running the proposed conda install -n my_env ipykernel --update-deps --force-reinstall and reloading the window, the issue re-appears.
I have tried multiple solutions, like the proposed in sol1, sol2 and also pip install --upgrade jupyter_client, but nothing works.
I am using macOS with M1 chip and conda 23.1.0
Let me know if I need to add additional details.
I found a solution. The problem was related to my installation of jupyter in the selected environment.
I re-started from scratch in a new environment, and followed the below steps in order:
conda create env -n env_name python=3.XX
conda activate env_name
conda install jupyter
conda install -c anaconda ipykernel
python -m ipykernel install --user --name=env_name

pip defaulting to global path instead of conda env

I create a conda environment in my repository and activate it
conda env create --prefix ./env
conda activate ./env
I can see that python now correctly uses the conda PATH
which python
/Users/michaelmoreno/project/env/bin/python
However, pip is still using my global homebrew install
which pip
/opt/homebrew/bin/pip
I can run python -m pip to use the correct conda provided pip, but I'd prefer to be able to run pip.
Why is this? How can I fix it?

When using env.yml with conda whats the difference between dependencies and pip dependencies?

I am creating a .SH script for setting up automatically my dev environment in Azure ML, according to this:
https://learn.microsoft.com/en-gb/azure/machine-learning/how-to-customize-compute-instance
The script looks like this:
#!/bin/bash
set -e
# https://pypi.org/project/azure-ai-ml/
# Requires: Python <4.0, >=3.7
# This script creates a custom conda environment and kernel based on a sample yml file.
conda env create python=3.10
#conda env create -f env.yml
echo "Activating new conda environment"
conda activate envname
conda install -y ipykernel
echo "Installing kernel"
sudo -u azureuser -i <<'EOF'
conda activate envname
python -m ipykernel install --user --name envname --display-name "mykernelp310v2"
echo "Conda environment setup successfully."
pip install azure-ai-ml
EOF
my env looks like this:
name: p310v2
dependencies:
- python=3.10
- numpy
- matplotlib
- pandas
- scikit-learn
- pip:
-kaggle==1.5
When I check this document:
https://carpentries-incubator.github.io/introduction-to-conda-for-data-scientists/04-sharing-environments/index.html
I am confused between the dependencies section and the pip section. For example scikit-learn I could put in dependencies but also on the pip section, so whats the deal here?
dependencies are conda dependencies; listing them is equivalent to run conda install <deps>. For example conda installs numpy from https://anaconda.org/conda-forge/numpy .
pip means pip dependencies for pip install command; pip installs them from PyPI.org. For example, https://pypi.org/project/numpy/
The same for scikit-learn: https://anaconda.org/search?q=scikit-learn and https://pypi.org/search/?q=scikit-learn
See also https://stackoverflow.com/search?q=%5Bconda%5D+%5Bpip%5D+difference

How to install ipykernel just for current project?

I want to install a package which is just used in one project.
So I create a virtual env and install it
python -m venv .venv --system-site-packages
python -m pip install my_package
Then I want to debug it with jupyter.
The problem is It seems I have to either install another jupyter in my virtual env ( quite large):
pip install jupyter
jupyter notebook
or register this env as a kernel to user:
python -m ipykernel install --user --name my_test_env
in this case, this env will list in my global kernel list but I won't use if for any other project. And delete the project folder will leave a broken kernel in global jupyter.
Is there any way to register a kernel just for current project?

Cant activate virtual environment

I am a bit of a newbie and made a virtualenvironment to connect to jutyer notebook as a kernel and I see the kernel when I open jp but cannot activate the virtual environment in the terminal.
To recreate what I had done
virtualenv myenv
source myenv/bin/activate
pip install --user ipykernel
pip install ipykernel
python -m ipykernel install --name=myenv
and now I get
$ source myenv/bin/activate
-bash: myenv/bin/activate: No such file or directory
and
lsvirtualenv -b
command not found
My available kernels are
myenv /Users/me/Library/Jupyter/kernels/myenv

Categories