很久没有更新了,今天换一种写作风格,一切从简。建议搭配「必应」或者「谷歌」进行食用。
快速配置脚本
以下操作都在 powershell 下执行,如果可以,请更新最新的 powershell 版本,当然使用默认的版本也是可行的
# 从清华源下载安装包
# 清华源 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
# 官方 https://repo.anaconda.com/archive/
curl -o anaconda.exe https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2022.05-Windows-x86_64.exe
# 运行安装包, 记住有一项需要勾选「添加到环境变量」
anaconda.exe
# 添加清华源
conda config --set show_channel_urls yes
Add-Content ~/.condarc '
# https://mirror.tuna.tsinghua.edu.cn/help/anaconda
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
ssl_verify: true
'
conda clean -i
# 更新
conda update conda
# 修改执行策略,注意需要以管理员模式运行
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# 激活 powershell conda 环境
conda init powershell
# 关闭终端默认进入 base 环境
conda config --set auto_activate_base false
# 重新打开 powershell 即可正常运行
问题源
Q 提示 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
系统默认禁止了 powershell
运行脚本,因此需要通过 Set-ExecutionPolicy
修改执行策略,确保在启动 powershell 时,可以正确读取并执行 ...\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
,详细可参考 微软官方文档-关于执行策略
# 以管理员模式运行 powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Q powershell 没有正常显示 base,以及在运行 conda activate 时并没有效果
conda 在 powershell 上的问题也不是一天两天了。如果出现了问题,或许在 conda github 上能找到一些解决线索
# 1.先换源再更新
conda update conda
# 2.激活 conda 环境
conda init powershell
# 3.重新打开 powershell
Q conda init powershell 时, 部分文件路径为中文,出现乱码
# 文本打开 Microsoft.PowerShell_profile.ps1
notepad $PROFILE
# 将下述内容添加到 $PROFILE 中
# 936代表GBK,65001代表UTF-8,注释不需要的行
[System.Console]::OutputEncoding=[System.Text.Encoding]::GetEncoding(936)
[System.Console]::OutputEncoding=[System.Text.Encoding]::GetEncoding(65001)