2024.5.14
- __init__函数是 两个下划线开头的函数是声明该属性为私有,不能在类的外部被使用或访问。而__init__函数(方法)支持带参数类的初始化,也可为声明该类的属性(类中的变量)。__init__函数(方法)的第一个参数必须为self,后续参数为自己定义。
#!/usr/bin/python
# -*- coding utf-8 -*-
#Created by Lu Zhan
class Box:
def setDimension(self, width, height, depth):
self.width = width
self.height = height
self.depth = depth
def getVolume(self):
return self.width * self.height * self.depth
b = Box()
b.setDimension(10, 20, 30)
print(b.getVolume())
2024.5.19
- 安装dgl或pyg时安装了低版本的torch, 导致了版本冲突,
The following packages are causing the inconsistency:
- pyg/win-64::pyg==2.5.2=py38_torch_1.13.0_cpu
- 当时没事,第二天打开电脑突然报错
[WinError 127] 找不到指定的程序。 Error loading "F:\Anaconda\envs\HMCAN\lib\site-packages\torch\lib\c10_cuda.dll" or one of its dependencies.
寻找了多种办法,发现卸载时没卸载干净
(HMCAN) E:\Download>pip uninstall torch
Found existing installation: torch 2.1.1+cu118
Uninstalling torch-2.1.1+cu118:
Would remove:
f:\anaconda\envs\hmcan\lib\site-packages\nvfuser\*
f:\anaconda\envs\hmcan\lib\site-packages\torch-2.1.1+cu118.dist-info\*
Proceed (Y/n)? y
Successfully uninstalled torch-2.1.1+cu118
-
重新卸载后,最终决定重装torch,结果安装都报错,但是site-package中torchvision等都在打算手动离线下载,pytorch2.1.1-cu118版本,下载好whl文件后,cd到文件对应位置,pip install 文件名,离线安装。
-
但是!!dgl cuda版本的还是不能用,因为版本与torch2.1.1+cu118不匹配,即:
FileNotFoundError: Cannot find DGL C++ graphbolt library at ...
原因是:默认的cu118版本的dgl对应torch是1.13版,懒得重新创建虚拟环境安装torch了,所以替换为win-64_dgl-1.1.2-py38_0.tar版本,下载链接为:dgl-cpu,安装教程为:dgl安装教程完整版
最后发现自己离线安装了cuda版本,是正确的,实际上是可以使用的,只是pycahrm中一些函数会报警告,并不是安装错误。真的是误区哇。pycharm的问题。