Python development on Ubuntu on AWS EC2 (using JupyterLab)

Overview

I had the opportunity to use EC2 in my research, so I will write down what I did at that time. I hope it will help people who develop Python on EC2 from now on.

The execution environment is Mac Catalina. (Addition: Even on Windows, the environment could be built by doing the same with Git Bash.)

Step.1 Creating an instance

I used ubuntu 18.04 LST which can be used for free tier. There is an image provided by nvidia, but I tried it there and it didn't work, so I made it from scratch.

スクリーンショット 2020-10-06 15.52.21.png

The instance type can be a free tier. You don't have to pay a high fee while building the environment. If you want to calculate the heavy load later, change it at that time.

I haven't made any other settings, so it's OK to proceed with "Confirmation and Creation".

Please check the creation of pem file separately. I'm sorry for being unfriendly. After that, we will proceed on the assumption that the pem file has been created.

Step.2 Connect to your instance

If the created instance is running and the status check passes the 2/2 check, try connecting to the instance. Then, EC2 Instance Connect / Session Manager / SSH Client I think you will jump to the page with the tab. Open the tab for that SSH client.

Also, in the terminal, move to the directory where the pem file is located. And in the SSH client tab, After executing the command starting with chmod, Execute a command like ssi -i "~~~ .pem" ubuntu @. You should be able to connect to the created instance.

スクリーンショット 2020-10-07 14.58.12.png ↑ This is the screen

Step.3 Install Jupyter Lab

Execute the following code on the created instance.

sudo apt update
sudo apt upgrade
sudo apt install -y software-properties-common
sudo apt-add-repository -y ppa:git-core/ppa
sudo apt install -y git
sudo apt install -y python3-pip
sudo pip3 install --upgrade pip
sudo pip3 install jupyterlab
sudo pip3 install ipywidgets
jupyter nbextension enable --py widgetsnbextension

You have now installed jupyterLab on the instance you just created.

Step.4 Connect to Jupyter Lab

If you can do this, stop the instance once, and if you can confirm the stop, start it again.

If the check is passed as in Step.1, connect with the SSH client as before, but add "-L 8889: 127.0.0.1:8889" to the command.

ssh -i "***.pem" -L 8889:127.0.0.1:8889 ubuntu@ec2-***-***-***-***.*********.compute.amazonaws.com

After connecting, execute the following command on the instance to start jupyterLab.

jupyter-lab --ip=0.0.0.0 --port=8889 --no-browser --allow-root --NotebookApp.token=''

If you don't get any errors, in your browser

127.0.0.1:8889

Try connecting to. I think that you can connect to the jupyterLab running on the launched instance.

Finally

I hope there are no errors. After that, I installed packages such as tensorflow, but there are various problems ... Currently, that problem has been solved, so I think it will be helpful if you ask at ↓. (In some cases, I will write it as a separate article) Thank you for reading.

Referenced articles etc. (Thank you !!)

Operate the jupyter notebook on the SSH destination server on the local PC https://sishida21.github.io/2019/12/12/remote-jupyter-notebook/

[Explanation with image] Create Anaconda environment with Docker and use VS Code in the container https://qiita.com/komiya_____/items/96c14485eb035701e218

I built the environment by referring to the dockerfile I created a long time ago, so there must be other articles that I referred to at that time ... but I can't remember ... I'm sorry.

Recommended Posts

Python development on Ubuntu on AWS EC2 (using JupyterLab)
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Prepare Python development environment on Ubuntu
Introducing Python using pyenv on Ubuntu 20.04
Preparing python using vscode on ubuntu
Until building a Python development environment using pyenv on Ubuntu 20.04
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
[2020 version] How to install Python3 on AWS EC2
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
build Python on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Check types_map when using mimetypes on AWS Lambda (Python)
Execute python3 system with PHP exec () on AWS EC2
Troublesome story when using Python3 with VScode on ubuntu
Build a Python development environment using pyenv on MacOS
Set up Python 3.4 on Ubuntu
Python + Kivy development on Windows
Put Python 3.x on Ubuntu
Install OpenCV on Ubuntu + python
Python --Install MySQLDB on EC2
Introducing TensorFlow on Ubuntu + Python 2.7
Broadcast on LINE using python
Build an Ubuntu python development environment on Google Cloud Platform
Building an environment to execute python programs on AWS EC2
Install Python 3.8 on Ubuntu 18.04 (OS standard)
[Ubuntu] [Python] Object tracking using dlib
Summary if using AWS Lambda (Python)
Building a Python environment on Ubuntu
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Run Python on Schedule on AWS Lambda
Python development environment construction on macOS
Study on Tokyo Rent Using Python (3-2)
Notes on installing Python using PyEnv
Using a serial console on Ubuntu 20.04
Notes on using rstrip with python.
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install Python development environment on Windows 10
Install Python on CentOS using Pyenv
Install confluent-kafka for Python on Ubuntu
Study on Tokyo Rent Using Python (3-3)
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Run Yocto on Ubuntu using QEMU.
Install Python on CentOS using pyenv
OpenCV3 & Python3 environment construction on Ubuntu
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
Create an AWS Cloud9 development environment on your Amazon EC2 instance
Things to note when running Python on EC2 from AWS Lambda
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Notes for using OpenCV on Windows10 Python 3.8.3.
Python development environment for macOS using venv 2016
Execute Python code on C ++ (using Boost.Python)
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
[Ubuntu] [Python] Facial organ detection using dlib
Install python library on Lambda using [/ tmp]
Steps to install Python environment on Ubuntu
Created Ubuntu, Python, OpenCV environment on Docker
Modules cannot be imported in Python on EC2 run from AWS Lambda
Run servomotor on Raspberry Pi 3 using python
[Python] Run Headless Chrome on AWS Lambda