IPython errors pop up while building the docs
#### Command

```
(pandas) root@XXXXX:/mnt/e/ProgrammingProjects/pandas/doc# python3 make.py latex
Running Sphinx v1.8.1
/root/miniconda3/envs/pandas/lib/python3.6/site-packages/sphinx/application.py:402: RemovedInSphinx20Warning: app.info() is now deprecated. Use sphinx.util.logging instead.
  RemovedInSphinx20Warning)
Initializing Spelling Checker
[autosummary] generating autosummary for: 10min.rst, advanced.rst, api.rst, basics.rst, categorical.rst, comparison_with_r.rst, comparison_with_sas.rst, comparison_with_sql.rst, comparison_with_stata.rst, computation.rst, ..., r_interface.rst, release.rst, reshaping.rst, sparse.rst, text.rst, timedeltas.rst, timeseries.rst, tutorials.rst, visualization.rst, whatsnew.rst
loading intersphinx inventory from http://www.statsmodels.org/devel/objects.inv...
loading intersphinx inventory from http://matplotlib.org/objects.inv...
intersphinx inventory has moved: http://matplotlib.org/objects.inv -> https://matplotlib.org/objects.inv
loading intersphinx inventory from https://pandas-gbq.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://docs.scipy.org/doc/numpy/objects.inv...
loading intersphinx inventory from https://docs.scipy.org/doc/scipy/reference/objects.inv...
loading intersphinx inventory from https://pylib.readthedocs.io/en/latest/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [latex]: all documents
updating environment: 1529 added, 0 changed, 0 removed
reading sources... [  0%] cookbook

>>>-------------------------------------------------------------------------
Exception in /mnt/e/ProgrammingProjects/pandas/doc/source/cookbook.rst at block ending on line 485
Specify :okexcept: as an option in the ipython:: block to suppress this message
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-88-f383d2261d3f> in <module>
----> 1 avg_weight += sum(x[x['size'] == 'M'].weight * 1.25)

NameError: name 'avg_weight' is not defined
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-89-f72d4d450698> in <module>
----> 1 avg_weight += sum(x[x['size'] == 'L'].weight)

NameError: name 'avg_weight' is not defined
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-90-ec76bd1aa2cb> in <module>
----> 1 avg_weight /= len(x)

NameError: name 'avg_weight' is not defined
  File "<ipython-input-91-204b3859f54f>", line 1
    return pd.Series(['L',avg_weight,True], index=['size', 'weight', 'adult'])
                                                                              ^
SyntaxError: 'return' outside function

<<<-------------------------------------------------------------------------


Exception occurred:
  File "/root/miniconda3/envs/pandas/lib/python3.6/site-packages/IPython/sphinxext/ipython_directive.py", line 567, in process_input
    raise RuntimeError('Non Expected exception in `{}` line {}'.format(filename, lineno))
RuntimeError: Non Expected exception in `/mnt/e/ProgrammingProjects/pandas/doc/source/cookbook.rst` line 485
The full traceback has been saved in /tmp/sphinx-err-m5m3114c.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** No targets specified and no makefile found.  Stop.
(pandas) root@XXXXX:/mnt/e/ProgrammingProjects/pandas/doc#
```
#### Problem description

I thought that way I could build the docs with just the steps described at https://pandas.pydata.org/pandas-docs/stable/contributing.html#requirements. I use Linux-as-a-Subsystem on a Windows machine. The C code I successfully installed.

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-17134-Microsoft
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.0.dev0+780.g145c227.dirty
pytest: 3.8.2
pip: 18.1
setuptools: 40.4.3
Cython: 0.29
numpy: 1.15.2
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.0.1
sphinx: 1.8.1
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: 1.5.1
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.0
openpyxl: 2.5.5
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.1
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.12
pymysql: 0.9.2
psycopg2: None
jinja2: 2.10
s3fs: 0.1.6
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: 0.1.2

</details>
