如何在Jupyter Notebook中安装各种编程语言

如何在Jupyter Notebook中使用各种编程语言

  • 1. Jupyter Notebook 简介
  • 2. Jupyter Notebook的安装
    • 2.1 基本内核安装&安装python插件
    • 2.2 安装Julia插件
    • 2.3 安装R语言插件
    • 2.4 安装iTorch插件
  • 参考

1. Jupyter Notebook 简介

Jupyter Notebook是基于网页的用于交互计算的应用程序。其可被应用于全过程计算:开发、文档编写、运行代码和展示结果。详细的内容可以查看jyputer的官方文档。它主要有两部分组成,第一部分是网页应用的组成部分,一部分是文档。网页应用就是基于网页形式的、结合编写说明文档、数学公式、交互计算和其他形式的工具。文档即输出的所有交互式计算、编写说明文档、数学公式、图片以及其他形式的输入和输出,一文档来体现的。文档一般保存为ipynb或者是json格式的文件。jyputer notebook 主要有以下的几个特点:

  • 编程时具有语法高亮、缩进、tab补全的功能。
  • 可直接通过浏览器运行代码,同时在代码块下方展示运行结果。
  • 以富媒体格式展示计算结果。富媒体格式包括:HTML,LaTeX,PNG,SVG等。
  • 对代码编写说明文档或语句时,支持Markdown语法。
  • 支持使用LaTeX编写数学性说明。

也可以在线体验Jupyter Notebook 的使用,这里是在线文档编辑,可以试用。

2. Jupyter Notebook的安装

2.1 基本内核安装&安装python插件

安装前提条件是有python3.3或者是python2.7以上的环境。
可以使用Anaconda安装:

conda install jyputer notebook

也可以使用pip安装:

pip install jyputer notebook

在安装过程中会有一些不兼容的现象,因为老版本的pip在安装Jupyter Notebook过程中或面临依赖项无法同步安装的问题。因此强烈建议先把pip升级到最新版本。
pip 3.x 版本

pip3 install --upgrade pip

pip 2.x版本

pip install --upgrade pip

安装完成之后,输入命令

jupyter notebook

它将会启动服务并打开浏览器
如何在Jupyter Notebook中安装各种编程语言_第1张图片即安装成功

2.2 安装Julia插件

进入Julia终端
如何在Jupyter Notebook中安装各种编程语言_第2张图片在Julia交互式终端输入以下命令,即可以安装成功

using Pkg
Pkg.add("IJulia")

如何在Jupyter Notebook中安装各种编程语言_第3张图片

2.3 安装R语言插件

这个有两种方法,一种是基于conda安装,在终端直接输入以下命令

conda install -c r r-essentials

这样就可以安装了。另外一种是基于R交互式终端进行安装。打开R交互式终端,并输入以下的命令

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))# 安装需要的基础包
devtools::install_github('IRkernel/IRkernel')#安装IRkernel包
IRkernel::installspec(user = FALSE)

其中参数user表示安装到哪个位置,TRUE表示安装到当前用户下,FALSE表示安装到系统下。
在之后的博客中笔者会逐一介绍Jupyter Notebook 的使用方法。

2.4 安装iTorch插件

iTorch插件是lua语言中深度学习库torch使用的交互性jupyter notebook 平台。首先需要安装以下文件

sudo apt-get install openssl libssl-dev #ubuntu 系统
sudo yum install openssl-devel -y #Centos 系统

然后需要安装的是lua中一些基础库文件,使用luarocks工具进行安装

luarocks install lzmq uuid lbase64 luacrypto

luarocks 在安装过程中会出现raw.githubusercontent.com网址无法访问导致无法安装,可以参考笔者这篇博文无法连接github部分网址
然后就是安装itorch,可以从源码进行安装,也可以使用luarocks工具进行安装:
方法一:
方法二:

luarocks install itorch

存在的问题
在安装luacrypto可能会出现libssl库找不到或者是其他libcrypto库找不到,要安装以下库文件即可以解决

sudo apt install libssl-dev openssl

但是笔者安装过程中最后出现了这样的一个编译过程中遇到的问题,不论是用源码luarocks make安装luacrypto还是用luarocks install 进行安装都会出现这样的一个问题:

Installing https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luacrypto-0.3.2-2.src.rock...
Using https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luacrypto-0.3.2-2.src.rock... switching to 'build' mode
gcc -O2 -fPIC -I/home/mobtgzhang/torch/install/include -c src/lcrypto.c -o src/lcrypto.o -I/usr/include
src/lcrypto.c: In function ‘digest_pnew’:
src/lcrypto.c:81:61: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_MD_CTX {aka struct evp_md_ctx_st}’
     EVP_MD_CTX *c = (EVP_MD_CTX *)lua_newuserdata(L, sizeof(EVP_MD_CTX));
                                                             ^~~~~~~~~~
