Files
learn-python-the-smart-way/notebook/chapter_0-Installation.ipynb
2023-09-18 00:05:23 +08:00

507 lines
11 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"id": "68e6c596",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Chapter 0 安装 Installation"
]
},
{
"cell_type": "markdown",
"id": "e3b9b6a8",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## 安装清单\n",
"- Miniconda: https://docs.conda.io/en/latest/miniconda.html\n",
"- Visual Studio Code: https://code.visualstudio.com/"
]
},
{
"cell_type": "markdown",
"id": "e3eb91af",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Miniconda 安装配置"
]
},
{
"cell_type": "markdown",
"id": "4585b342",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### 下载 Miniconda\n",
"\n",
"Miniconda 下载地址:<https://docs.conda.io/en/latest/miniconda.html>\n",
"\n",
"最新版 Miniconda For Windows 下载链接:\n",
"\n",
"<https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe>"
]
},
{
"cell_type": "markdown",
"id": "d9358602",
"metadata": {
"cell_style": "center",
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Windows 下安装配置推荐\n",
"\n",
"- Just Me (recommended)\n",
"- Clear the package cache upon completion"
]
},
{
"cell_type": "markdown",
"id": "963b4fd9",
"metadata": {
"cell_style": "split"
},
"source": [
"![](./image/chap0/miniconda_installation_1.png)"
]
},
{
"cell_type": "markdown",
"id": "5d2168a7",
"metadata": {
"cell_style": "split"
},
"source": [
"![](./image/chap0/miniconda_installation_2.png)"
]
},
{
"cell_type": "markdown",
"id": "0312d547",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## 修改 Powershell 执行策略(可选)\n",
"\n",
"在`开始`图标**右键单击**,选择 `Windows PowerShell管理员`\n",
"\n",
"先输入下面的内容,并回车:\n",
"```powershell\n",
"Set-ExecutionPolicy -Scope CurrentUser RemoteSigned\n",
"```\n",
"出现如下内容后,输入:`A`,回车:\n",
"\n",
"![](../resources/slides/chap0/pic/powershell.png)\n",
"\n",
"最后在 **Anaconda Powershell Prompt** 中输入:\n",
"```bash\n",
"conda init\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "50b897f3",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## 更换镜像源\n",
"\n",
"- Pip 换源\n",
"- Conda 换源\n",
"\n",
"> 加快国内资源下载速度"
]
},
{
"cell_type": "markdown",
"id": "5ec52c36",
"metadata": {
"cell_style": "center",
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### 校园网联合镜像站\n",
"<https://help.mirrors.cernet.edu.cn/>\n",
"\n",
"### 阿里巴巴开源镜像站\n",
"\n",
"<https://developer.aliyun.com/mirror/>\n",
"\n",
"请避免使用代理,不合理的代理设置会导致下载失败"
]
},
{
"cell_type": "markdown",
"id": "02919362",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Conda 更换镜像源\n",
"\n",
"清华大学开源软件镜像站:<https://help.mirrors.cernet.edu.cn/anaconda/>\n",
"\n",
"南方科技大学开源软件镜像站:<https://help.mirrors.cernet.edu.cn/anaconda-extra/>\n",
"\n",
"在 **Anaconda Powershell Prompt** 中输入:\n",
"\n",
"```bash\n",
"conda config --set show_channel_urls yes\n",
"```\n",
"\n",
"在镜像站复制文本后,在 **Anaconda Powershell Prompt** 中输入:\n",
"\n",
"```bash\n",
"notepad .condarc # 注意有个小点 \".\" 在 \"condarc\" 的前面\n",
"```\n",
"\n",
"粘贴刚刚复制的文本,保存文件后关闭\n",
"\n",
"最后在 **Anaconda Powershell Prompt** 中输入:\n",
"\n",
"```bash\n",
"conda clean -i # 清除源缓存,以启用镜像源\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "0de0a2be",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## PyPI 更换镜像源\n",
" \n",
"校园网联合镜像站:<https://help.mirrors.cernet.edu.cn/pypi/>\n",
"\n",
"复制文本后,在 **Anaconda Powershell Prompt** 中粘贴运行即可:\n",
"\n",
"```bash\n",
"# 设置 PyPI 镜像源\n",
"pip config set global.index-url https://mirrors.cernet.edu.cn/pypi/web/simple \n",
"```"
]
},
{
"cell_type": "markdown",
"id": "054f6cbc",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## 课程环境搭建"
]
},
{
"cell_type": "markdown",
"id": "d8028b9c",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### 创建与激活 Conda 环境\n",
"\n",
"创建 Conda 环境\n",
"\n",
"```bash\n",
"conda create -n Datawhale python=3.10 # conda 环境创建\n",
"```\n",
"\n",
"其中 ***-n*** 代表创建的环境名称,这里是 ***Datawhale***,并指定 ***Python 版本为 3.10***\n",
"\n",
"激活刚刚创建的 Conda 环境:\n",
"\n",
"```bash\n",
"conda activate Datawhale # 激活 Datawhale 环境,不同环境的 Python 包版本不同!\n",
"```\n",
"\n",
"如果需要删除某个 Conda 环境:\n",
"\n",
"```bash\n",
"conda deactivate # 退出该环境\n",
"conda remove -n Datawhale --all # 删除整个环境\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "4cac85fe",
"metadata": {
"cell_style": "split",
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Pip 安装与展示\n",
"\n",
"Pip 安装课程所需第三方库\n",
"\n",
"```bash\n",
"pip install jupyter\n",
"```\n",
"\n",
"在指定路径输入:\n",
"\n",
"```bash\n",
"jupyter-notebook # 会自动跳转到浏览器\n",
"```\n",
"\n",
"结束学习时使用:\n",
"\n",
"```bash\n",
"Ctrl + C # 关闭 Jupyter Notebook 服务\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "708d553e",
"metadata": {
"cell_style": "split",
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"### 安装清单\n",
"\n",
"数据挖掘:\n",
"- scikit-learn\n",
"- numpy\n",
"- pandas\n",
"- tqdm\n",
"- lightgbm (数据挖掘模型)\n",
"\n",
"CV\n",
"- nibabel\n",
"- pillow"
]
},
{
"cell_type": "markdown",
"id": "8aedd2d4",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Conda 安装与展示\n",
"\n",
"首先在 **Anaconda Powershell Prompt** 中输入:\n",
"\n",
"```bash\n",
"nvidia-smi # 查看当前 GPU 支持的最高 CUDA 版本\n",
"```\n",
"\n",
"![](../resources/slides/chap0/pic/CUDA_info.png)\n",
"\n",
"**Pytorch** 安装: <https://pytorch.org/get-started/locally/>\n",
"\n",
"```bash\n",
"conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia\n",
"```\n",
"\n",
"**PaddlePaddle** 安装:<https://www.paddlepaddle.org.cn>\n",
"```bash\n",
"conda install paddlepaddle-gpu==2.4.2 cudatoolkit=11.7 -c Paddle -c conda-forge\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "109adde7",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## CUDA 验证"
]
},
{
"cell_type": "markdown",
"id": "5651891e",
"metadata": {},
"source": [
"在 **Anaconda Powershell Prompt** 中输入:\n",
"\n",
"```bash\n",
"ipython # 交互 Python 运行环境\n",
"```\n",
"\n",
"使用 `exit` 或 `exit()` 来退出 **IPython**"
]
},
{
"cell_type": "markdown",
"id": "f6021cd5",
"metadata": {
"cell_style": "split",
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"PaddlePaddle:\n",
"\n",
"```python\n",
">>> import paddle\n",
">>> paddle.utils.run_check()\n",
"```\n",
"\n",
"正确输出:\n",
"```plain\n",
"PaddlePaddle works well on 1 GPU.\n",
"PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "de874521",
"metadata": {
"cell_style": "split",
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Pytorch:\n",
"\n",
"```python\n",
">>> import torch\n",
">>> torch.cuda.is_available()\n",
"```\n",
"\n",
"正常输出:\n",
"\n",
"```python\n",
"True\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "0d011cdf",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## 云端环境的使用\n",
"- 百度飞桨 AI Studio https://aistudio.baidu.com/aistudio/index\n",
"- 阿里天池 PAI DSW https://tianchi.aliyun.com/notebook-ai\n",
"- Kaggle https://www.kaggle.com/code\n",
"- Google Colab https://colab.research.google.com/\n",
"- Sagemaker Studio Lab https://studiolab.sagemaker.aws/"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
},
"rise": {
"overlay": "<div class='my-top-right'><img height=40px src='../resources/datawhale_logo.png'/></div><div class='my-top-left'></div>"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}