자바스크립트를 활성화 해주세요

d022 Goormide, Jupyterlab, Dotnet Interactive를 설치해 봤습니다

 ·  ☕ 5 min read

Tyler Leonhardt 라는 분의 트윗을 통해 알게되어, 최근 dotnet-interactive라는 것에 관심을 가지게 되었습니다.

twitter에서 #dotnetinteractive 라는 태그를 사용해 보면, 훨씬 많은 정보를 만나볼 수 있습니다.

이 dotnet-interactive는 jupyter에서도 사용할 수 있고 vscode에서도 사용할 수 있는 것 같습니다만, 제 개발환경의 vscode 설정을 변경하면 현재 진행하고 있는 프로젝트에 영향이 발생해 곤란해지기 때문에, goormide의 jupyterlab에 설치해서 살펴보았습니다.

goormide container

우선 goormide에 컨테이너를 작성합니다.

그냥 empty 프로젝트를 사용해도 되지만, 이쪽은 베이스가 되는 python이 python2이므로 jupyter 프로젝트를 사용한 컨테이너를 만듭니다.

starship

간단히, 그리고 재빠르게 startship 프롬프트를 설치합니다.

취향입니다. 무시하셔도 됩니다.

curl -fsSL https://starship.rs/install.sh | bash
echo 'eval "$(starship init bash)"' >> ~/.bashrc
eval "$(starship init bash)"

package repository

닷넷 코어를 설치하기 위해 다음의 명령을 실행합니다. 다음의 문서에도 기재되어 있습니다.

https://docs.microsoft.com/ko-kr/dotnet/core/install/linux-ubuntu#1804-

1
2
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

dotnet core

SDK를 설치합니다. .NET Core SDK를 설치하면 해당 런타임을 설치할 필요가 없습니다.

1
2
3
4
sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-3.1

이제는 dotnet 커맨드를 사용할 수 있습니다.

.NET Interactive

다음은 jupyter용 커널을 설치합니다. 참조하는 문서는 이쪽입니다.

https://github.com/dotnet/interactive/blob/main/docs/NotebooksLocalExperience.md

먼저 어떤 커널이 설치되어 있는 지 확인해 봅니다.

jupyter kernelspec list

1
2
3
❯ jupyter kernelspec list
Available kernels:
  python3    /usr/local/share/jupyter/kernels/python3

아직 설치되어 있지 않네요.

dotnet tool install -g --add-source "https://dotnet.myget.org/F/dotnet-try/api/v3/index.json" Microsoft.dotnet-interactive

실행하면 다음과 같이 한글로 된 메시지도 보여줍니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
❯ dotnet tool install -g --add-source "https://dotnet.myget.org/F/dotnet-try/api/v3/index.json" Microsoft.dotnet-interactive

.NET Core 3.1을() 시작합니다.
---------------------
SDK 버전: 3.1.401

원격 분석
---------
.NET Core 도구는 사용자 환경 개선을 위해 사용량 현황 데이터를 수집합니다. 데이터는 익명입니다. Microsoft에서 데이터를 수집하여 커뮤니티와 공유합니다
. 원하는 셸에서 DOTNET_CLI_TELEMETRY_OPTOUT 환경 변수를 '1' 또는 'true'로 설정하여 원격 분석을 옵트아웃할 수 있습니다.

.NET Core CLI 도구 원격 분석에 대한 자세한 내용은 https://aka.ms/dotnet-cli-telemetry를 참조하세요.

----------------
설명서 살펴보기: https://aka.ms/dotnet-docs
GitHub에서 문제 보고 및 소스 찾기: https://github.com/dotnet/core
새로운 기능 확인: https://aka.ms/dotnet-whats-new
설치된 HTTPS 개발자 인증서에 대해 알아보기: https://aka.ms/aspnet-core-https
사용 가능한 명령을 확인하려면 'dotnet --help' 사용 또는 다음 방문: https://aka.ms/dotnet-cli-docs
첫 번째 앱 작성: https://aka.ms/first-net-core-app
-------------------------------------------------------------------------------------- 
.NET Core SDK를 방금 설치했기 때문에 설치한 도구를 실행하기 전에 로그아웃하거나 세션을 다시 시작해야 합니다.
다음 명령을 사용하여 도구를 호출할 수 있습니다. dotnet-interactive
'microsoft.dotnet-interactive' 도구('1.0.145402' 버전)가 설치되었습니다.

