venv虚拟环境

venv

https://docs.python.org/zh-cn/3/library/venv.html

创建

1
2
3
4
5
python -m venv -h

python -m venv /path/to/new/virtual/environment

source <venv>/bin/activate

激活

1
2
3
4
python3 -m venv /opt/stable-diffusion/sd-venv

#激活虚拟环境
source /opt/stable-diffusion/sd-venv/bin/activate

(sd-venv) cs@debian:/opt/stable-diffusion/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#查看当前pip源
pip config list
#pip config set global.index-url 源网址

pip install -r requirements.txt

#已经安装的包以requirements的格式
pip freeze



pip wheel -w ./tmp_dir -r requirements.txt
pip download -d ./tmp_dir -r requirements.txt
pip install -no-index --find-links=./tmp_dir -r requirements.txt

停止

1
2
#停止使用虚拟环境
source /opt/stable-diffusion/sd-venv/bin/deactivate

list

1
pip list | grep gradio

gradio 3.23.0

show

1
pip show gradio

Name: gradio
Version: 3.23.0
Summary: Python library for easily interacting with trained machine learning models
Home-page: None
Author: None
Author-email: Abubakar Abid team@gradio.app, Ali Abid team@gradio.app, Ali Abdalla team@gradio.app, Dawood Khan team@gradio.app, Ahsen Khaliq team@gradio.app, Pete Allen team@gradio.app, Ömer Faruk Özdemir team@gradio.app
License: None
Location: /home/cs/oss/sd/venv/lib/python3.9/site-packages
Requires: websockets, fastapi, markupsafe, fsspec, pydantic, huggingface-hub, altair, orjson, python-multipart, aiohttp, ffmpy, markdown-it-py, pillow, semantic-version, uvicorn, pyyaml, typing-extensions, pandas, huggingface-hub, httpx, numpy, aiofiles, matplotlib, requests, pydub, mdit-py-plugins, jinja2
Required-by:

if torch.cuda.is_available():
  device = torch.device('cuda')
else:
  device = torch.device('cpu')
  
#等价  
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

加载cuda异常

1
2
3
4
5
6
7
8
>>> import torch
>>> torch.cuda.is_available()
/home/cs/.local/lib/python3.9/site-packages/torch/cuda/__init__.py:107: UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:109.)
return torch._C._cuda_getDeviceCount() > 0
False
>>> torch.cuda.is_available()
False

nvidia-modprobe 版本过低或未安裝,与显卡驱动的版本不匹配,将nvidia-modprobe更新至与显卡驱动的版本一致即可。 apt-get install nvidia-modprobe

重装pytorch和CUDA也无济于事,后面查到是因为ubuntu在suspend出现的问题,重启服务器物理机就可以了。

1
2
3
4
5
source /home/cs/data/sd-venv/bin/activate

sudo python setup.py install --prefix /home/cs/.local

python setup.py install --prefix /home/cs/stable-diffusion-webui/venv

7z x yajiu.7z

python wheel 安装包的制作与安装

http://coolpython.net/informal_essay/20-09/python-wheel-make-and-install.html

点击打赏
文章目录
  1. 1. venv
    1. 1.1. python wheel 安装包的制作与安装
载入天数...载入时分秒... ,