在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运行失败问题

大功告成!

希望能帮到你。

相关推荐
李昊哲小课18 小时前
Stable Diffusion 保姆级教程|HF 国内镜像配置 + 一键安装 + 本地模型加载 + 完整代码
stable diffusion·hugging face
yumgpkpm18 小时前
Qwen3.6正式开源,华为昇腾910B实现高效适配
华为·ai作画·stable diffusion·开源·ai写作·llama·gpu算力
Just right2 天前
pycharm卡死在Connected to pydev debugger
ide·python·pycharm
Irene19912 天前
(AI总结版)Rich 配置经验总结:PyCharm 终端颜色显示操作指南
python·pycharm
小张同学8242 天前
[特殊字符]Python 进阶实战指南(PyCharm 专属优化):从高效编码到工程化落地,告别新手低效写法
开发语言·python·pycharm
秉寒-CHO2 天前
从 PyCharm 到 Cursor:我的 LLM 项目 AI 编程工具链全解析
ide·人工智能·pycharm
WHS-_-20223 天前
Pycharm 使用经验
ide·python·pycharm
数智工坊3 天前
深度拆解AnomalyAny:异常检测新工作,利用Stable Diffusion生成真实多样异常样本!
人工智能·pytorch·python·stable diffusion
花间相见3 天前
【AI私人家庭医生day01】—— 项目介绍
大数据·linux·人工智能·python·flask·conda·ai编程
Irene19913 天前
PyCharm 终端显示优化
python·pycharm