Use jupyter-lab installed in python virtual environment (venv)

There was already a post on Qiita, but since the information was scattered, I organized it.

There are two points.

It is natural to understand it, but in many cases it is installed in the original environment without checking.

environment

Create virtual environment

It is assumed that the module that creates the virtual environment is already installed.

$ virtualenv test
$ source test/bin/activate
$ pip install keras
$ pip install jupyterlab

Install kernel in virtual environment

$ pip install ipykernel
$ ipython kernel install --user --name=test

Run

Start jupyter-lab.

$ test/bin/jupyter-lab

The installed kernel will be displayed in the list, so select the kernel (test) created this time. The kernel can also be selected from the menu (Kernel / select kernel). launcher_JupyterLab.png

You can see that the kernel on the boot screen (right side) is test. start_JupyterLab.png

When importing a module installed in a virtual environment, an error (ModuleNotFoundError) occurs. JupyterLab_ModuleNotFoundError.png

Shows the Python path. JupyterLab_syspath_before.png

Add the path of the virtual environment and try running it. The import is successful. JupyterLab_syspath_after.png JupyterLab_install_keras.png

Link

Recommended Posts

Use jupyter-lab installed in python virtual environment (venv)
virtual environment in python
venv: Python virtual environment management
python standard virtual environment venv
Python virtual environment in 2021 ~ There is no reason not to use venv now ~
Using venv in Windows + Docker environment [Python]
Python environment preparation (venv first time use)
Use config.ini in Python
How to create a Python virtual environment (venv)
Ubuntu18.04.05 Creating a python virtual environment in LTS
Use dates in Python
Use Valgrind in Python
Create a virtual environment with conda in Python
python virtual environment Pipenv
Use Python in your environment from Win Automation
Work in a virtual environment with Python virtualenv.
Use Python in Anaconda environment with VS Code
Use profiler in Python
Development environment in Python
Virtual environment with Python 3.6
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Use pydantic when reading environment variables in Python
Use os.getenv to get environment variables in Python
Periodically execute python script with cron in venv environment
Python: Creating a virtual environment (venv), starting and stopping
Use the CASA Toolkit in your own Python environment
Simplified Path input when enabling virtual environment in venv
Build a Python virtual environment using venv (Django + MySQL ①)
Building and enabling a python virtual environment, etc. (venv)
Setting up Jupyter Lab in a Python 3.9 venv environment
Let's use def in python
Use let expression in Python
Use Anaconda in pyenv environment
Use Measurement Protocol in Python
Use callback function in Python
Use HTTP cache in Python
Use MongoDB ODM in Python
Handle environment variables in Python
Use list-keyed dict in Python
Use Random Forest in Python
Use regular expressions in Python
Use Spyder in Python IDE
Building a Python virtual environment
Building a Python virtual environment
python3.8 venv environment jupyter notebook
[Django3] Display a web page in Django3 + WSL + Python virtual environment
How to use VS Code in venv environment on windows
How to develop in a virtual environment of Python [Memo]
[CLPEX memo] Run DO Python API in COS installed environment
Virtual Environment Version Control Summary Python
Use fabric as is in python (fabric3)
[Personal memo] Python virtual environment command memo
Install scrapy in python anaconda environment
How to use SQLite in Python
Create a virtual environment with Python!
Use rospy with virtualenv in Python3
install tensorflow in anaconda + python3.5 environment
Use Python in pyenv with NeoVim
How to use ChemSpider in Python
How to use PubChem in Python
Use django-debug-toolbar in VirtualBox / Vagrant environment