Anconda正确使用姿势

1. 下载exe Anaconda | Individual Edition,默认安装,不勾选添加环境变量;

 2. 创建或yaml导入虚拟环境;

#使用已有的yaml配置生成环境
conda env create -f xx.yml

 #Anaconda 镜像使用帮助

##https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

#创建名为 .condarc 的文件
conda config --set show_channel_urls yes

#复制配置
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。

运行 conda create -n myenv numpy 测试一下吧。

3. 使用问题

 python 启动环境不正确,如在windows环境下,大概是cmd或powershell环境path不对;

可使用conda init 初始化;Powershell、CMD添加conda init

#可使用anconda 默认cmd进行配置
#ps
conda init powershell
#cmd
conda init cmd.exe
#重启powershell或者cmd

powershell执行后,不能正确启动,报“无法加载文件 WindowsPowerShell\profile.ps1,因为在此系统上禁止 运行脚本” 解决办法:

get-executionpolicy

#Restricted 执行策略不允许任何脚本运行。  
#AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。
set-ExecutionPolicy RemoteSigned

4.正确配置后,输入conda activate env**后,出现环境前缀:

5. VS code和Pycharm,从Anconda Navigator启动,似乎底下终端python环境混乱,activate不起作用,启动python不正确,cuda调用会失败,torch.cuda.is_available()=False!!

解决:直接启动vscode或pycharm exe程序!!

!!调试最好使用VS Code,pycharm搭配anconda,环境仍不正常。!!

 6. vscode 添加调试参数"args":[.....]

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": ["--upscale_factor","3", "--batchSize","64","--nEpochs","5","--cuda"]
        }
    ]
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值