Can I use a virtual environment for each project folder?

56 views
Skip to first unread message

Brayan Rodriguez

unread,
Aug 28, 2019, 3:48:28 PM8/28/19
to Project Jupyter
I have some github repos in a server and I would like to run that repos but in different virtual environments in the JupyterHub installed there. 

Jason Anderson

unread,
Aug 29, 2019, 4:06:43 PM8/29/19
to jup...@googlegroups.com
Hi Brayan,

One way to do this requires JupyterHub is configured to allow named servers[1]. When enabled, users can create multiple Jupyter servers associated with their user, and you could then check out one repo into each one.

Depending on what type of virtual environments you're after (are we just talking Python modules?), you could rely entirely on virtualenv/venv[2], check out each repo in to a different folder and then create a virtualenv for each one.

Hope that helps!
/Jason

[1]: https://jupyterhub.readthedocs.io/en/stable/reference/rest.html#enabling-users-to-spawn-multiple-named-servers-via-the-api
[2]: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/


On 8/28/19 2:48 PM, Brayan Rodriguez wrote:
I have some github repos in a server and I would like to run that repos but in different virtual environments in the JupyterHub installed there. 
--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/56e86081-88a9-4b40-8ab0-f0480885a592%40googlegroups.com.

Brayan Rodriguez

unread,
Aug 29, 2019, 4:21:36 PM8/29/19
to Project Jupyter
Thanks for responding, Jason. 

Yes, I am just talking about Python modules. If I create a virtualenv (with the venv folder) for each different repo (in independent folders), automatically JupyterHub works with that virutalenv? 

Thanks in advance. 


El jueves, 29 de agosto de 2019, 15:06:43 (UTC-5), Jason Anderson escribió:
Hi Brayan,

One way to do this requires JupyterHub is configured to allow named servers[1]. When enabled, users can create multiple Jupyter servers associated with their user, and you could then check out one repo into each one.

Depending on what type of virtual environments you're after (are we just talking Python modules?), you could rely entirely on virtualenv/venv[2], check out each repo in to a different folder and then create a virtualenv for each one.

Hope that helps!
/Jason

[1]: https://jupyterhub.readthedocs.io/en/stable/reference/rest.html#enabling-users-to-spawn-multiple-named-servers-via-the-api
[2]: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

On 8/28/19 2:48 PM, Brayan Rodriguez wrote:
I have some github repos in a server and I would like to run that repos but in different virtual environments in the JupyterHub installed there. 
--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jup...@googlegroups.com.

Jason Anderson

unread,
Aug 29, 2019, 4:30:25 PM8/29/19
to jup...@googlegroups.com
OK, then another thing you can try is something like installing new IPython kernels[1].

The way this would work (I think) is you would create the virtualenvs inside those venv folder, then go inside each one and install a new IPython kernel with a name. For example, if you had a repo "my-project" checked out, it would be like:

  cd my-project
  virtualenv venv
  source venv/bin/activate
  ipython kernell install --user --name my-project --display-name "Python (my-project)"
  deactivate

This _should_ install a new kernel into your JupyterLab environment. I'm not 100% sure if this can be done without restarting the server, which afaik isn't possible within something spawned from JupyterHub.

Let me know how it works,
/Jason

[1]: https://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/928d8343-5478-4dfa-a56d-8e4e44c321ed%40googlegroups.com.

Brayan Rodriguez

unread,
Aug 29, 2019, 5:13:37 PM8/29/19
to Project Jupyter
Thank you so much! It seems it works! Just adding: 
pip install ipykernel
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

Jason Anderson

unread,
Aug 29, 2019, 5:26:02 PM8/29/19
to jup...@googlegroups.com
Very cool! Glad it worked out for you :)
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/e54ba4e6-5666-423c-b0b2-ae7f47eb8090%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages