iPython settings etc.

Solved the problem when using ipython on Windows.

A little setup to master iPython with Windows PowerShell

I often use iPython on Windows PowerShell to check a little code or write and execute a discard script, but can I manage the color scheme at that time? I was thinking.

Specifically, certain keywords can be invisible by batting with the PowerShell "screen color" setting. For example, "in" disappears. Even though it's a keyword I use so often.

This is probably due to the fact that the background color set in the Windows PowerShell console is the same as the color set in the iPython color scheme.

for x in range(100):
	...

IMG_3104.PNG

Also, when I want to draw a graph and check it, I often forget to add "--matplotlib" when starting ipython, and each time I really throw away the discard script I wrote so far and exit ipython. I was also dissatisfied with having to restart.

Dissatisfaction with iPython

--Some characters disappear when used on Windows PowerShell --It's easy to forget the boot option "--matplotlib"

To resolve these complaints, you need to have the default settings at ipython startup in place.

Creating an iPython configuration file

For the iPython configuration file, when you enter the following command on Windows PowerShell, a folder called ".ipython \ profile_default" is created in the folder set in the environment variable% HOME%, and "ipython_config.py" is created there. A file called "ipython_kernel_config.py" will be created.

PS C:¥Users¥user01> ipython profile create
[ProfileCreate] Generating default config file: 'c:¥¥Users¥¥user01¥¥.ipython¥¥profile_default¥¥ipython_config.py'
[ProfileCreate] Generating default config file: 'c:¥¥Users¥¥user01¥¥.ipython¥¥profile_default¥¥ipython_kernel_config.py'

After that, you can change the settings by editing this ipython_config.py.

Change color scheme

Line 183 of ipython_config.py has the following description.

#c.InteractiveShell.colors = 'Neutral'

After removing this leading "#", change Neutral to Linux. Unfortunately, the only color scheme available is "No Color, Neutral, Linux or Light BG".

c.InteractiveShell.colors = 'Linux'

Now the keyword in is displayed properly as shown in the figure below.

IMG_3106.PNG

On line 308, there is a commented out description "# c.TerminalInteractiveShell.highlighting_style = traitlets.Undefined", and it seems that highlighting_style can also be described here, but it is illustrated on line 307. I tried to describe the style as it is, but it didn't work. It may not be supported by Windows PowerShell.

matplotlib settings

To use iPython with matplotlib functionality, also set ipython_config.py.

On line 52, there is a commented out line that looks like this:

#c.InteractiveShellApp.matplotlib = None

Remove the "#" at the beginning of this line and change the description as follows.

c.InteractiveShellApp.matplotlib = 'auto'

Then, even in the iPython environment started without `` --matplotlib```, if you use the function defined in matplotlib.pyplot, the graph will be displayed.

from matplotlib import pyplot as plt
from numpy import random

plt.scatter(random.rand(10), random.rand(10))

IMG_3107.PNG

Summary

The iPython configuration file is generated by ipython profile create.

By editing the generated ipython_config.py, it is possible to change the color scheme and display images etc. in another window when matplotlib is called.

Recommended Posts

iPython settings etc.
samba settings
ipython + jupyter + plotly (matplotlib) settings & usage notes
VIM settings