I created a virtual environment in python3 (with venv) to use several packages, including jupyter notebook.
Running the bash command jupyter --config-dir I noticed that the config file used by jupyter notebook in the virtual environment is the main one of my machine (~/.jupyter/jupyter_notebook_config.py).
How can I create a new config file and tell the virtual environment to use it. The goal is not to modify the main one because I need it for other projects.
from https://jupyter.readthedocs.io/en/latest/use/jupyter-directories.html:
So what you'd need to do is set the
JUPYTER_CONFIG_DIRenvironment variable when activating the environment.How you do this depends on what virtual environment manager you're using. I believe with
venvyou should be able to addto the
activatescript that runs when you activate your virtual environment (should be in$venv/environmentname/bin/activate).Another option that you might prefer (which is the route I went for this since I'm using pyenv+virtualenv, which does not use the
activatescript), you can use an additional tool like direnv or dotenv to set environment variables by project. In the case of direnv (which is a little simpler IMO), you create a.envrcfile in your project directory with theexportcommand from above, and then every time youcdinto your project directory it runs the commands in the.envrcfile. This works well if your virtual environments are organized by project.Once the
JUPYTER_CONFIG_DIRenvironment variable is being set properly, after your environment activates when you runjupyter notebook --generate-configit should create a new config file in the new directory.