Jupyter kernel uses different Python version than Conda environment - jupyter-notebook

I am not able to link Jupyter kernels to their parent Conda environments. After creating a new kernel linked to Conda environment, I'm getting a different version of Python and its dependencies inside Jupyter lab.
Here are the steps I followed:
Created a conda environment using:
conda create -n nlp python=3.6
conda activate nlp
(nlp) ➜ ~ python --version
Python 3.6.9 :: Anaconda, Inc.
(nlp) ➜ ~ which python
/anaconda3/envs/nlp/bin/python
Inside the environment I created a Jupyter kernel with:
(nlp) ➜ ~ python -m ipykernel install --user --name=nlp
Installed kernelspec nlp in /Users//Library/Jupyter/kernels/nlp
Investigating the created json file for the kernel:
(nlp) ➜ ~ cat /Users/<username>/Library/Jupyter/kernels/nlp/kernel.json
{
"argv": [
"/anaconda3/envs/nlp/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "nlp",
"language": "python"
}%
It seems to be pointing to the environment version of Python
But when I start Jupyter Lab and select the nlp kernel, I get a different version of Python and some dependencies are missing
!python --version
Python 3.5.6 :: Anaconda, Inc.
!which python
/anaconda3/bin/python

Could you please try the following steps:
conda activate nlp
conda install ipykernel
ipython kernel install --name nlp --user
After these steps please try changing the kernel again in jupyter lab to "nlp".
Thanks.

this behavior is actually normal in Jupyter lab.
If you run
import sys
print(sys.version)
!python --version
in a notebook, the print statement will give you the Python version of the conda env, while the second will give you the Python version of your base env.
The easiest workaround for this is to simply pip install jupyterlab in your conda env and then run jupyter lab in your conda env. Then, there will not be a mismatch in Python versions between the new "base" env and the conda env which will help clear up any DLL problems.
It's probably not best practice, but you do what you gotta do when working with legacy code, ig.

Can you try this :
# in base env
conda install nb_conda_kernels
conda activate nlp
conda install ipykernel
conda install ipywidgets
# install kernelspec
python -m ipykernel install --user --name nlp --display-name "nlp env"
When you run jupyter notebook, you will see 2 nlp kernels. Use the one with "Python [conda:env:nlp]"

Related

Install Rdkit in jupyter notebook, using Anaconda enviornment

How to install rdkit library in my jupyter notebook. I am using Anaconda environment.
Inside the anaconda environment, just run conda install -c conda-forge rdkit
You can find detailed installation instructions here.

I can't install lableImg Annotation tool in M1 Mac

While installing LabelImg in M1 Mac using below command
pip install pyqt5 lxml
This is the error I got
ERROR: pyqt5 from https://files.pythonhosted.org/packages/7c/5b/e760ec4f868cb77cee45b4554bf15d3fe6972176e89c4e3faac941213694/PyQt5-5.14.0.tar.gz#sha256=0145a6b7de15756366decb736c349a0cb510d706c83fda5b8cd9e0557bc1da72 has a pyproject.toml file that does not comply with PEP 518: 'build-system.requires' contains an invalid requirement: 'sip >=5.0.1 <6'
How to install lableImg annotation tool in M1 Mac?
I got it to work by using the following commands
brew install pyqt#5
pip install labelimg
And that's it, it just works
You just need to type labelimg in the Terminal and the app will start running
I don't know why they don't tell you this in the installation guide
Alrighty!
On MacOS Monterey, none of the other solutions posted here solved this problem for me. However, I managed to easily solve the issue, without a virtual environment or too much fiddling about like so:
Firstly, you have to download all labelImg packages from this link:
https://github.com/tzutalin/labelImg#macos
(You can download it as a .zip file or clone it)
Unzip and then in your terminal cd into whatever directory you downloaded the above files to.
Then run the following commands in order:
pyrcc5 -o libs/resources.py resources.qrc
Then,
pip3 install lxml
Finally,
python3 labelImg.py
It should run without an issue now.
You can go one of two ways:
Using brew:
You can use homebrew to install the dependencies - like qt and libxml2. This will let your package manager handle everything and generally should solve the problem with the . Then you can run
python3 labelimg.py
Using Virtual Environments:
This is the more recommended way to go about in such cases. You can use conda, pipenv or venv to create a virtual environment which is isolated from your system python installation. Then you can try to install it as explained in the README.rst in the root of the repository:
brew install python3
pip3 install pipenv
pipenv run pip install pyqt5==5.12.1 lxml
pipenv run make qt5py3
pipenv run python3 labelImg.py
[Optional] rm -rf build dist; python setup.py py2app -A;mv "dist/labelImg.app" /Applications
You can try the two methods and and get back with the errors if there are any.
This is my note.
I just succeed on my Mac M1 Chip
CHECK THIS OUT!
Installation of labelimg on mac m1 chip
my first reference
my second reference
First, you must use terminal with rosetta version
Then, you already have python3
Then...
[Done]
# check where python3 is
$ where python3
# create env
$ /usr/bin/python3 -m venv env
# check env is
$ where env
# activate env list
$ source env/bin/activate
# updated to the newest
$ pip install --upgrade pip
# installation of PyQt5
$ pip install PyQt5
# start to run labelImg.py
$ cd Documents/repos/labelImg
$ pip3 install pyqt5 lxml
$ make qt5py3
# [run ok!!]
$ python3 labelImg.py
Using Conda
Create a virtual environment in conda and activate it
conda create -n venv
conda activate venv
Install pyqt using conda
conda install pyqt
Install lxml using pip
pip install lxml
Change directory to the downloaded/cloned labelImg folder
cd path/to/labelImg/folder/
Make qt5py3
make qt5py3
Run LabelImg
python labelImg.py

adding conda environment via cmd line to jupyter doesn't work

Trying to get OSMnx into jupyter conda environment.
But conda environment not set correctly.
On command line:
Created conda environment using OSMnx installation steps
I cloned the environment to rename it 'realestate'
Added realestate to Jupyter:
> conda activate realestate
> conda install -c anaconda ipykernel
> python -m ipykernel install --user --name=realestate
> which python
/opt/anaconda3/envs/realestate/bin/python
On Jupyter the realestate environment shows up... but when I run
!which python
I get
/opt/anaconda3/bin/python
I've created some conda environments inside of Jupyter(Conda) and they show up as
Python [conda env: otherenv]
that then produces right path
!which python
/opt/anaconda3/envs/otherenv/bin/python
What am I missing?
PS. OSMnx install is not a simple conda install
conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx
From what I can tell, it sounds like you're trying to have OSMnx, Jupyter, and all the packages in the anaconda metapackage installed together in a single conda environment. If so, just create the conda environment with all those packages in one line, then install the ipython kernelspec in it:
conda config --prepend channels conda-forge
conda create -n realestate --strict-channel-priority osmnx anaconda jupyter
conda activate realestate
python -m ipykernel install --sys-prefix --name realestate --display-name "Python (realestate)"
jupyter kernelspec list

C++14 no visible after installing xeus-cling in Jupyter (Ubuntu 18.04 - Anaconda)

I followed the installation of the xeus-cling (created an env, activated,installed xeus-cling there) and when I want to select the C++14 kernel in a jupyter notebook it only appears Python3. What am I doing wrong?
I had the same problem. Its because jupyter-notebook is not installed in your environment. The jupyter server which is starting is the global one hence you don't see the c++14 option. The solution is:
Create a new directory and git clone the repository.
Run the conda env create -f environmental.yml command in cmd.
Run the conda activate xeus-cling command.
Run the jupyter notebook command.
You should now be able to see the c++14 and c++17 options. Step 2 created the xeus-cling environment and installs all the correct package versions including the correct jupyter notebook version.
Install notebook in your environment.
conda install xeus-cling notebook -c QuantStack -c conda-forge
You need register new kernels in jupyter:
jupyter kernelspec install PREFIX/share/jupyter/xcpp11 --sys-prefix
jupyter kernelspec install PREFIX/share/jupyter/xcpp14 --sys-prefix
jupyter kernelspec install PREFIX/share/jupyter/xcpp17 --sys-prefix

OSMnx wont open in Juypter Notebook

I downloaded osmnx via conda using the code:
conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx
This comes from the osmnx documentation: https://osmnx.readthedocs.io/en/stable/
I can see the module has downloaded because in the Anaconda Prompt I can type conda activate oxand it works. However when I go into my jupyter notebook and type
import osmnx as ox
I get the following error:
​
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-11-7e05e48535cd> in <module>
----> 1 import osmnx as ox
2
3
ModuleNotFoundError: No module named 'osmnx'
Please advise as to what I can do. Thanks
In your terminal, run:
conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx jupyterlab
conda activate ox
python -m ipykernel install --user --name ox --display-name "Python (ox)"
jupyter lab
This installs OSMnx and JupyterLab into a conda environment called ox, activates the environment, installs an ipython kernel in the environment, then launches JupyterLab.
See also
Conda environments not showing up in Jupyter Notebook
Conda environments not showing up in Jupyter Notebook
How to use Jupyter notebooks in a conda environment?
How to add conda environment to jupyter lab
Link Conda environment with Jupyter Notebook
In which conda environment is Jupyter executing?

Resources