在Pycharm配置stable diffusion环境(使用conda虚拟环境)

自己配环境的时候也没个指南,少安装包或者包之间版本冲突是再按正常不过的事了,真的令人不胜其烦。

下面记录一下自己在conda虚拟环境配置stable diffusion的代码环境,希望能帮大家少踩几个坑。

虚拟环境配置

默认你已经安装了annaconda,接下来打开命令提示符:

python 复制代码
#创建python3.10的虚拟环境,环境名为newgit_env 
conda create -n newgit_env python=3.10
#激活虚拟环境
conda activate newgit_env 
#安装git
conda install git
#安装pytorch(本人安装的是GPU版本)
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
#测试GPU是否可用(在命令提示符测试)
import torch
print(torch.__version__)          # 应输出类似 2.5.1+cu118
print(torch.cuda.is_available())  # 应返回 True
print(torch.version.cuda)         # 应输出 11.8
#官方教程安装diffusers
pip install --upgrade diffusers[torch]  #以下是两种不同安装渠道,推荐第二种
conda install -c conda-forge diffusers
#安装transformers
conda install transformers=4.40.0
#安装jupyter
conda install -c conda-forge jupyter
#安装opencv(本人运行代码时发现少包,安装上)
conda install -c conda-forge opencv
pip install hf_xet

Pytorch导入conda虚拟环境

点击pycharm右下角红框地方,打开python解释器界面->添加新的解释器->添加本地解释器

点击选择现有

类型选择conda,环境就选择我们创建的虚拟环境名,conda的路径不用管,系统会自动识别我们安装的路径

运行stable diffusion官方demo

(此处我使用的是jupyter,jupyter在pycharm里面的配置教程看我另外一篇文章:
在pycharm配置虚拟环境和jupyter,解决jupyter运行失败问题

大功告成!

希望能帮到你。

相关推荐
充气大锤2 小时前
从0开始配置conda环境并在PyCharm中使用
ide·pycharm·conda
Seeklike19 小时前
diffusers学习--stable diffusion的管线解析
人工智能·stable diffusion·diffusers
马甲是掉不了一点的<.<1 天前
Stable Diffusion 环境配置详细指南
stable diffusion·环境配置
软件测试-阿涛1 天前
【AI绘画】Stable Diffusion webUI 常用功能使用技巧
人工智能·深度学习·计算机视觉·ai作画·stable diffusion
小徐敲java1 天前
python-pycharm切换python各种版本的环境与安装python各种版本的环境(pypi轮子下载)
开发语言·python·pycharm
m0_603888712 天前
Stable Diffusion Models are Secretly Good at Visual In-Context Learning
人工智能·ai·stable diffusion·论文速览
lyx33136967592 天前
IDEA、Pycharm、DataGrip等激活破解冲突问题解决方案之一
java·pycharm·intellij-idea
万粉变现经纪人3 天前
何解决PyCharm中pip install安装Python报错ModuleNotFoundError: No module named ‘json’问题
python·pycharm·json·beautifulsoup·scikit-learn·matplotlib·pip
猫头虎3 天前
如何解决 JetBrains IntelliJ IDEA 2024.2 和 2025.2 新版本区域选择问题:key is invalid
java·ide·pycharm·intellij-idea·idea·intellij idea·phpstorm