Show More
@@ -1,80 +1,96 b'' | |||||
1 | .. _kernel_install: |
|
1 | .. _kernel_install: | |
2 |
|
2 | |||
3 | Installing the IPython kernel |
|
3 | Installing the IPython kernel | |
4 | ============================= |
|
4 | ============================= | |
5 |
|
5 | |||
6 | .. seealso:: |
|
6 | .. seealso:: | |
7 |
|
7 | |||
8 | :ref:`Installing Jupyter <jupyter:install>` |
|
8 | :ref:`Installing Jupyter <jupyter:install>` | |
9 | The IPython kernel is the Python execution backend for Jupyter. |
|
9 | The IPython kernel is the Python execution backend for Jupyter. | |
10 |
|
10 | |||
11 | The Jupyter Notebook and other frontends automatically ensure that the IPython kernel is available. |
|
11 | The Jupyter Notebook and other frontends automatically ensure that the IPython kernel is available. | |
12 | However, if you want to use a kernel with a different version of Python, or in a virtualenv or conda environment, |
|
12 | However, if you want to use a kernel with a different version of Python, or in a virtualenv or conda environment, | |
13 | you'll need to install that manually. |
|
13 | you'll need to install that manually. | |
14 |
|
14 | |||
15 | Kernels for Python 2 and 3 |
|
15 | Kernels for Python 2 and 3 | |
16 | -------------------------- |
|
16 | -------------------------- | |
17 |
|
17 | |||
18 | If you're running Jupyter on Python 3, you can set up a Python 2 kernel like this:: |
|
18 | If you're running Jupyter on Python 3, you can set up a Python 2 kernel like this:: | |
19 |
|
19 | |||
20 | python2 -m pip install ipykernel |
|
20 | python2 -m pip install ipykernel | |
21 | python2 -m ipykernel install --user |
|
21 | python2 -m ipykernel install --user | |
22 |
|
22 | |||
23 | Or using conda, create a Python 2 environment:: |
|
23 | Or using conda, create a Python 2 environment:: | |
24 |
|
24 | |||
25 | conda create -n ipykernel_py2 python=2 ipykernel |
|
25 | conda create -n ipykernel_py2 python=2 ipykernel | |
26 | source activate ipykernel_py2 # On Windows, remove the word 'source' |
|
26 | source activate ipykernel_py2 # On Windows, remove the word 'source' | |
27 | python -m ipykernel install --user |
|
27 | python -m ipykernel install --user | |
28 |
|
28 | |||
29 | If you're running Jupyter on Python 2 and want to set up a Python 3 kernel, |
|
29 | If you're running Jupyter on Python 2 and want to set up a Python 3 kernel, | |
30 | follow the same steps, replacing ``2`` with ``3``. |
|
30 | follow the same steps, replacing ``2`` with ``3``. | |
31 |
|
31 | |||
32 | The last command installs a :ref:`kernel spec <jupyterclient:kernelspecs>` file |
|
32 | The last command installs a :ref:`kernel spec <jupyterclient:kernelspecs>` file | |
33 | for the current python installation. Kernel spec files are JSON files, which |
|
33 | for the current python installation. Kernel spec files are JSON files, which | |
34 | can be viewed and changed with a normal text editor. |
|
34 | can be viewed and changed with a normal text editor. | |
35 |
|
35 | |||
36 | .. _multiple_kernel_install: |
|
36 | .. _multiple_kernel_install: | |
37 |
|
37 | |||
38 | Kernels for different environments |
|
38 | Kernels for different environments | |
39 | ---------------------------------- |
|
39 | ---------------------------------- | |
40 |
|
40 | |||
41 |
If you want to have multiple IPython kernels for different virtualenvs or conda |
|
41 | If you want to have multiple IPython kernels for different virtualenvs or conda | |
42 | you will need to specify unique names for the kernelspecs. |
|
42 | environments, you will need to specify unique names for the kernelspecs. | |
43 |
|
43 | |||
44 | For example, using conda environments: |
|
44 | Make sure you have ipykernel installed in your environement. If you are using | |
|
45 | ``pip`` to install ``ipykernel`` in a conda env, make sure ``pip`` is | |||
|
46 | installed:: | |||
|
47 | ||||
|
48 | .. sourcecode:: bash | |||
|
49 | ||||
|
50 | source activate myenv | |||
|
51 | conda install pip | |||
|
52 | conda install ipykernel # or pip install ipykernel | |||
|
53 | ||||
|
54 | For example, using conda environments, install a ``Python (myenv)`` Kernel in a first | |||
|
55 | environment: | |||
45 |
|
56 | |||
46 | .. sourcecode:: bash |
|
57 | .. sourcecode:: bash | |
47 |
|
58 | |||
48 | source activate myenv |
|
59 | source activate myenv | |
49 | python -m ipykernel install --user --name myenv --display-name "Python (myenv)" |
|
60 | python -m ipykernel install --user --name myenv --display-name "Python (myenv)" | |
|
61 | ||||
|
62 | And in a second environment, after making sure ipykernel is installed in it: | |||
|
63 | ||||
|
64 | .. sourcecode:: bash | |||
|
65 | ||||
50 | source activate other-env |
|
66 | source activate other-env | |
51 | python -m ipykernel install --user --name other-env --display-name "Python (other-env)" |
|
67 | python -m ipykernel install --user --name other-env --display-name "Python (other-env)" | |
52 |
|
68 | |||
53 | The ``--name`` value is used by Jupyter internally. These commands will overwrite |
|
69 | The ``--name`` value is used by Jupyter internally. These commands will overwrite | |
54 | any existing kernel with the same name. ``--display-name`` is what you see in |
|
70 | any existing kernel with the same name. ``--display-name`` is what you see in | |
55 | the notebook menus. |
|
71 | the notebook menus. | |
56 |
|
72 | |||
57 | Using virtualenv or conda envs, you can make your IPython kernel in one env available to Jupyter in a different env. To do so, run ipykernel install from the kernel's env, with --prefix pointing to the Jupyter env: |
|
73 | Using virtualenv or conda envs, you can make your IPython kernel in one env available to Jupyter in a different env. To do so, run ipykernel install from the kernel's env, with --prefix pointing to the Jupyter env: | |
58 |
|
74 | |||
59 | .. sourcecode:: bash |
|
75 | .. sourcecode:: bash | |
60 |
|
76 | |||
61 | /path/to/kernel/env/bin/python -m ipykernel install --prefix=/path/to/jupyter/env --name 'python-my-env' |
|
77 | /path/to/kernel/env/bin/python -m ipykernel install --prefix=/path/to/jupyter/env --name 'python-my-env' | |
62 |
|
78 | |||
63 | Note that this command will create a new configuration for the kernel in one of the prefered location (see ``jupyter --paths`` command for more details): |
|
79 | Note that this command will create a new configuration for the kernel in one of the prefered location (see ``jupyter --paths`` command for more details): | |
64 |
|
80 | |||
65 | * system-wide (e.g. /usr/local/share), |
|
81 | * system-wide (e.g. /usr/local/share), | |
66 | * in Jupyter's env (sys.prefix/share), |
|
82 | * in Jupyter's env (sys.prefix/share), | |
67 | * per-user (~/.local/share or ~/Library/share) |
|
83 | * per-user (~/.local/share or ~/Library/share) | |
68 |
|
84 | |||
69 | If you want to edit the kernelspec before installing it, you can do so in two steps. |
|
85 | If you want to edit the kernelspec before installing it, you can do so in two steps. | |
70 | First, ask IPython to write its spec to a temporary location: |
|
86 | First, ask IPython to write its spec to a temporary location: | |
71 |
|
87 | |||
72 | .. sourcecode:: bash |
|
88 | .. sourcecode:: bash | |
73 |
|
89 | |||
74 | ipython kernel install --prefix /tmp |
|
90 | ipython kernel install --prefix /tmp | |
75 |
|
91 | |||
76 | edit the files in /tmp/share/jupyter/kernels/python3 to your liking, then when you are ready, tell Jupyter to install it (this will copy the files into a place Jupyter will look): |
|
92 | edit the files in /tmp/share/jupyter/kernels/python3 to your liking, then when you are ready, tell Jupyter to install it (this will copy the files into a place Jupyter will look): | |
77 |
|
93 | |||
78 | .. sourcecode:: bash |
|
94 | .. sourcecode:: bash | |
79 |
|
95 | |||
80 | jupyter kernelspec install /tmp/share/jupyter/kernels/python3 |
|
96 | jupyter kernelspec install /tmp/share/jupyter/kernels/python3 |
General Comments 0
You need to be logged in to leave comments.
Login now