root on goorm in ~ took 37s

jupyter 커널을 설치하기 위해서 다음의 명령을 실행하라고 설명하고 있지만,

dotnet interactive jupyter install

정상적으로 실행되지 않습니다.

1
2
3
4
5
6
7
root on goorm in ~
❯ dotnet interactive jupyter install
지정된 명령 또는 파일을 찾을 수 없으므로 실행할 수 없습니다.
가능한 원인은 다음과 같습니다.
  * 기본 제공 dotnet 명령 철자가 잘못 입력되었습니다.
  * .NET Core 프로그램을 실행하려고 했지만, dotnet-interactive이() 없습니다.
  * 전역 도구를 실행하려고 했지만, 이 이름의 dotnet 접두사가 있는 실행 파일을 PATH에서 찾을 수 없습니다.

흠.

.NET Core SDK를 방금 설치했기 때문에 설치한 도구를 실행하기 전에 로그아웃하거나 세션을 다시 시작해야 합니다.

이런 메시지가 있어서 컨테이너를 재기동 해봤지만, 다시 실행해도 dotnet-interactive라는 명령이 실행되지 않습니다. 어디에 있는 명령어인지 찾아보았습니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
❯ dotnet-interactive
bash: dotnet-interactive: command not found

root on goorm in ~
❯ cd ~/.dotnet/tools/
.store/             dotnet-interactive

root on goorm in ~
❯ ls ~/.dotnet/tools/dotnet-interactive -la
-rwxr-xr-x 1 root root 90552  9월  5 03:21 /root/.dotnet/tools/dotnet-interactive

흠. 직접 실행해 볼까요?

~/.dotnet/tools/dotnet-interactive jupyter install
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
root on goorm in ~
❯ ~/.dotnet/tools/dotnet-interactive jupyter install

Welcome to .NET Interactive!
---------------------
Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience.The data is anonymous and doesn't include command-line arguments.
 The data is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_TRY_CLI_TELEMETRY_OPTOUT envir
onment variable to '1' or 'true' using your favorite shell.

Installing using jupyter kernelspec module.
Installed ".NET (F#)" kernel.
Installing using jupyter kernelspec module.
Installed ".NET (PowerShell)" kernel.
Installing using jupyter kernelspec module.
Installed ".NET (C#)" kernel.

정상적으로 실행이 됩니다. PATH에 이쪽 경로를 넣어둡니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export PATH=~/.dotnet/tools:$PATH


❯ dotnet interactive
Required command was not provided.

dotnet-interactive:
  Interactive programming for .NET.

Usage:
  dotnet-interactive [options] [command]

Options:
  --log-path <log-path>    Enable file logging to the specified directory
  --verbose                Enable verbose logging to the console
  --version                Show version information
  -?, -h, --help           Show help and usage information

Commands:
  jupyter <connection-file>    Starts dotnet-interactive as a Jupyter kernel
  stdio                        Starts dotnet-interactive with kernel functionality exposed over
                               standard I/O
  http                         Starts dotnet-interactive with kernel functionality exposed over http

네. dotnet interactive라는 명령이 정상적으로 실행되는 것을 확인했습니다.

다음은 jupyter 설정을 합니다.

generate jupyter config

기본적인 config 파일을 만들어 둡니다. 만일 변경하고 싶은 내용이 있으면 옵션으로 넘기는 방법도 있지만, 이쪽을 수정하는 방법도 있습니다.

root on goorm in ~ took 12s
❯ jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