src/lcrypto.c: In function ‘digest_reset’:
src/lcrypto.c:120:10: warning: implicit declaration of function ‘EVP_MD_CTX_cleanup’; did you mean ‘EVP_MD_CTX_create’? [-Wimplicit-function-declaration]
     if (!EVP_MD_CTX_cleanup(c))
          ^~~~~~~~~~~~~~~~~~
          EVP_MD_CTX_create
src/lcrypto.c: In function ‘encrypt_pnew’:
src/lcrypto.c:331:69: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
     EVP_CIPHER_CTX *c = (EVP_CIPHER_CTX *)lua_newuserdata(L, sizeof(EVP_CIPHER_CTX));
                                                                     ^~~~~~~~~~~~~~
src/lcrypto.c: In function ‘encrypt_fencrypt’:
src/lcrypto.c:425:20: error: storage size of ‘c’ isn’t known
     EVP_CIPHER_CTX c;
                    ^
src/lcrypto.c: In function ‘decrypt_pnew’:
src/lcrypto.c:470:69: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
     EVP_CIPHER_CTX *c = (EVP_CIPHER_CTX *)lua_newuserdata(L, sizeof(EVP_CIPHER_CTX));
                                                                     ^~~~~~~~~~~~~~
src/lcrypto.c: In function ‘decrypt_fdecrypt’:
src/lcrypto.c:561:20: error: storage size of ‘c’ isn’t known
     EVP_CIPHER_CTX c;
                    ^
src/lcrypto.c: In function ‘hmac_pnew’:
src/lcrypto.c:604:57: error: invalid application of ‘sizeof’ to incomplete type ‘HMAC_CTX {aka struct hmac_ctx_st}’
     HMAC_CTX *c = (HMAC_CTX *)lua_newuserdata(L, sizeof(HMAC_CTX));
                                                         ^~~~~~~~
src/lcrypto.c: In function ‘hmac_fnew’:
src/lcrypto.c:621:5: warning: implicit declaration of function ‘HMAC_CTX_init’; did you mean ‘HMAC_CTX_new’? [-Wimplicit-function-declaration]
     HMAC_CTX_init(c);
     ^~~~~~~~~~~~~
     HMAC_CTX_new
src/lcrypto.c: In function ‘hmac_clone’:
src/lcrypto.c:631:5: error: dereferencing pointer to incomplete type ‘HMAC_CTX {aka struct hmac_ctx_st}’
     *d = *c;
     ^~
src/lcrypto.c: In function ‘hmac_gc’:
src/lcrypto.c:697:5: warning: implicit declaration of function ‘HMAC_CTX_cleanup’; did you mean ‘HMAC_CTX_get_md’? [-Wimplicit-function-declaration]
     HMAC_CTX_cleanup(c);
     ^~~~~~~~~~~~~~~~
     HMAC_CTX_get_md
src/lcrypto.c: In function ‘hmac_fdigest’:
src/lcrypto.c:711:14: error: storage size of ‘c’ isn’t known
     HMAC_CTX c;
              ^
src/lcrypto.c: In function ‘sign_pnew’:
src/lcrypto.c:747:61: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_MD_CTX {aka struct evp_md_ctx_st}’
     EVP_MD_CTX *c = (EVP_MD_CTX *)lua_newuserdata(L, sizeof(EVP_MD_CTX));
                                                             ^~~~~~~~~~
src/lcrypto.c: In function ‘sign_fsign’:
src/lcrypto.c:828:20: error: storage size of ‘c’ isn’t known
         EVP_MD_CTX c;
                    ^
src/lcrypto.c: In function ‘verify_pnew’:
src/lcrypto.c:857:61: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_MD_CTX {aka struct evp_md_ctx_st}’
     EVP_MD_CTX *c = (EVP_MD_CTX *)lua_newuserdata(L, sizeof(EVP_MD_CTX));
                                                             ^~~~~~~~~~
src/lcrypto.c: In function ‘verify_fverify’:
src/lcrypto.c:940:20: error: storage size of ‘c’ isn’t known
         EVP_MD_CTX c;
                    ^
src/lcrypto.c: In function ‘rand_pseudo_bytes’:
src/lcrypto.c:992:5: warning: ‘RAND_pseudo_bytes’ is deprecated [-Wdeprecated-declarations]
     return rand_do_bytes(L, RAND_pseudo_bytes);
     ^~~~~~
In file included from /usr/include/openssl/e_os2.h:13:0,
                 from /usr/include/openssl/err.h:13,
                 from src/lcrypto.c:7:
/usr/include/openssl/rand.h:44:1: note: declared here
 DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num))
 ^
src/lcrypto.c: In function ‘pkey_generate’:
src/lcrypto.c:1064:9: warning: ‘RSA_generate_key’ is deprecated [-Wdeprecated-declarations]
         RSA *rsa = RSA_generate_key(key_len, RSA_F4, NULL, NULL);
         ^~~
In file included from /usr/include/openssl/e_os2.h:13:0,
                 from /usr/include/openssl/err.h:13,
                 from src/lcrypto.c:7:
