2

I've searched through SO, but haven't found a clear answer to what I'm trying to do. If the answer already exists, I'd appreciate a pass-along of the URL. For reference: I'm new to running multiple Python versions, and can run code through both interpreters. I'm on Windows 7, and used the anaconda distribution.

In my cmd, I've activated Python2.7 as default. To access Python2.7 and Python3.4, I use python and py -3 respectively. I'd like to be able to open IPython browser notebooks for 2.7 and 3.4 in parallel, but am not sure how the command would look/how to determine which browser window is using which interpreter.

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

ipython notebook not launching mentions ipython vs ipython3, which I would really prefer, to 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.

Is it possible to set up an alias? If so, how?

To reiterate from above, once I've opened notebooks in parallel, is there a way for me to tell which notebook is which version?

Thanks in advance!

Community
  • 1
  • 1
Amy D
  • 571
  • 2
  • 7
  • 16

2 Answers2

1

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

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

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

You can get Python version with the following command:

import sys
print (sys.version)
Amit
  • 19,780
  • 6
  • 46
  • 54
1

You can specify the port, so you choose the port number to use for each version; there are no predefined ports for python2 vs python3.

For example:

ipython notebook --port=10000

will run IPython, using the default python interpreter, on port 10000. You can then connect to that notebook by going to http://localhost:10000/tree.

Say that ipython2 launches IPython with python2.7 while ipython3 launches IPython with python3.4 you can run both IPythons with the commands:

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

If the URL of a page starts with localhost:27272 then the notebook is running python 2.7 while if the URL starts with localhost:34343 then the notebook is running python 3.4.


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

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

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

so you don't need to have ipython or ipython3 as recognized commands. You simply need to be able to run the 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 have to do this often you may be interested in putting the port number setting in a configuration file. I don't know whether it's 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 right port number.

Bakuriu
  • 98,325
  • 22
  • 197
  • 231