window_anaconda_python虚拟环境_常用命令

介绍语

你好! 这是我使用anaconda进行Python虚拟环境配置的一些命令。

1 自动记录程序运行时间

(参考https://blog.csdn.net/weixin_39679379/article/details/128015001)

import time
start = time.clock()
程序
end = time.clock()
print("运行耗时", end-start)

Python3.8不再支持time.clock(),如果使用Python3.8:

import time
start = time.perf_counter()
程序
end = time.perf_counter()
print("运行耗时", end-start)

2 虚拟环境安装opencv-python(cv2)

(参考https://blog.csdn.net/qq_44111805/article/details/128287948)
去下载镜像文件到本地,然后进入到下载目录,pip安装

3 查看虚拟环境下的cuda版本

nvcc --version 
import torch
print(torch.__version__)#pytorch的版本
print(torch.version.cuda)#cuda版本
print(torch.backends.cudnn.version())

4 修改包的管理镜像为国内源

Anaconda安装成功之后,我们需要修改其包管理镜像为国内源Tsinghua Open Source Mirror

简单来说就是在cmd中分别运行这两个命令就好了。

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

5 给虚拟环境指定Python版本

如果我们需要添加2.7版本的Python,可以进行如下操作:
1.

conda create -n py27 python=2.7 #其中py27是新添加环境的名字,可以自定义修改

(之后可以通过activate py27deactivate py27命令激活、退出该环境)

  1. 在激活新环境后,我们所做的操作便都是在新环境下的,包括pip命令来安装第三方库。

试一下pip安装lxml包(其他包类似语句):pip install lxmlconda install lxml

通过conda info -e命令查看已创建的虚拟环境们

通过conda remove -n 虚拟环境名 --all来删除指定的环境(如果不添–all参数,而是指明某个库名,则是删除该库)。

  1. 测试pytorch
    (1)进入python:python
    (2)测试pytorch:
import torch
torch.cuda.is_available() #验证gpu版本的torch是否成功

6 在虚拟环境中安装cuda

  1. 首先要看好cudnn与cudatoolkit与pytorch包的版本对应;
  2. 装cudatoolkit:
conda install cudatoolkit=11.3 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/
  1. 装对应cudnn:(不是必须要装cudnn,要看代码的运行要求)
conda install cudnn=8.0.5 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64/
  1. 就可以装cuda对应版本的torch包:
    网址:https://pytorch.org/get-started/previous-versions/

7 打开jupyter notebook

不要从anaconda navigate里面打开!
不要用anaconda下载后自带的jupyter notebook,要在anaconda prompt的虚拟环境下重新安装的jupyter notebook才可以正常import(反正我的是这样)

解决方法:(第一次打开需要安装jupyter包)

  1. 打开anaconda prompt
  2. 激活虚拟环境
  3. 安装jupyter notebook:在anaconda prompt中输入 conda install jupyter
  4. 再在anaconda prompt中去打开jupyter notebook,输入 jupyter notebook

平时打开jupyter notebook步骤:

  1. 打开anaconda prompt
  2. 激活对应虚拟环境
  3. 打开jupyter notebook:输入 jupyter notebook

8 查看pytorch版本

  1. 进入python:虚拟环境下输入python
  2. 输入:
import torch
print(torch.__version__)

9 pytorch官网

https://pytorch.org/get-started/locally/

安装pytorch看虚拟环境下安装的cuda版本或直接安装cpu版本

10 pyg包官网

https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html#

11 查看目前安装的cuda们

  1. 进入目录:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
    可以看到已经安装的cuda版本:10.2,11.1,11.3
  2. 更换cuda“应该”去系统环境配置里面修改优先级

12 cudnn网站

https://developer.nvidia.com/rdp/cudnn-archive
我给cuda10.2配的cudnn版本是7.6.5

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值