VM下运行python

VM下Ubuntu中pytorch环境搭建

1.虚拟机装miniconda
a.下载
地址:https://docs.conda.io/en/latest/miniconda.html
安装此版本,无需手动下载,使用命令:
在这里插入图片描述

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

推荐使用镜像源下载:

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py38_4.8.3-Linux-x86_64.sh --no-check-certificate

b.安装

bash Miniconda3-py38_4.8.3-Linux-x86_64.sh

安装过程中根据提示输入enter或yes
c.验证安装
重启终端(必须),运行下方命令,显示版本号则安装成功

conda -V

2.配置镜像源
a.在用户目录(/home/xxx)下新建.condarc文件

touch .condarc

b.vim打开.condarc文件,写入下方内容保存后退出

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_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/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - 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
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

c.执行以下命令清除索引缓存,保证用的是镜像站提供的索引

conda clean -i

d.查看是否已经换源

conda config --show

3.使用特定的python版本
a.下载

conda install python=3.8

b.若将python安装到一个新的环境中

conda create -n <my_environment> python=3.8

4.环境管理
官方文档:Managing environments — conda 4.12.0.post41+897384a0 documentation
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

a.创建环境

conda create -n pytorch python=3.8

弹出提示,输入 y,即可安装
安装成功后,输入以下指令:

conda info --envs

在这里插入图片描述
b.激活环境

conda activate pytorch

c.安装pytorch
官网:https://pytorch.org/

 conda install pytorch torchvision torchaudio cudatoolkit=10.2 

去掉了官网给的 -c pytorch,否则可能下载失败

验证是否安装成功
在自己的环境中,输入python

import torch
print(torch.cuda.is_available())


5.安装pycharm并且使用anaconda虚拟环境
下载地址:https://www.jetbrains.com/pycharm/
选择自己系统对应版本,这里主要针对linux,下载community版本就够用了
下载成功之后,在浏览器查看下载的文件,然后打开压缩包,把文件移动到所需要的位置,打开pycharm->bin,在这个目录中右键打开终端输入

./pycharm.sh
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值