Spyder: IPython: Run Code at Startup - Magics

Created on 8 Aug 2017  ·  3Comments  ·  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

  1. Start Spyder
  2. Open Preferences
  3. Select IPython console preferences
  4. Select Startup Tab
  5. Enter %load_ext autoreload, %autoreload 2
  6. Click Apply

What is the expected output? What do you see instead?

  • Expected: Allow these valid IPython magics to be stored in the config and loaded on Console startup
  • Actual: The commands cause the error below

Please provide any additional information below

File "C:\Anaconda3\lib\site-packages\spyder\plugins\configdialog.py", line 221, in button_clicked
configpage.apply_changes()
File "C:\Anaconda3\lib\site-packages\spyder\plugins\configdialog.py", line 100, in apply_changes
self.save_to_conf()
File "C:\Anaconda3\lib\site-packages\spyder\plugins\configdialog.py", line 408, in save_to_conf
self.set_option(option, to_text_string(lineedit.text()))
File "C:\Anaconda3\lib\site-packages\spyder\plugins__init__.py", line 437, in set_option
CONF.set(self.CONF_SECTION, str(option), value)
File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 443, in set
self._set(section, option, value, verbose)
File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 86, in _set
cp.ConfigParser.set(self, section, option, value)
File "C:\Anaconda3\lib\configparser.py", line 1193, in set
super().set(section, option, value)
File "C:\Anaconda3\lib\configparser.py", line 894, in set
value)
File "C:\Anaconda3\lib\configparser.py", line 402, in before_set
"position %d" % (value, tmp_value.find('%')))
ValueError: invalid interpolation syntax in '%load_ext autoreload, %a

Work Around
from IPython import get_ipython, ipython = get_ipython(), ipython.magic("load_ext autoreload"), ipython.magic("autoreload 2")

IPython Console Bug

All 3 comments

@dalthviz, please take a look at this one. We have to find a way to prevent saving strings with % in our config system (i.e. in spyder.ini).

I had to add some special code around spyder/plugins/variableexplorer.py:110 to remove the % at the start of a format string, so that code can probably be streamlined after this is fixed.

Thanks @jitseniesen!

Was this page helpful?
0 / 5 - 0 ratings