Open IPython Notebook 2.7 and 3.4 in parallel

I searched for SO but did not find a clear answer to what I am trying to do. If the answer already exists, I will be grateful for passing the url. For reference: I am new to running multiple versions of Python and can run code through both interpreters. I am on Windows 7 and used the anaconda distribution.

In my cmd I activated Python2.7 by default. To access Python2.7 and Python3.4, I use python and py -3 respectively. I would like to be able to open portable IPython browsers for versions 2.7 and 3.4 in parallel, but I'm not sure what the command will look like / how to determine which browser window this interpreter is using.

From @Jonas Buckner's comment on How to activate Ipython Notebook and QT Console with Python 3.4 in Anaconda 2.0 , it seems like I can specify a port. My question is: how do I know which port # is associated with each version? Is it fixed, or can I determine which port?

ipython notebook not launching mentions ipython vs ipython3 , which I would prefer for the port method. However, when I try ipython3 notebook , I get:

 'ipython3' is not recognized as an internal or external command, operable program, or batch file. 

Can I set an alias? If so, how?

Repeat above as soon as I open parallel parallel portals, is there any way to find out which laptop is the version?

Thanks in advance!

+2
source share
2 answers

You can specify a port, so you choose a port number for each version; There are no predefined ports for python2 vs python3.

For instance:

 ipython notebook --port=10000 

will launch IPython using the default python interpreter on port 10000 . Then you can connect to this laptop by going to http://localhost:10000/tree .

Let's say that ipython2 starts IPython with python2.7, and ipython3 starts IPython with python3.4, you can start both IPythons with the commands:

 ipython2 notebook --port=27272 ipython3 notebook --port=34343 

If the page URL starts with localhost:27272 , then python 2.7 is running on the laptop, and if the URL starts with localhost:34343 then python 3.4 is running on the laptop.


Note that this in itself has nothing to do with the various versions of python. You can run two instances of IPython on different ports using the same interpreter.

If you want to start IPython using a specific interpreter, you can start it as a module using the -m switch:

 python2.7 -m IPython notebook --port=27272 python3.4 -m IPython notebook --port=34343 

therefore, you do not need to have ipython or ipython3 as recognized commands. You just need to be able to run two different interpreters.

Again: to understand which version of the interpreter you are using, you can simply look at the port number in the URL. Or you can check sys.version_info in the interpreter.


If you need to do this often, you may be interested in setting the port number parameter in the configuration file. I do not know if it is possible to have two different configuration files: one for python2 and one for python3. However, inside the file you can check the version and set the desired port number.

+1
source

You can specify the port in the ipython_notebook_config.py file, which is usually located in the ~/.ipython/profile_nbserver

For example, in my profile, I installed it to run on port 9999

 # Configuration file for ipython-notebook. c = get_config() c.NotebookApp.port = 9999 

You can get the Python version with the following command:

 import sys print (sys.version) 
+1
source

All Articles