Show More
@@ -1,233 +1,233 b'' | |||||
1 | ===================================== |
|
1 | ===================================== | |
2 | Introduction to IPython configuration |
|
2 | Introduction to IPython configuration | |
3 | ===================================== |
|
3 | ===================================== | |
4 |
|
4 | |||
5 | .. _setting_config: |
|
5 | .. _setting_config: | |
6 |
|
6 | |||
7 | Setting configurable options |
|
7 | Setting configurable options | |
8 | ============================ |
|
8 | ============================ | |
9 |
|
9 | |||
10 | Many of IPython's classes have configurable attributes (see |
|
10 | Many of IPython's classes have configurable attributes (see | |
11 | :doc:`options/index` for the list). These can be |
|
11 | :doc:`options/index` for the list). These can be | |
12 | configured in several ways. |
|
12 | configured in several ways. | |
13 |
|
13 | |||
14 | Python configuration files |
|
14 | Python configuration files | |
15 | -------------------------- |
|
15 | -------------------------- | |
16 |
|
16 | |||
17 | To create the blank configuration files, run:: |
|
17 | To create the blank configuration files, run:: | |
18 |
|
18 | |||
19 | ipython profile create [profilename] |
|
19 | ipython profile create [profilename] | |
20 |
|
20 | |||
21 | If you leave out the profile name, the files will be created for the |
|
21 | If you leave out the profile name, the files will be created for the | |
22 | ``default`` profile (see :ref:`profiles`). These will typically be located in |
|
22 | ``default`` profile (see :ref:`profiles`). These will typically be located in | |
23 | :file:`~/.ipython/profile_default/`, and will be named |
|
23 | :file:`~/.ipython/profile_default/`, and will be named | |
24 | :file:`ipython_config.py`, for historical reasons you may also find files |
|
24 | :file:`ipython_config.py`, for historical reasons you may also find files | |
25 | named with IPython prefix instead of Jupyter: |
|
25 | named with IPython prefix instead of Jupyter: | |
26 | :file:`ipython_notebook_config.py`, etc. The settings in |
|
26 | :file:`ipython_notebook_config.py`, etc. The settings in | |
27 | :file:`ipython_config.py` apply to all IPython commands. |
|
27 | :file:`ipython_config.py` apply to all IPython commands. | |
28 |
|
28 | |||
29 | By default, configuration files are fully featured Python scripts that can |
|
29 | By default, configuration files are fully featured Python scripts that can | |
30 | execute arbitrary code, the main usage is to set value on the configuration |
|
30 | execute arbitrary code, the main usage is to set value on the configuration | |
31 | object ``c`` which exist in your configuration file. |
|
31 | object ``c`` which exist in your configuration file. | |
32 |
|
32 | |||
33 | You can then configure class attributes like this:: |
|
33 | You can then configure class attributes like this:: | |
34 |
|
34 | |||
35 | c.InteractiveShell.automagic = False |
|
35 | c.InteractiveShell.automagic = False | |
36 |
|
36 | |||
37 | Be careful with spelling--incorrect names will simply be ignored, with |
|
37 | Be careful with spelling--incorrect names will simply be ignored, with | |
38 | no error. |
|
38 | no error. | |
39 |
|
39 | |||
40 | To add to a collection which may have already been defined elsewhere or have |
|
40 | To add to a collection which may have already been defined elsewhere or have | |
41 | default values, you can use methods like those found on lists, dicts and |
|
41 | default values, you can use methods like those found on lists, dicts and | |
42 | sets: append, extend, :meth:`~traitlets.config.LazyConfigValue.prepend` (like |
|
42 | sets: append, extend, :meth:`~traitlets.config.LazyConfigValue.prepend` (like | |
43 | extend, but at the front), add and update (which works both for dicts and |
|
43 | extend, but at the front), add and update (which works both for dicts and | |
44 | sets):: |
|
44 | sets):: | |
45 |
|
45 | |||
46 | c.InteractiveShellApp.extensions.append('Cython') |
|
46 | c.InteractiveShellApp.extensions.append('Cython') | |
47 |
|
47 | |||
48 | .. versionadded:: 2.0 |
|
48 | .. versionadded:: 2.0 | |
49 | list, dict and set methods for config values |
|
49 | list, dict and set methods for config values | |
50 |
|
50 | |||
51 | Example configuration file |
|
51 | Example configuration file | |
52 | `````````````````````````` |
|
52 | `````````````````````````` | |
53 |
|
53 | |||
54 | :: |
|
54 | :: | |
55 |
|
55 | |||
56 | # sample ipython_config.py |
|
56 | # sample ipython_config.py | |
57 |
|
57 | |||
58 | c.TerminalIPythonApp.display_banner = True |
|
58 | c.TerminalIPythonApp.display_banner = True | |
59 | c.InteractiveShellApp.log_level = 20 |
|
59 | c.InteractiveShellApp.log_level = 20 | |
60 | c.InteractiveShellApp.extensions = [ |
|
60 | c.InteractiveShellApp.extensions = [ | |
61 | 'myextension' |
|
61 | 'myextension' | |
62 | ] |
|
62 | ] | |
63 | c.InteractiveShellApp.exec_lines = [ |
|
63 | c.InteractiveShellApp.exec_lines = [ | |
64 | 'import numpy', |
|
64 | 'import numpy', | |
65 | 'import scipy' |
|
65 | 'import scipy' | |
66 | ] |
|
66 | ] | |
67 | c.InteractiveShellApp.exec_files = [ |
|
67 | c.InteractiveShellApp.exec_files = [ | |
68 | 'mycode.py', |
|
68 | 'mycode.py', | |
69 | 'fancy.ipy' |
|
69 | 'fancy.ipy' | |
70 | ] |
|
70 | ] | |
71 | c.InteractiveShell.colors = 'LightBG' |
|
71 | c.InteractiveShell.colors = 'LightBG' | |
72 | c.InteractiveShell.confirm_exit = False |
|
|||
73 | c.InteractiveShell.editor = 'nano' |
|
|||
74 | c.InteractiveShell.xmode = 'Context' |
|
72 | c.InteractiveShell.xmode = 'Context' | |
|
73 | c.TerminalInteractiveShell.confirm_exit = False | |||
|
74 | c.TerminalInteractiveShell.editor = 'nano' | |||
75 |
|
75 | |||
76 | c.PrefilterManager.multi_line_specials = True |
|
76 | c.PrefilterManager.multi_line_specials = True | |
77 |
|
77 | |||
78 | c.AliasManager.user_aliases = [ |
|
78 | c.AliasManager.user_aliases = [ | |
79 | ('la', 'ls -al') |
|
79 | ('la', 'ls -al') | |
80 | ] |
|
80 | ] | |
81 |
|
81 | |||
82 | JSON Configuration files |
|
82 | JSON Configuration files | |
83 | ------------------------ |
|
83 | ------------------------ | |
84 |
|
84 | |||
85 | In case where executability of configuration can be problematic, or |
|
85 | In case where executability of configuration can be problematic, or | |
86 | configurations need to be modified programmatically, IPython also support a |
|
86 | configurations need to be modified programmatically, IPython also support a | |
87 | limited set of functionalities via ``.json`` configuration files. |
|
87 | limited set of functionalities via ``.json`` configuration files. | |
88 |
|
88 | |||
89 | You can defined most of the configuration options via a json object which |
|
89 | You can defined most of the configuration options via a json object which | |
90 | hierarchy represent the value you would normally set on the ``c`` object of |
|
90 | hierarchy represent the value you would normally set on the ``c`` object of | |
91 | ``.py`` configuration files. The following ``ipython_config.json`` file:: |
|
91 | ``.py`` configuration files. The following ``ipython_config.json`` file:: | |
92 |
|
92 | |||
93 | { |
|
93 | { | |
94 | "InteractiveShell": { |
|
94 | "InteractiveShell": { | |
95 | "colors": "LightBG", |
|
95 | "colors": "LightBG", | |
96 | "editor": "nano" |
|
96 | "editor": "nano" | |
97 | }, |
|
97 | }, | |
98 | "InteractiveShellApp": { |
|
98 | "InteractiveShellApp": { | |
99 | "extensions": [ |
|
99 | "extensions": [ | |
100 | "myextension" |
|
100 | "myextension" | |
101 | ] |
|
101 | ] | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | Is equivalent to the following ``ipython_config.py``:: |
|
105 | Is equivalent to the following ``ipython_config.py``:: | |
106 |
|
106 | |||
107 | c.InteractiveShellApp.extensions = [ |
|
107 | c.InteractiveShellApp.extensions = [ | |
108 | 'myextension' |
|
108 | 'myextension' | |
109 | ] |
|
109 | ] | |
110 |
|
110 | |||
111 | c.InteractiveShell.colors = 'LightBG' |
|
111 | c.InteractiveShell.colors = 'LightBG' | |
112 | c.InteractiveShell.editor = 'nano' |
|
112 | c.InteractiveShell.editor = 'nano' | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | Command line arguments |
|
115 | Command line arguments | |
116 | ---------------------- |
|
116 | ---------------------- | |
117 |
|
117 | |||
118 | Every configurable value can be set from the command line, using this |
|
118 | Every configurable value can be set from the command line, using this | |
119 | syntax:: |
|
119 | syntax:: | |
120 |
|
120 | |||
121 | ipython --ClassName.attribute=value |
|
121 | ipython --ClassName.attribute=value | |
122 |
|
122 | |||
123 | Many frequently used options have short aliases and flags, such as |
|
123 | Many frequently used options have short aliases and flags, such as | |
124 | ``--matplotlib`` (to integrate with a matplotlib GUI event loop) or |
|
124 | ``--matplotlib`` (to integrate with a matplotlib GUI event loop) or | |
125 | ``--pdb`` (automatic post-mortem debugging of exceptions). |
|
125 | ``--pdb`` (automatic post-mortem debugging of exceptions). | |
126 |
|
126 | |||
127 | To see all of these abbreviated options, run:: |
|
127 | To see all of these abbreviated options, run:: | |
128 |
|
128 | |||
129 | ipython --help |
|
129 | ipython --help | |
130 | jupyter notebook --help |
|
130 | jupyter notebook --help | |
131 | # etc. |
|
131 | # etc. | |
132 |
|
132 | |||
133 | Options specified at the command line, in either format, override |
|
133 | Options specified at the command line, in either format, override | |
134 | options set in a configuration file. |
|
134 | options set in a configuration file. | |
135 |
|
135 | |||
136 | The config magic |
|
136 | The config magic | |
137 | ---------------- |
|
137 | ---------------- | |
138 |
|
138 | |||
139 | You can also modify config from inside IPython, using a magic command:: |
|
139 | You can also modify config from inside IPython, using a magic command:: | |
140 |
|
140 | |||
141 | %config IPCompleter.greedy = True |
|
141 | %config IPCompleter.greedy = True | |
142 |
|
142 | |||
143 | At present, this only affects the current session - changes you make to |
|
143 | At present, this only affects the current session - changes you make to | |
144 | config are not saved anywhere. Also, some options are only read when |
|
144 | config are not saved anywhere. Also, some options are only read when | |
145 | IPython starts, so they can't be changed like this. |
|
145 | IPython starts, so they can't be changed like this. | |
146 |
|
146 | |||
147 | .. _configure_start_ipython: |
|
147 | .. _configure_start_ipython: | |
148 |
|
148 | |||
149 | Running IPython from Python |
|
149 | Running IPython from Python | |
150 | ---------------------------- |
|
150 | ---------------------------- | |
151 |
|
151 | |||
152 | If you are using :ref:`embedding` to start IPython from a normal |
|
152 | If you are using :ref:`embedding` to start IPython from a normal | |
153 | python file, you can set configuration options the same way as in a |
|
153 | python file, you can set configuration options the same way as in a | |
154 | config file by creating a traitlets config object and passing it to |
|
154 | config file by creating a traitlets config object and passing it to | |
155 | start_ipython like in the example below. |
|
155 | start_ipython like in the example below. | |
156 |
|
156 | |||
157 | .. literalinclude:: ../../../examples/Embedding/start_ipython_config.py |
|
157 | .. literalinclude:: ../../../examples/Embedding/start_ipython_config.py | |
158 | :language: python |
|
158 | :language: python | |
159 |
|
159 | |||
160 | .. _profiles: |
|
160 | .. _profiles: | |
161 |
|
161 | |||
162 | Profiles |
|
162 | Profiles | |
163 | ======== |
|
163 | ======== | |
164 |
|
164 | |||
165 | IPython can use multiple profiles, with separate configuration and |
|
165 | IPython can use multiple profiles, with separate configuration and | |
166 | history. By default, if you don't specify a profile, IPython always runs |
|
166 | history. By default, if you don't specify a profile, IPython always runs | |
167 | in the ``default`` profile. To use a new profile:: |
|
167 | in the ``default`` profile. To use a new profile:: | |
168 |
|
168 | |||
169 | ipython profile create foo # create the profile foo |
|
169 | ipython profile create foo # create the profile foo | |
170 | ipython --profile=foo # start IPython using the new profile |
|
170 | ipython --profile=foo # start IPython using the new profile | |
171 |
|
171 | |||
172 | Profiles are typically stored in :ref:`ipythondir`, but you can also keep |
|
172 | Profiles are typically stored in :ref:`ipythondir`, but you can also keep | |
173 | a profile in the current working directory, for example to distribute it |
|
173 | a profile in the current working directory, for example to distribute it | |
174 | with a project. To find a profile directory on the filesystem:: |
|
174 | with a project. To find a profile directory on the filesystem:: | |
175 |
|
175 | |||
176 | ipython locate profile foo |
|
176 | ipython locate profile foo | |
177 |
|
177 | |||
178 | .. _ipythondir: |
|
178 | .. _ipythondir: | |
179 |
|
179 | |||
180 | The IPython directory |
|
180 | The IPython directory | |
181 | ===================== |
|
181 | ===================== | |
182 |
|
182 | |||
183 | IPython stores its files---config, command history and extensions---in |
|
183 | IPython stores its files---config, command history and extensions---in | |
184 | the directory :file:`~/.ipython/` by default. |
|
184 | the directory :file:`~/.ipython/` by default. | |
185 |
|
185 | |||
186 | .. envvar:: IPYTHONDIR |
|
186 | .. envvar:: IPYTHONDIR | |
187 |
|
187 | |||
188 | If set, this environment variable should be the path to a directory, |
|
188 | If set, this environment variable should be the path to a directory, | |
189 | which IPython will use for user data. IPython will create it if it |
|
189 | which IPython will use for user data. IPython will create it if it | |
190 | does not exist. |
|
190 | does not exist. | |
191 |
|
191 | |||
192 | .. option:: --ipython-dir=<path> |
|
192 | .. option:: --ipython-dir=<path> | |
193 |
|
193 | |||
194 | This command line option can also be used to override the default |
|
194 | This command line option can also be used to override the default | |
195 | IPython directory. |
|
195 | IPython directory. | |
196 |
|
196 | |||
197 | To see where IPython is looking for the IPython directory, use the command |
|
197 | To see where IPython is looking for the IPython directory, use the command | |
198 | ``ipython locate``, or the Python function :func:`IPython.paths.get_ipython_dir`. |
|
198 | ``ipython locate``, or the Python function :func:`IPython.paths.get_ipython_dir`. | |
199 |
|
199 | |||
200 |
|
200 | |||
201 | Systemwide configuration |
|
201 | Systemwide configuration | |
202 | ======================== |
|
202 | ======================== | |
203 |
|
203 | |||
204 | It can be useful to deploy systemwide ipython or ipykernel configuration |
|
204 | It can be useful to deploy systemwide ipython or ipykernel configuration | |
205 | when managing environment for many users. At startup time IPython and |
|
205 | when managing environment for many users. At startup time IPython and | |
206 | IPykernel will search for configuration file in multiple systemwide |
|
206 | IPykernel will search for configuration file in multiple systemwide | |
207 | locations, mainly: |
|
207 | locations, mainly: | |
208 |
|
208 | |||
209 | - ``/etc/ipython/`` |
|
209 | - ``/etc/ipython/`` | |
210 | - ``/usr/local/etc/ipython/`` |
|
210 | - ``/usr/local/etc/ipython/`` | |
211 |
|
211 | |||
212 | When the global install is a standalone python distribution it may also |
|
212 | When the global install is a standalone python distribution it may also | |
213 | search in distribution specific location, for example: |
|
213 | search in distribution specific location, for example: | |
214 |
|
214 | |||
215 | - ``$ANACONDA_LOCATION/etc/ipython/`` |
|
215 | - ``$ANACONDA_LOCATION/etc/ipython/`` | |
216 |
|
216 | |||
217 | In those locations, Terminal IPython will look for a file called |
|
217 | In those locations, Terminal IPython will look for a file called | |
218 | ``ipython_config.py`` and ``ipython_config.json``, ipykernel will look for |
|
218 | ``ipython_config.py`` and ``ipython_config.json``, ipykernel will look for | |
219 | ``ipython_kernel_config.py`` and ``ipython_kernel.json``. |
|
219 | ``ipython_kernel_config.py`` and ``ipython_kernel.json``. | |
220 |
|
220 | |||
221 | Configuration files are loaded in order and merged with configuration on |
|
221 | Configuration files are loaded in order and merged with configuration on | |
222 | later location taking precedence on earlier locations (that is to say a user |
|
222 | later location taking precedence on earlier locations (that is to say a user | |
223 | can overwrite a systemwide configuration option). |
|
223 | can overwrite a systemwide configuration option). | |
224 |
|
224 | |||
225 | You can see all locations in which IPython is looking for configuration files |
|
225 | You can see all locations in which IPython is looking for configuration files | |
226 | by starting ipython in debug mode:: |
|
226 | by starting ipython in debug mode:: | |
227 |
|
227 | |||
228 | $ ipython --debug -c 'exit()' |
|
228 | $ ipython --debug -c 'exit()' | |
229 |
|
229 | |||
230 | Identically with ipykernel though the command is currently blocking until |
|
230 | Identically with ipykernel though the command is currently blocking until | |
231 | this process is killed with ``Ctrl-\``:: |
|
231 | this process is killed with ``Ctrl-\``:: | |
232 |
|
232 | |||
233 | $ python -m ipykernel --debug |
|
233 | $ python -m ipykernel --debug |
General Comments 0
You need to be logged in to leave comments.
Login now