巨量資料探勘與應用
Big Data Mining and Applications
Python Development Environment Setup
李建樂
Chien-Yueh Lee, Ph.D.
Assistant Professor
Master Program in Artificial Intelligence
Innovation Frontier Institute of Research for Science and Technology
Department of Electrical Engineering
National Taipei University of Technology
Feb. 24, 2025
Outline
• Setting Up the Development Environment
-Installing Python
-Introduction to Anaconda and installation
• User Interface Explanation
-Introduction to Jupyter notebook
-Operational interface
-Edit mode and command mode
-Common keyboard shortcuts
• Python Coding Style
• Methods for Running Python Programs
2
How to Install Python?
• Windows 10/11
Ø Anaconda → Python & Jupyter notebook
• Windows 10/11 + Linux
Ø Windows Subsystem for Linux (WSL) → Anaconda → Python & Jupyter notebook
Ø Docker → pull “jupyter/datascience-notebook” image
Ø VM (如:VMware、VirtualBox) → Linux → Anaconda → Python & Jupyter notebook
• macOS (Intel x86)
Ø Anaconda → Python & Jupyter notebook
• macOS (Apple Silicon)
Ø Miniforge3 → Python & Jupyter notebook
• Linux
Ø Anaconda → Python & Jupyter notebook 3
Introduction to
Anaconda
• Anaconda is a package and software
management platform for Python and R.
• It is primarily used for data science,
machine learning, big data processing, and
predictive analytics.
• General users can install and manage
software independently, offering high
flexibility.
• It comes with Python, GCC, and libraries,
making software compilation and
installation convenient without being
affected by the main system environment.
• Supports Python virtual environments.
• Automatically handles software
dependency issues. 4
Download Anaconda Individual Edition
• URL: [Link]
5
Install Anaconda (Windows)
6
Install Anaconda (macOS)
7
Install Anaconda (Linux)
wget [Link]
--2021-09-02 [Link]-- [Link]
Resolving [Link] ([Link])... [Link], [Link], [Link], ...
Connecting to [Link] ([Link])|[Link]|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 570853747 (544M) [application/x-sh]
Saving to: ‘Anaconda3-2021.05-Linux-x86_64.sh’
Anaconda3-2021.05-Linux-x86_64.
100%[======================================================>] 544.41M 11.1MB/s in 49s
2021-09-02 [Link] (11.1 MB/s) - ‘Anaconda3-2021.05-Linux-x86_64.sh’ saved [570853747/570853747]
8
Install Anaconda (Linux)
bash Anaconda3-2021.05-Linux-x86_64.sh
Welcome to Anaconda3 2021.05
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
…
Do you accept the license terms? [yes|no]
[no] >>> yes
9
Install Anaconda (Linux)
Anaconda3 will now be installed into this location:
/home/user/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/user/anaconda3] >>>
…
Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes 10
Install Anaconda (Linux)
source .bashrc
(base) user@LAPTOP-FKT0GC2T:~#
11
• List installed packages
Conda Commands - conda list
• Search for a specific package
• Install packages - conda search PACKAGE
- conda install PACKAGE1
PACKAGE2 …
• Create a virtual environment
- conda create -n py2 python=2.7
• Install a specific version of
the package • Activate a specific virtual
environment
- conda install python=3.5
- conda activate py2
• Uninstall packages • Deactivate the current virtual
- conda uninstall PACKAGE1 environment
PACKAGE2 …
- conda deactivate
• Update packages
• List available virtual environment
- conda update PACKAGE1
PACKAGE2 … - conda env list
12
Introduction to Jupyter Notebook
• Jupyter Notebook is a web-based interactive computing environment
that leverages its interpreted nature to visualize data in real time,
allowing programs to execute interactively.
13
From: Wikipedia From: Coding Lab
Start Jupyter Notebook
• Start → Anaconda → • Enter the command to start Jupyter
Click "Jupyter Notebook" Notebook
Ø Open the terminal interface and enter
the following command:
jupyter notebook
Ø Applicable for an Anaconda environment
on Windows + WSL
14
Start Jupyter Notebook (Windows + WSL )
jupyter notebook --no-browser
I 2021-09-17 [Link].863 LabApp] JupyterLab extension loaded from /home/user/anaconda3/lib/python3.8/site-
packages/jupyterlab
[I 2021-09-17 [Link].863 LabApp] JupyterLab application directory is /home/user/anaconda3/share/jupyter/lab
[I [Link].867 NotebookApp] Serving notebooks from local directory: /home/user
[I [Link].867 NotebookApp] Jupyter Notebook 6.3.0 is running at:
[I [Link].867 NotebookApp] [Link]
[I [Link].867 NotebookApp] or [Link]
[I [Link].867 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C [Link].869 NotebookApp]
To access the notebook, open this file in a browser:
[Link]
Or copy and paste one of these URLs:
[Link]
or [Link] 15
Start Jupyter Notebook (Windows + WSL )
• Open a browser and paste the URL, e.g.,
[Link]
16
Explanation of the Notebook Dashboard Interface
File path
Sub-folder
Running Notebook
Non-running Notebook
17
Create a Python Notebook
1
2
18
Explanation of the Noteboot Editor Interface
Notebook file name
Main menu
Toolbar Cell (編輯單元 )
Kernel (程式核心)
Editable area
Output area
19
重
Explanation of the Toolbar 啟
Kernel
並 開
向 執 啟
下 中 指
儲 剪 斷 行
貼 移 整 令
存 下 上 動 程 面
式 個
Notebook Cell Cell Cell Notebook 板
在 複 向 執 重 改
下 製 上 行 新 變
方 Cell 移 選 啟 Cell
新 動 擇 動 類
增 Cell 的 Kernel 型
一 Cell
個
Cell 20
Edit and Command Modes
• The Edit Mode
ØYou can enter text or code into a Cell
ØThe Cell border turns green when active
ØClick inside the editable area of the Cell with the mouse or press the
Enter key to enter Edit Mode
• The Command Mode
ØYou can perform operations on the Notebook or Cell
ØThe Cell border turns blue when in Command Mode
ØClick outside the editable area of the Cell with the mouse or press Esc
to enter Command Mode
21
The Instruction for Keyboard Shortcuts
• Press H in Command Mode to view the list of available
keyboard shortcuts
22
Common Keyboard Shortcuts List
進入指令模式 Esc
執行選擇的Cell並移至下一個Cell Shift Enter
執行選擇的Cell Ctrl Enter
執行選擇的Cell並於下方插入新的Cell Alt Enter
選擇上方的Cell K或↑
選擇下方的Cell J或↓
在上方插入新的Cell A
在下方插入新的Cell B
剪下Cell X
複製Cell C
於上方貼上Cell Shift V
於下方貼上Cell V
刪除選擇的Cell DD
取消刪除Cell Z
儲存 Ctrl S 或 S 23
Hello world!
24
Python Coding Style
• Case Sensitivity: Python distinguishes between uppercase and lowercase
letters.
Ø For example: Student and student are considered different.
• Whitespace:
Ø It is recommended to add a space before and after operators, e.g., i = 100.
Ø Prefer one statement per line.
Ø Avoid extra spaces in the following cases, e.g., print(x, y), and not
print (x, y), print( x, y ), or print(x , y).
• Maximum Line Length: Each line should ideally not exceed 79 characters.
• Indentation (縮排):
Ø Use 4 spaces per indentation level.
Ø The Tab key can be used for indentation, but do not mix spaces and tabs.
25
Comments in Python
• Python provides the following two types of comment syntax:
Ø# for single-line comments, e.g.:
# My first Python program
print("Hello, World!")
Ø''' (triple single quotes) or """ (triple double quotes) for multi-line
comments, e.g.:
'''
My first Python program.
It will print "Hello, World!"
'''
print("Hello, World!")
26
Methods for Running Python Programs
1. Using an Integrated Development Environment (IDE) for Editing and
Execution
ØIDEs provide many features that assist in programming, making
development easier and faster.
ØCommon IDEs include Jupyter Notebook, Visual Studio Code, PyCharm,
and Spyder.
ØCloud-based environments like Google Colaboratory can also be used.
2. Running Python Shell in the Terminal
ØSuitable for testing small and simple code snippets
3. Writing Code in a Text Editor and Executing It
ØSuitable for writing large programs
ØCode is written in a file and then executed
ØPython script files have the extension .py
27
Google Colaboratory (Colab)
• [Link]
28
Running Python Shell in the Terminal
• Type "python" to enter the Python shell
(base) user@LAPTOP-FKT0GC2T:~$ python
Python 3.9.7 (default, Sep 16 2021, [Link])
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hi, Python')
Hi, Python
>>> 123+456
579
• Exit Python shell with the exit() function or shortcut
>>> exit() # Or use the shortcut: Ctrl D
(base) user@LAPTOP-FKT0GC2T:~$
29
Writing Code in a Text Editor and Executing It
1. Use any text editor you are comfortable with, such as
Notepad++, Sublime Text, etc.
2. Open a new blank document and enter the following code:
print("Hello, World!")
3. Save the file with the name [Link].
4. In the command line interface or Windows Terminal, run
the program by entering:
(base) user@LAPTOP-FKT0GC2T:~$ python [Link]
Hello World
30