To add existing environment as a jupyter kernel:

List kernels

jupyter kernelspec list

Remove kernel

jupyter kernelspec remove <kernel-name>  

Install new kernel

ipython kernel install --name <local-venv> --user
is_jupyter = get_ipython().__class__.__name__ == 'ZMQInteractiveShell'


Custom path for VSCode Jupyter notebook

Go to global VSCode settings (Cmd + ,) and search for Jupyter Notebook File Root, then set it to any path you like to be imported by default.

Custom path for Jupyter Notebook in a browser

Go to kernel.json file:

jupyter kernelspec list
cd ~/.local/share/jupyter/kernels/mykernel/

add PYTHONPATH environmental variable in the env section:

"argv": [
"env": {
    "PYTHONPATH": "/path/to/custom/path"

Note PYTHONPATH has nothing to do with the path to the python file set in argv.

Global path

To add a global path to all kernels we can use file:

ipython profile create
ipython locate


vi /Users/username/.ipython/profile_default/

add these lines (use i to enter insert mode and Esc to exit, save and quit as :wq:

c.InteractiveShellApp.exec_lines = [
    'import sys; sys.path.append("/path/to/your/module")'

Manual path

One can always get the current folder in the notebook a = os.path.abspath('') and then manipulate it. Manually setting up some ENV path variable is also an option. Magic command for environemtal variables:


Change the default kernel

jupyter notebook --generate-config

In jupyter config file modify and uncomment following line: c.MultiKernelManager.default_kernel_name='newDefault' \n"