jupyter 어플리케이션을 dry run 해봅니다. 옵션으로 ip와 port를 설정합니다.

jupyter notebook --ip=0.0.0.0 --port=80 --no-browser --allow-root

브라우저에서 잘 실행되는 것을 확인합니다.

d022_goormide_jupyter_dotnet_interactive.png

jupyter password

처음 살행할 때 토큰을 입력해서 사용권한을 확인하는데, 좀 불편하다면 패스워드로 변경해, 브라우저에서 입력하는 방법이 있습니다.

패스워드를 설정하는 방법은 jupyter_notebook_config.py를 사용하는 방법도 있지만, 그냥 jupyter notebook password 명령어를 사용하는 방법도 있습니다.

jupyter notebook password

jupyterlab 설치

pip를 이용하여 jupyterlab을 설치합니다.

pip install jupyterlab
jupyter serverextension enable --py jupyterlab --sys-prefix

실행은 notebook 이라는 키워드 대신에 lab 이라는 키워드를 사용하면 됩니다.

jupyter lab --ip=0.0.0.0 --port=80 --no-browser --allow-root

실행 화면

실행화면은 다음과 같습니다.

d022_goormide_jupyterlab_dotnet_interactive.png

d022_goormide_jupyterlab_dotnet_interactive_csharp.png

한글로 에러메시지도 나오고, 완벽하지 않지만, 인텔리센스의 기능도 사용할 수 있는 것을 확인할 수 있습니다.

d022_goormide_jupyterlab_dotnet_interactive_csharp2.png

샘플은 이쪽을 사용하고 있습니다. 버전이 완전하지 않아서 약간 충돌이 발생하는 것도 확인할 수 있습니다.

https://github.com/dotnet/interactive/tree/main/samples

공부해야 할 것이 늘었네요.

문제

dotnet-interactive를 실행할 때,

❯ jupyter lab --ip=0.0.0.0 --port=80 --no-browser --allow-root
[I 13:59:35.551 LabApp] JupyterLab extension loaded from /usr/local/lib/python3.7/site-packages/jupyterlab
[I 13:59:35.554 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab
[I 13:59:35.567 LabApp] Serving notebooks from local directory: /root
[I 13:59:35.567 LabApp] The Jupyter Notebook is running at:
[I 13:59:35.569 LabApp] http://goorm:80/
[I 13:59:35.570 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 14:00:10.072 LabApp] Kernel started: e7711d54-8c0f-47d4-94a3-583960d1339f
[I 14:00:17.749 LabApp] Saving file at /interactive/samples/notebooks/polyglot/COVID-19.ipynb
Hosting environment: Production
Content root path: /root/.dotnet/tools/.store/microsoft.dotnet-interactive/1.0.145402/microsoft.dotnet-interactive/1.0.145402/tools/netcoreapp3.1/an
y/
Now listening on: http://172.17.0.35:1000
Now listening on: http://127.0.0.1:1000
Application started. Press Ctrl+C to shut down.

csharp kernel이 시작되면 다음과 같이 listening하는 프로세스가 발생합니다

Now listening on: http://172.17.0.35:1000
Now listening on: http://127.0.0.1:1000

process를 보면 다음과 같습니다.

❯ netstat -tulpn | grep 1000
tcp        0      0 127.0.0.1:1000          0.0.0.0:*               LISTEN      759/dotnet-interact
tcp        0      0 172.17.0.35:1000        0.0.0.0:*               LISTEN      759/dotnet-interact

이 아이피를 글로벌(0.0.0.0)으로 실행하는 방법은 아직 탐색중입니다.

그래픽

다음의 예제에서처럼 XPlot 를 사용하면 그래프도 가능한 것 같습니다

https://colab.research.google.com/github/TravisEz13/travisez13/blob/master/_notebooks/2020-05-06-sierpinski.ipynb#scrollTo=GiLIAvbKTMtL

레퍼런스

공유하기

tkim
글쓴이
tkim
Software Engineer