Jupyter + R + Windows 编码错误

Jupyter + R + Windows encoding error

我正在尝试让 Jupyter 运行 在 Windows 上安装 R 内核。 Jupyter 在 iPython 内核下运行良好:打开 ipython notebook,我可以正确地创建一个新的 > notebooks > Python 2 和 运行 代码。

现在,当我尝试创建一个新的 > notebooks > R 时,笔记本会按预期打开,但我无法 运行 代码。内核似乎从一开始就很忙,并一直停留在这种状态。

在 shell 上,ipython notebook 表示如下:

[I 16:57:16.128 NotebookApp] Using MathJax from CDN: https://cdn.mathjax.org/mat
hjax/latest/MathJax.js
[I 16:57:16.158 NotebookApp] The port 8888 is already in use, trying another ran
dom port.
[I 16:57:16.158 NotebookApp] Serving notebooks from local directory: C:\Anaconda
\pkgs
[I 16:57:16.158 NotebookApp] 0 active kernels
[I 16:57:16.158 NotebookApp] The IPython Notebook is running at: http://localhos
t:8889/
[I 16:57:16.158 NotebookApp] Use Control-C to stop this server and shut down all
 kernels (twice to skip confirmation).
[I 16:57:23.400 NotebookApp] Creating new notebook in
[E 16:57:24.395 NotebookApp] Unhandled error in API request
    Traceback (most recent call last):
      File "C:\Anaconda\lib\site-packages\IPython\html\base\handlers.py", line 3
94, in wrapper
        result = yield gen.maybe_future(method(self, *args, **kwargs))
      File "C:\Anaconda\lib\site-packages\IPython\html\services\sessions\handler
s.py", line 53, in post
        model = sm.create_session(path=path, kernel_name=kernel_name)
      File "C:\Anaconda\lib\site-packages\IPython\html\services\sessions\session
manager.py", line 66, in create_session
        kernel_name=kernel_name)
      File "C:\Anaconda\lib\site-packages\IPython\html\services\kernels\kernelma
nager.py", line 84, in start_kernel
        kernel_name=kernel_name, **kwargs)
      File "C:\Anaconda\lib\site-packages\IPython\kernel\multikernelmanager.py",
 line 112, in start_kernel
        km.start_kernel(**kwargs)
      File "C:\Anaconda\lib\site-packages\IPython\kernel\manager.py", line 240,
in start_kernel
        **kw)
      File "C:\Anaconda\lib\site-packages\IPython\kernel\manager.py", line 189,
in _launch_kernel
        return launch_kernel(kernel_cmd, **kw)
      File "C:\Anaconda\lib\site-packages\IPython\kernel\launcher.py", line 202,
 in launch_kernel
        proc = Popen(cmd, **kwargs)
      File "C:\Anaconda\lib\subprocess.py", line 710, in __init__
        errread, errwrite)
      File "C:\Anaconda\lib\subprocess.py", line 958, in _execute_child
        startupinfo)
    'WindowsError: [Error 2] Le fichier sp\xe9cifi\xe9 est introuvable'
[E 16:57:24.410 NotebookApp] Uncaught exception POST /api/sessions (::1)
    HTTPServerRequest(protocol='http', host='localhost:8889', method='POST', uri
='/api/sessions', version='HTTP/1.1', remote_ip='::1', headers={'Content-Length'
: '71', 'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encodi
ng': 'gzip, deflate', 'Host': 'localhost:8889', 'Accept': 'application/json, tex
t/javascript, */*; q=0.01', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; r
v:40.0) Gecko/20100101 Firefox/40.0', 'Connection': 'keep-alive', 'X-Requested-W
ith': 'XMLHttpRequest', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'Refe
rer': 'http://localhost:8889/notebooks/Untitled.ipynb?kernel_name=ir', 'Content-
Type': 'application/json; charset=UTF-8'})
    Traceback (most recent call last):
      File "C:\Anaconda\lib\site-packages\tornado\web.py", line 1415, in _execut
e
        result = yield result
      File "C:\Anaconda\lib\site-packages\tornado\gen.py", line 870, in run
        value = future.result()
      File "C:\Anaconda\lib\site-packages\tornado\concurrent.py", line 215, in r
esult
        raise_exc_info(self._exc_info)
      File "C:\Anaconda\lib\site-packages\tornado\gen.py", line 230, in wrapper
        yielded = next(result)
      File "C:\Anaconda\lib\site-packages\IPython\html\base\handlers.py", line 4
12, in wrapper
        self.finish(json.dumps(reply))
      File "C:\Anaconda\lib\json\__init__.py", line 243, in dumps
        return _default_encoder.encode(obj)
      File "C:\Anaconda\lib\json\encoder.py", line 207, in encode
        chunks = self.iterencode(o, _one_shot=True)
      File "C:\Anaconda\lib\json\encoder.py", line 270, in iterencode
        return _iterencode(o, 0)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 1360: in
valid continuation byte
[E 16:57:24.431 NotebookApp] {
      "Content-Length": "71",
      "Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
      "Accept-Encoding": "gzip, deflate",
      "Connection": "keep-alive",
      "Accept": "application/json, text/javascript, */*; q=0.01",
      "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101
 Firefox/40.0",
      "Host": "localhost:8889",
      "X-Requested-With": "XMLHttpRequest",
      "Pragma": "no-cache",
      "Cache-Control": "no-cache",
      "Referer": "http://localhost:8889/notebooks/Untitled.ipynb?kernel_name=ir"
,
      "Content-Type": "application/json; charset=UTF-8"
    }
[E 16:57:24.437 NotebookApp] 500 POST /api/sessions (::1) 74.00ms referer=http:/
/localhost:8889/notebooks/Untitled.ipynb?kernel_name=ir

Unhandled error in API request 开始的错误不会出现在 Python 内核中。

我认为存在编码问题,但我看不出具体位置。我试图通过添加 Sys.setlocale(category = "LC_ALL", locale = "French_France.1252") 来修改我的 .Rprofile 以使 R 使用 UTF-8 编码,但它没有帮助。

我的配置: - Windows 7
- iPython(包括笔记本)和 Anaconda 版本 3.2.0
- R 3.2.1。我按照 irkernel's github repo.
的说明进行操作 - 既不适用于 IE 也不适用于 Firefox

有人在 IRkernel 的 repo 上回答了我的问题。由于 IRkernel 中的某些错误,Jupyter 似乎无法找到 R。可以在 IRkernel 的 github 项目的主分支上找到 IRkernel 的固定版本(有关过程,请参阅 here)。

请注意,根据您的配置,执行 IRkernel::installspec(user = FALSE) 而不是 IRkernel::installspec() 可能会有所帮助。