/usr/include/openssl/rsa.h:234:1: note: declared here
 DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void
 ^
src/lcrypto.c:1074:9: warning: ‘DSA_generate_parameters’ is deprecated [-Wdeprecated-declarations]
         DSA *dsa = DSA_generate_parameters(key_len, NULL, 0, NULL, NULL, NULL, NULL);
         ^~~
In file included from /usr/include/openssl/e_os2.h:13:0,
                 from /usr/include/openssl/err.h:13,
                 from src/lcrypto.c:7:
/usr/include/openssl/dsa.h:117:1: note: declared here
 DEPRECATEDIN_0_9_8(DSA *DSA_generate_parameters(int bits,
 ^
src/lcrypto.c: In function ‘pkey_to_pem’:
src/lcrypto.c:1164:27: error: dereferencing pointer to incomplete type ‘struct evp_pkey_st’
     if (private && pkey_st->type == EVP_PKEY_DSA)
                           ^~
src/lcrypto.c: In function ‘pkey_tostring’:
src/lcrypto.c:1277:60: error: dereferencing pointer to incomplete type ‘EVP_PKEY {aka struct evp_pkey_st}’
     sprintf(buf, "%s %s %d %p", LUACRYPTO_PKEYNAME, (*pkey)->type == EVP_PKEY_DSA ? "DSA" : "RSA", EVP_PKEY_bits(*pkey), pkey);
                                                            ^~
src/lcrypto.c: In function ‘seal_pnew’:
src/lcrypto.c:1299:46: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
     c->ctx = (EVP_CIPHER_CTX *)malloc(sizeof(EVP_CIPHER_CTX));
                                              ^~~~~~~~~~~~~~
In file included from src/lcrypto.c:8:0:
src/lcrypto.c: In function ‘seal_tostring’:
src/lcrypto.c:1320:81: error: dereferencing pointer to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
     sprintf(s, "%s %p %s", LUACRYPTO_SEALNAME, (void *)c, EVP_CIPHER_name(c->ctx->cipher));
                                                                                 ^
src/lcrypto.c: In function ‘seal_fseal’:
src/lcrypto.c:1400:20: error: storage size of ‘ctx’ isn’t known
     EVP_CIPHER_CTX ctx;
                    ^~~
src/lcrypto.c: In function ‘open_pnew’:
src/lcrypto.c:1483:46: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}’
     c->ctx = (EVP_CIPHER_CTX *)malloc(sizeof(EVP_CIPHER_CTX));
                                              ^~~~~~~~~~~~~~
src/lcrypto.c: In function ‘open_fopen’:
src/lcrypto.c:1602:20: error: storage size of ‘ctx’ isn’t known
     EVP_CIPHER_CTX ctx;
                    ^~~

Error: Build error: Failed compiling object src/lcrypto.o

这个原因主要是因为openssl库中的一些库比较新,luarocks源上提供的luacrypto是一个旧版本,并不能很好使用openssl库文件。luacrypto官方网址上并没有在github上说明luacrypto太详细的信息。经过查找,找到另外一个luacrypto项目的github,地址在这里,发现README.MD上有这样的一句话

this project is deprecated, use luaossl

于是笔者安装了luaossl。安装过程也是很艰辛,系统中一直都在提示无法找到libcrypto.so等等文件以及libssl.so文件,但是这些依赖库已经安装成功。最后发现,luaossl项目安装的时候,是将lib库定向到了/usr/lib,但是依赖库实际上是在/usr/lib/x86_64-linux-gnu/,所以这里建立了两个软件链接:

sudo ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/libssl.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libcrypto.so /usr/lib/libssl.so

然后进行安装luaossl

luarocks install luaossl

但是再进行安装itorch库时候,仍然缺少luacrypto库,编译过程仍旧出现同样的错误。最后使用luarocks search命令查找到了luacrypto2库文件,然后进行安装

luarocks install luacrypto2

再进行安装的时候,依旧出现相同的问题,缺少luacrypto库。于是决定使用源码进行安装。

git clone https://github.com/facebook/iTorch.git
cd iTorch

为了防止再次出现luacrypto依赖库问题,将源码中的安装文件iTorch/itorch-scm-1.rockspec
中的一个依赖项进行改正:
如何在Jupyter Notebook中安装各种编程语言_第4张图片

改正为
如何在Jupyter Notebook中安装各种编程语言_第5张图片

然后进行编译安装

luarocks make 

成功安装。在终端启动itorch notebook的时候并不能启动

Unsupported ipython version. Only major versions 2.xx, 3.xx, 4.xx or 5.xx (Jupyter) are supported

不过在启动jupyter notebook之后,可以新建lua文件:
如何在Jupyter Notebook中安装各种编程语言_第6张图片测试
如何在Jupyter Notebook中安装各种编程语言_第7张图片可见已经成功安装itorch

参考

[1] Jupyter Notebook介绍、安装及使用教程

你可能感兴趣的:(系统安装教程)