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.
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
$ pip install ipykernel
$ ipython kernel install --user --name=test
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).
You can see that the kernel on the boot screen (right side) is test.
When importing a module installed in a virtual environment, an error (ModuleNotFoundError) occurs.
Shows the Python path.
Add the path of the virtual environment and try running it. The import is successful.
Recommended Posts