使用 Python 中可能遇到的问题

2021/7/22

# Python 常用国内源

清华源:

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

豆瓣源:https://pypi.doubanio.com/simple

阿里源:https://mirrors.aliyun.com/pypi/simple/

也可直接设置 pip 配置文件,Linux 位置在~/.pip/pip.conf,Windows 位置在C:\Users\[name]\AppData\Roaming\pip\pip.ini

如果没有文件,新建即可,填入以下内容。

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
timeout = 6000
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
1
2
3
4
5

# pip 安装 pytorch 报错

ERROR: torch ahs an invalid wheel, .dist-info directory not found

Previous PyTorch Versions | PyTorch (opens new window)

使用

pip install torch==1.7.0+cu101 torchvision==0.8.0+cu101 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
1

# pytorch 无法正常调用 cuda

AttributeError module ‘torch._C‘ has no attribute ‘_cuda_setDevice‘

说明 torch 安装的是 CPU 版本而不是 GPU 版本。

# visdom 500

FileNotFoundError: [Errno 2] No such file or directory: 'D:\Anaconda3\envs\omnimatte\lib\site-packages\visdom\static\index.html' ERROR:root:ERROR: 500: {'exc_info': (<class 'FileNotFoundError'>, FileNotFoundError(2, 'No such file or directory'), <traceback object at 0x00000166D0AD9500>)} ERROR:tornado.access:500 GET / (127.0.0.1) 3.00ms

重装 visdom 即可

pip uninstall visdom
pip install visdom
python -m visdom.server
1
2
3