Skip to content

Instantly share code, notes, and snippets.

@felixmon
Last active September 15, 2020 08:03
Show Gist options
  • Save felixmon/54fa66d7fa5fe9bb0436f528af025327 to your computer and use it in GitHub Desktop.
Save felixmon/54fa66d7fa5fe9bb0436f528af025327 to your computer and use it in GitHub Desktop.
Install Jupyter on Windows (errors)

Install Jupyter on Windows 10

1. Requirements

  1. Windows 10 64 bit
  2. Python 3.x 64 bit or errors will occour when installing pywinpty
  3. MS Visual Studio Build Tools (for c++ compiler)

2. Steps

  1. Set Python and Python/Scripts paths to system path (reboot required).
  2. pip install pywinpty
  3. pip install notebook
  4. pip install jupyterlab

3. Change languages

Jupyter automatically starts with local languages, to stick with English:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

or on Windows CMD:

set LC_ALL=en_US.UTF-8
set LANG=en_US.UTF-8

4. 32 bit Python version errors

If you are running Python 32 bit versions, errors will occor:

pip install pywinpty

error running the above command

Cannot open include file: 'winpty.h': No such file or directory error

anwser: https://www.kannon.link/free/2018/09/19/installing-jupyter-on-python-3-7-on-windows/

down load and unzip one of the binary releases of winpty from winpty 0.4.3.
copy the following files to the appropriate folders, which your paths include.

  • include/winpty.h, winpty_constants.h
  • x64/lib/winpty.lib
  • x64/bin/winpty.dll
  • retry "pip install jupyter".

anwser: andfoy/pywinpty#123

5. Export to PDF in Chinese

Jupyter use the LaTeX engine, XeLaTeX to be specifc, and Pandoc to generate PDF format, so correct configurations for XeLaTeX and MiKTeX is important.
Reference

5.1 Prerequisites

  1. Install Pandoc.
  2. Install XeLaTeX(already installed with basic features after Jupyter installation).
  3. Install MiKTeX.

5.2 Use the command line first

Use the command line to generate PDF format first to make sure everything is okay.

5.2.1 To Latex

Generate a latex file from your Jupyter notebook file.

jupyter nbconvert --to latex yourfile.ipynb

return: yourfile.tex

5.2.2 XeLaTeX upgrade

Convert it PDF with XeLaTeX

xelatex youfile.tex

There are about over 100 packages that XeLaTeX would automatically install, just wait till it finish. The "file too old" error might occur, just type "R" to continue without it.

5.2.3 MiKTeX upgrade

Run MiKTeX console as a Administrator or sudo, press "check for update", wait till it finish.

5.3 base.tplx

In order to display Chinese properly, you need to add some codes to the file base.tplx which is a package of XeLaTeX:

  1. Get the site-package directory of Python:
import site
site.getsitepackages()
  1. Go to that directory
cd %python-site-package-directory%/nbconvert/templages/latex
nano base.tplx

find ((* block packages *)), then add the following codes:

    \usepackage{fontspec, xunicode, xltxtra}
    \setmainfont{Microsoft YaHei}
    \usepackage{ctex}

note that there're four spaces for the indent, not tabs.

And now run jupyter nbconvert --to pdf yourfile.ipynb and it should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment