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
Related
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
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
I need to install mpl_finance under a conda virtual environment, this package is not available via conda, only pip can install. I have tried below, does not work out, please advice.
I first set up a virtual env called cs231p under user/miniconda3/envs/cs231p.
I cd to user/miniconda3/envs/cs231p/bin, and activated the env
conda activate cs231p
Then I do: conda list to make sure pip is there:
ca-certificates 2019.1.23 0
certifi 2019.3.9 py37_0
libcxx 4.0.1 hcfea43d_1
libcxxabi 4.0.1 hcfea43d_1
libedit 3.1.20181209 hb402a30_0
libffi 3.2.1 h475c297_4
ncurses 6.1 h0a44026_1
openssl 1.1.1b h1de35cc_1
pip 19.0.3 py37_0
Then I do:
which pip
shows
/miniconda3/envs/cs231p/bin/pip
(cs231p) bin$ pip install mpl_finance
I got error: but the path of pip is not from the virtual env that I set up.
XXX/anaconda/bin/python3.5: can't open file 'install': [Errno 2] No such file or directory
python -m pip install mpl_finance
gives
requirement already satisfied:mpl_finance in
~/anaconda/lib/python3.5/site-packages (0.10.0)
Instead of pip install ... you can also use python -m pip install ....
But you run pip install and you get python3.5 can't open file "install" - it looks like your pip is not real pip but alias for python3.5.
Run python3.5 install mpl_finance and you get the same error.
Maybe you have own local script/file with name pip and when you run it then it uses this script instead of expected pip.
You can always try full path /miniconda3/envs/cs231p/bin/pip install mpl_finance.
You can also create new environment to test if it is only problem with this one environment.
activate anaconda virtual environment
conda activate <env name>
install the package using pip
python -m pip install <package>
deactivate conda virtual env
conda deactivate
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.
I have a linux machine to which i installed Anaconda.
I am following:
https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html
pip instaltion part.
To be more specific:
which python
gives
/home/user/anaconda2/bin/python
After which i entered:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
And after:
sudo pip install --upgrade $TF_BINARY_URL
However,
while trying:
python -c "import tensorflow"
I get an import error:
ImportError: No module named tensorflow
The 'sudo' makes pip install tensorflow outside the env. Try:
pip install --upgrade $TF_BINARY_URL
Just tested this on Ubuntu 14.04 w/ conda env, was able to reproduce (with sudo) and resolve issue (without sudo).
You can also check the "Using Conda" section of tensorflow.org. They list the below:
# Python 2
(tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL
# Python 3
(tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL
In anaconda, simply do:
for installation
conda install -c conda-forge tensorflow
for update/upgrade
# -f will force the current installation to upgrade
conda update -f -c conda-forge tensorflow