Anaconda: Python 3 and 2 in IPython/Jupyter Notebook

sonium

I have a Python 3 installation of Anaconda and want to be able to switch quickly between python2 and 3 kernels. This is on OSX.

My steps so far involved:

conda create -p ~/anaconda/envs/python2 python=2.7
source activate python2
conda install ipython
ipython kernelspec install-self
source deactivate

After this I have a python2 Kernel to choose from in the python3 IPython notebook, which however can't start.

So I went ahead and modified /usr/local/share/jupyter/kernels/python2/kernel.json

{
 "display_name": "Python 2",
 "language": "python",
 "argv": [
  "/Users/sonium/anaconda/envs/python2/bin/python",
  "-m",
  "IPython.kernel",
  "-f",
  "{connection_file}"
 ],
 "env":{"PYTHONHOME":"~/anaconda/envs/python2/:~/anaconda/envs/python2/lib/"}
}

Now when I start the python2 kernel it fails with:

ImportError: No module named site
sonium

Apparently IPython expects explicit pathnames, so no '~' instead of the home directory. It worked after changing the kernel.json to:

{
 "display_name": "Python 2",
 "language": "python",
 "argv": [
  "/Users/sonium/anaconda/envs/python2/bin/python2.7",
  "-m",
  "IPython.kernel",
  "-f",
  "{connection_file}"
 ],
 "env":{"PYTHONHOME":"/Users/sonium/anaconda/envs/python2"}
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jupyter notebook with Python 2 and Python3 Kernel

From Dev

How to activate Ipython Notebook and QT Console with Python 3.4 in Anaconda 2.0

From Dev

Anaconda jupyter notebook

From Dev

Jupyter Notebook - Python 3 kernel

From Dev

How do I switch back to python2 after Anaconda set python3 as the default?

From Dev

How do I switch back to python2 after Anaconda set python3 as the default?

From Java

Using both Python 2.x and Python 3.x in IPython Notebook

From Dev

Easiest way to have Python 2 and 3 coexist on Mac OSX 10.8 with Anaconda installed

From Dev

Function CalcEMD2 missing from OpenCV3 module for Anaconda Python

From Dev

ipython notebook command in anaconda opens jupyter notebook?

From Dev

Installing opencv 3.1 with anaconda python3?

From Dev

Error "%1 is not a valid Win32 application" when starting IPython Notebook (Anaconda 3)

From Dev

Changing the tab sizes of a Notebook widget in Python 3

From Dev

Python 3.x : Jupyter Notebook and Pandas

From Dev

Install psycopg2 for Anaconda Python

From Dev

Having installed Pillow in Anaconda3, Python 3 does not find it

From Dev

How can I uninstall Anaconda2 and install Anaconda3?

From Dev

How to switch to python 2.7 from python 3- jupyter notebook

From Dev

can not start ipython notebook from anaconda

From Dev

Run ipython notebook in different anaconda environment (in script)

From Dev

Configuring Spark to work with Jupyter Notebook and Anaconda

From Dev

Created an Anaconda python3 environment but it still loads ipython 2.7.6

From Dev

Activate python 3 environemnt in Anaconda with batch-file

From Dev

How to install gi module for anaconda python3?

From Dev

Installing openCV in anaconda3 - Python.h: No such file or directory

From Dev

I can't install anaconda for python3

From Dev

How to enable intellisense for python in Visual Studio Code with anaconda3?

From Dev

Created an Anaconda python3 environment but it still loads ipython 2.7.6

From Dev

Activate python 3 environemnt in Anaconda with batch-file

Related Related

  1. 1

    Jupyter notebook with Python 2 and Python3 Kernel

  2. 2

    How to activate Ipython Notebook and QT Console with Python 3.4 in Anaconda 2.0

  3. 3

    Anaconda jupyter notebook

  4. 4

    Jupyter Notebook - Python 3 kernel

  5. 5

    How do I switch back to python2 after Anaconda set python3 as the default?

  6. 6

    How do I switch back to python2 after Anaconda set python3 as the default?

  7. 7

    Using both Python 2.x and Python 3.x in IPython Notebook

  8. 8

    Easiest way to have Python 2 and 3 coexist on Mac OSX 10.8 with Anaconda installed

  9. 9

    Function CalcEMD2 missing from OpenCV3 module for Anaconda Python

  10. 10

    ipython notebook command in anaconda opens jupyter notebook?

  11. 11

    Installing opencv 3.1 with anaconda python3?

  12. 12

    Error "%1 is not a valid Win32 application" when starting IPython Notebook (Anaconda 3)

  13. 13

    Changing the tab sizes of a Notebook widget in Python 3

  14. 14

    Python 3.x : Jupyter Notebook and Pandas

  15. 15

    Install psycopg2 for Anaconda Python

  16. 16

    Having installed Pillow in Anaconda3, Python 3 does not find it

  17. 17

    How can I uninstall Anaconda2 and install Anaconda3?

  18. 18

    How to switch to python 2.7 from python 3- jupyter notebook

  19. 19

    can not start ipython notebook from anaconda

  20. 20

    Run ipython notebook in different anaconda environment (in script)

  21. 21

    Configuring Spark to work with Jupyter Notebook and Anaconda

  22. 22

    Created an Anaconda python3 environment but it still loads ipython 2.7.6

  23. 23

    Activate python 3 environemnt in Anaconda with batch-file

  24. 24

    How to install gi module for anaconda python3?

  25. 25

    Installing openCV in anaconda3 - Python.h: No such file or directory

  26. 26

    I can't install anaconda for python3

  27. 27

    How to enable intellisense for python in Visual Studio Code with anaconda3?

  28. 28

    Created an Anaconda python3 environment but it still loads ipython 2.7.6

  29. 29

    Activate python 3 environemnt in Anaconda with batch-file

HotTag

Archive