安装pytorch,使用python

安装pytorch

1.查询我的显卡支持的cuda版本:最高12.7。
image
2.已经安装好anaconda。
3.创建新环境

conda create -n learning_pytorch python==3.10
  1. 登录pytorch官网
    cuda12.6应该是可以支持的:
    image
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126

image
4.惨啦,忽然发现我忘记切换环境了,紧急停止。

conda activate learning_pytorch
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126

image
5.在桌面创建hungry.py并执行
image
6.为什么系统成功执行了?
因为环境变量path告诉系统应该去哪里查找可执行文件。
image
7.python类的定义

class Man:
	def __init__(self,name):
		self.name = name
		print("Initialized")
	
	def hello(self):
		print("Hello " + self.name + "!")

m = Man("David")
m.hello()
posted @ 2026-01-30 16:53  MineralWaterAndCola  阅读(0)  评论(0)    收藏  举报