一、 安装 Anaconda
1.1 下载并安装
https://www.anaconda.com/download/success
1.2 验证是否成功
CMD输入命令:
conda --version
注意:找不到命令需要配置环境变量:
Path 中 添加 Anaconda 的安装路径:
如果没有修改安装位置,默认为: C:\Users\ <用户名> \anaconda3\Scripts
二 、使用 Conda 创建 Python 环境
注意:
以下命令在PowrerShell中执行:
错误修正
如果PowrerShell报错:
*无法加载文件 C:\Users\Administrator.SY-202402052026\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行
脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
- . 'C:\Users\Administrator.SY-202402052026\Documents\WindowsPowerShell ...
-
CategoryInfo : SecurityError: (😃 [],PSSecurityException
-
FullyQualifiedErrorId : UnauthorizedAccess*
执行:Set-ExecutionPolicy RemoteSigned 全都选 Y
创建环境
# 创建名为aidev的python3.9环境
conda create -n aidev python=3.11.9
# 创建成功后可以查看现有环境
conda env list
登录环境
# 初始化命令行设置
conda init powershell
# 进入已创建的环境
conda activate aidev
成功后,输入python 可进入命令行:
退出环境
conda deactivate
删除环境
conda env remove --name aidev
三、 包管理工具pip
通常安装python时,应该默认会安装pip包管理器。
查看是否有pip
pip --version
若不存在
python -m pip install --upgrade pip
设置国内镜像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
使用pip安装包命令 以requests包为例
安装包
pip install requests
指定定版本
pip install requests==x.x.x
升级包
pip install --upgrade requests
查看包
pip list
卸载包
pip uninstall requests
pip修复
python -m ensurepip --upgrade
四、 使用 requirements.txt 管理依赖
创建requirements.txt
pip freeze > requirements.txt
安装requirements.txt中的包
pip install -r requirements.txt
五、jupyter 安装及使用
登录环境
# 初始化命令行设置
conda init powershell
# 进入已创建的环境
conda activate aidev
安装 jupyter
pip install jupyter
汉化
pip install jupyterlab-language-pack-zh-CN
![](https://i-blog.csdnimg.cn/direct/14ff7588f4ca45d5b8da78516f5e1bf7.png)
启动 jupyter notebook
jupyter notebook
登录查看
设置默认打开地址
配置文件地址查看
jupyter notebook --generate-config
修改配置文件中的地址配置
![](https://i-blog.csdnimg.cn/direct/3a795d3427534f239a8f1ead2524c7f3.png)
修改后: