Python学习之路(15)查看及修改pip源和conda源及创建环境,注释规范

茴香豆 Lv5

总结修改查看源的方法,免得每次都得重新找。

高算中心指定源:

1
2
3
4
5
6
7
8
9
#conda 
https://mirrors.tuna.tsinghua.edu.cn/
http://mirrors.ustc.edu.cn/
http://mirrors.aliyun.com/

#pip
https://pypi.tuna.tsinghua.edu.cn/simple
http://pypi.mirrors.ustc.edu.cn/
https://pypi.mirrors.ustc.edu.cn/

pip源

pip更换默认源(以西电源为示例)

临时使用

1
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --user some-package

设为默认源,先升级pip到最新版本

1
2
3
python -m pip install --upgrade pip

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

查看当前源

1
pip config list

conda源

conda 更换默认源(以清华源为示例)

使用下列命令生成.condarc 配置文件,位于用户家目录下

1
conda config --set show_channel_urls yes

编辑.condarc文件,清空原先内容,写入以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

conda虚拟环境

1.conda常用命令

1
2
3
conda list #查看当前环境下安装的包
conda env list #查看当前存在哪些虚拟环境
conda update conda #检查更新conda

2.创建虚拟环境

anaconda命令创建python版本为x.x,名字为your_env_name的虚拟环境。your_env_name文件可以在Anaconda安装目录envs文件下找到

1
conda create -n $your_env_name python=x.x

3.删除虚拟环境

1
conda remove -n $your_env_name --all

4.删除环境中某个包

1
conda remove --name MATHJAX-SSR-0package_name 

检测CUDA是否可用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import torch
print('CUDA版本:',torch.version.cuda)
print('Pytorch版本:',torch.__version__)
print('显卡是否可用:','可用' if(torch.cuda.is_available()) else '不可用')
print('显卡数量:',torch.cuda.device_count())
print('是否支持BF16数字格式:','支持' if (torch.cuda.is_bf16_supported()) else '不支持')
print('当前显卡型号:',torch.cuda.get_device_name())
print('当前显卡的CUDA算力:',torch.cuda.get_device_capability())
print('当前显卡的总显存:',torch.cuda.get_device_properties(0).total_memory/1024/1024/1024,'GB')
print('是否支持TensorCore:','支持' if (torch.cuda.get_device_properties(0).major >= 7) else '不支持')
print('当前显卡的显存使用率:',torch.cuda.memory_allocated(0)/torch.cuda.get_device_properties(0).total_memory*100,'%')

#如果可以正常使用,应当输出以下内容
CUDA版本: 11.7
Pytorch版本: 1.13.1+cu117
显卡是否可用: 可用
显卡数量: 1
是否支持BF16数字格式: 不支持
当前显卡型号: NVIDIA GeForce GTX 960M
当前显卡的CUDA算力: (5, 0)
当前显卡的总显存: 3.9998779296875 GB
是否支持TensorCore: 不支持
当前显卡的显存使用率: 0.0 %

作者:默子要早睡.AinfO
链接:https://zhuanlan.zhihu.com/p/599779565
来源:知乎

注释规范

python代码注释-看这一篇就可以-刘刚刚的博客 (shaoer.cloud)

  • Title: Python学习之路(15)查看及修改pip源和conda源及创建环境,注释规范
  • Author: 茴香豆
  • Created at : 2022-11-27 09:51:20
  • Updated at : 2024-02-29 22:48:19
  • Link: https://hxiangdou.github.io/2022/11/27/Python_15/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
Python学习之路(15)查看及修改pip源和conda源及创建环境,注释规范