บันทึก / บทความ

การติดตั้ง Python + JupyterLab บน Windows 10

ติดตั้ง Python, JupyterLab, Pandas และ Plotly แล้วเปิดใช้งานผ่าน Visual Studio Code บน Windows 10

การติดตั้ง Python + JupyterLab บน Windows 10

แนะนำการติดตั้ง Python + Jupyter Lab และการใช้งานผ่าน Visual Studio Code บน Windows 10

เตรียมการติดตั้ง

โปรแกรมที่จำเป็น

  1. Visual Studio Code

โปรแกรมที่ควรมีก่อนการติดตั้ง

  1. Windows Terminal

ขั้นตอนการติดตั้ง

ติดตั้ง Python 3.9 ผ่าน Microsoft Store

ติดตั้ง Python 3.9 ผ่าน Microsoft Store — assets/85c4abd6 294b 4f29 8023 cc99bd57136f step1 installpython

หลังติดตั้งแล้วให้ทำการตรวจสอบ Version ดู

python --version

ติดตั้ง Python 3.9 ผ่าน Microsoft Store — assets/90c7587b 643d 4238 a985 1f7e752dd6b4 step2 checkpython

ติดตั้ง JupyterLab

ติดตั้งผ่าน Windows Terminal หรือ Command Prompt

pip install jupyterlab

หลังจากติดตั้งแล้ว ให้ทดลองรันโดยใช้

jupyter lab

หากไม่สามารถรันได้ โดยแจ้งข้อความผิดพลาดที่ว่าไม่พบคำสั่ง jupyter นั้นอาจเกิดจากตัวติดตั้งไม่ได้เพิ่ม environment variables ให้ตรวจสอบที่อยู่ของ jupyter.exe ก่อน โดย Python Script ที่ติดตั้งจาก Pip จะไปอยู่ที่

C:\Users\{User-Name}\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts

ติดตั้ง JupyterLab — assets/1d113345 9880 4836 b8b5 23fd217036e4 step3 checkpath

เมื่อเจอกับไฟล์ jupyter.exe ในโฟลเดอร์นี้แล้วให้ทำการเพิ่ม environment variables โดยเพิ่มไปที่ System variables ที่ชื่อว่า Path ตามรูป

ติดตั้ง JupyterLab — assets/66a78bb4 4a63 48a9 b13e a65a348136eb step3 addpath ติดตั้ง JupyterLab — assets/efb57f4d ae31 44c9 a3aa 3210832c3ff3 step3 addpath2

จากนั้นให้ปิด Command Prompt / Windows Terminal แล้วเปิดใหม่เพื่อให้มันโหลด environment variables แล้วรัน jupyter lab อีกครั้ง จะได้แบบนี้

ติดตั้ง JupyterLab — assets/b9ee42f4 1a46 48b3 b0be 5b9453a542e1 step4 run

ให้คลิก URL ที่มันบอกเพื่อเปิด Jupyter Lab ใน Browser

ติดตั้ง JupyterLab — assets/06f6e59e e681 4f81 88d7 fafc5618a4f1 step4 jupyter

ติดตั้ง Libraries ที่จำเป็น

Pandas

pip install pandas

Plotly

pip install plotly
pip install jupyterlab ipywidgets
jupyter labextension install jupyterlab-plotly
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget

Visual Studio Code

ทำการติดตั้ง Extension ชื่อ Python Pylance และ Jupyter

Visual Studio Code — assets/8c68a38a 9410 4790 a5eb 8ef5cc1c5c48 step5 vsextension

จากนั้นกด Ctrl+Shift+P เพื่อเปิด Command Palette แล้วพิมพ์ Jupyter แล้วเลือก Create New Blank Notebook ก็เรียบร้อย

Visual Studio Code — assets/0ac12fee 65a6 4302 abd4 b050223d3818 step5 add