Forums

Starting an ipython / jupyter notebook inside a virtualenv

Is there a way to do this? Start an ipython / jupyter notebook inside of a specific virtualenv?

Background: I am taking a Udacity deep learning class that uses the google tensorflow library. The class provides some ipython notebooks as projects / homework to work from.

I have created a python 2.7 virtualenv ("tensorflow") and have installed ipython, jupyter and tensorflow there. I have uploaded the Udacity class ipython notebook into my home directory.

A) From inside the pythonanywhere virtual environment, I can start a notebook on a localhost, but I don't have access to that localhost port, so that doesn't seem to give me access to the running notebook.

B) I can create an empty python 2.7 notebook, and I could cut and paste the Udacity notebook material into that notebook as a workaround (I guess) but the python 2.7 notebook environment does not have access to the tensorflow library in the virtualenv.

C) I guess I could install the tensorflow library into my default (python 2.7) workspace without a virtual environment, but there appear to be many dependencies and this kind of defeats the purpose of having virtual environments. Maybe this would work, but right now I don't want to risk introducing some other package/module dependency.

D) From the files tab, I can select and open one of the ipython notebooks in my home directory, and while this opens with python 3.x, I can go into the kernel tab and select the 2.7 kernel environment. I think this is giving me my default 2.7 home env python, and there is no tensorflow library there.

Other ideas or suggestions? After I wrote this I realized options B) and D) are basically the same.

Thanks.

At the moment, it's a little bit of a hassle.

We have a help page on it, but for some reason, it's not appearing in the search. It's here.

The feature is pretty new so let us know if there's anything we can make clearer in the docs.

Thanks Glenn. The instructions don't look too bad compared to other things I have been trying! I had tried searching the forums prior the post and had not found the help page.

Cool. I'll try to work out why the page was not in the help search.

Hi Glenn ,

I just went through the help page you pointed me to and it worked great!

I am up and running with a jupyter notebook in my tensorflow virtual environment.

It was very simple to set up compared to the other options I was looking at.

I found getting the combination of jupyter notebook and tensorflow together was fairly complex outside of PythonAnywhere. My best alternate approach was going to be installing the Anaconda distribution into a AWS EC2 / AMI / ECD instance. The PythonAnywhere jupyter notebook is so much better ! Much easier for me to work with PA than direct AWS EC2 ...

Thank you!

Excellent, glad you got it working OK :-)

Hi Giles,

Just a note that I also tried the jupyter notebook from the inside of an anaconda virtual environment. This did not work, I was able to create a kernel and find in the notebook 'select kernel' tab. The notebook was not able to connect to the kernel, calling it a 'dead kernel'.

Note that I do not need this conda environment to work at this time, I am using the regular virtualenvironment and installing the modules I need into that location.

Just a note for your long list of features to prioritize!

Thanks.

OK -- many thanks! I've put it on the (yes, definitely long :-) list with an upvote on your behalf. If anyone else is keen on notebooks using Anaconda virtualenvs, let us know.

I created a python3.5 virtual environment and followed the instructions in the link http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs but it created a python 2.7 kernelspec.

What am I doing wrong?

(plam35) 20:42 ~/PLAM$ which python
/home/jenyquist/.virtualenvs/plam35/bin/python
(plam35) 20:42 ~/PLAM$ python --version
Python 3.5.1
(plam35) 20:42 ~/PLAM$ jupyter kernelspec install-self --user                                                                                               
[InstallNativeKernelSpec] Installed kernelspec python2 in /home/jenyquist/.local/share/jupyter/kernels/python2
(plam35) 20:42 ~/PLAM$

What happens if you run "which jupyter" in the virtualenv?

(plam35) 20:42 ~/PLAM$ which jupyter /usr/local/bin/jupyter

Ah, that's the system jupyter.

Try installing jupyter into your virtualenv?

That did it! Once I installed Jupyter into the virtualenv and renamed the kernel in the JSON file I could change to it from the notebook kernel menu. Convoluted, but it works!

How do you actually launch the web app Jupyter rather than ipython notebook in the command line editor? In past experience I would type in "ipython notebook" on my local machine and I'm stuck on how to get this to work on PA.

I followed the instructions on https://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs/ . Once getting past step 2 I'm getting permissions denied when trying to change the name of the kernel ipython displays.

About three months ago I got this to work on PA, then reverted back to a free account. Tonight I decided to start another paid subscription and can't figure out the problem. Jupyter is the main reason I'm wanting to move forward with a paid account.

Thanks.

You don't need to "launch the web app Jupyter" on PythonAnywhere. Just go to the Files tab and create one.

Thanks, Glenn....that worked!

Hello, I installed a virtualenv, and also installed jupyter in my virtualenv, but i'm still unable to launch a notebook ...

I run the command $: jupyter notebook and get the following : ...

[C 01:36:10.774 NotebookApp] Bad config encountered during initialization: [C 01:36:10.779 NotebookApp] The 'kernel_spec_manager_class' trait of <notebook.notebookapp.NotebookApp object at 0x7f48b7abe550> instance m ust be a type, but 'environment_kernels.EnvironmentKernelSpecManager' could not be imported

You don't launch Jupyter Notebooks from the console on PythonAnywhere, you do that from the Files tab. You can either create a new notebook from there or you can open an existing one.

You don't launch Jupyter Notebooks from the console on PythonAnywhere, you do that from the Files tab. You can either create a new notebook from there or you can open an existing one.

Is there a page that explains how to do this? I'm not trying to do anything fancy, just run a Jupyter notebook inside PythonAnywhere. Any help appreciated.

That is the explanation of how to do it. Notebooks are only available to paying users, though.

Ahhhh....

So if I have a paying account will there be a new button in the UI?

EDIT: Nvm. Got it.

You guys are pure joy. I just found this and I'm glad I did.

Thanks.

Sorry, I might be doing something stupid / missing something obvious, but I'm unable to get an iPython Notebook started in my virtualenv. Each time I try to create a sqlalchemy engine within the Notebook, I get an error on the connection string, "pymysql not installed" (or something to that effect).

My set-up:

  • virtualenv with pymysql installed, and activated via source env/bin/activate

  • created a notebook, but no option in kernal > change kernal allows me to switch to the virtualenv

Directory structure:

HOME 
|_ project
        |_ env 
|_ notebooks
        |_ python_notebook.ipynb

Have you followed these instructions?

Hey Conrad,

Yes, and my kernal does not appear in the list of options - only different Python versions.

Paul

The ipython kernel search only looks in ~/.virtualenvs for virtualenvs to use for kernels.

Thanks Glenn. Perhaps this could be added to the instructions?

Yes, it should. I have updated the documentation.

In case anyone is still having trouble, you can use this guide

https://ipython.readthedocs.io/en/stable/install/kernel_install.html

Thanks, that's a useful link!

Any reason the virtualenv needs to downgrade those packages to be the same (e.g. tornado 6.1 -> 5.1.1 as I read this thread)

Is it a dependency of another package? It may require an older version.