使用python帮助艺术家完成角色动画和服装模型等任务
- 声明:
- 克隆项目
- 第 1 步:准备 Python 环境
- 第 2 步:安装依赖
- ✅ 第 3 步:运行项目主入口
- 报错:
- 报错:
- **降级 Python 到 3.10 或 3.11**
- 推荐版本:
- 创建 Python 3.10 的 Conda 环境:
- 报错:
- 报错:
- 使用 `pip` 创建虚拟环境:
- 激活虚拟环境:
- 报错提示[ROOP.CORE] ffmpeg is not installed.缺少ffmpeg :
- 安装ffmpeg
- 报错:
- 用 Conda 命令速查表:
声明:
这款软件旨在为人工智能生成的媒体产业做出积极贡献,帮助艺术家完成角色动画和服装模型等任务。
我们意识到潜在的道德问题,并已采取措施防止该软件被用于不适当的内容,如裸体。
用户应遵守当地法律,负责任地使用本软件。如果使用真实面孔,请征得同意,并在分享时明确标记深度伪造。开发者不对用户的行为负责。
项目地址:s0md3v/roop: one-click face swap
克隆项目
git clone https://github.com/s0md3v/roop.git
cd roop
第 1 步:准备 Python 环境
-
安装 Python(通常使用 Python 3.8+)
# 我是3.13.3 python --version
-
创建虚拟环境(推荐)
python -m venv venv source venv/bin/activate # Linux/macOS venv\Scripts\activate # Windows
第 2 步:安装依赖
根据你提供的信息,有两个依赖文件:
requirements.txt
(常规环境)requirements-headless.txt
(无头环境,如服务器)
运行其中之一:
pip install -r requirements.txt
# 或者
pip install -r requirements-headless.txt
✅ 第 3 步:运行项目主入口
通常项目入口是 run.py
,所以你可以运行:
python run.py
ui.json
: UI 配置
.flake8
、mypy.ini
: 用于代码检查,不影响运行
报错:
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Cannot import ‘setuptools.build_meta’
解决方法:
# 先升级 pip、setuptools、wheel
pip install --upgrade pip setuptools wheel
#继续 pip install -r requirements.txt
报错:
AttributeError: module ‘pkgutil’ has no attribute ‘ImpImporter’. Did you mean: ‘zipimporter’?
因为 Python 3.12 起,官方 移除了 pkgutil.ImpImporter
,而一些旧版本的包还在使用它。
降级 Python 到 3.10 或 3.11
这个是最靠谱的做法,尤其是当项目使用的是深度学习、AI、图形库等——这些库对 Python 版本兼容性要求很高。
推荐版本:
- Python 3.10.13 ✅(兼容性好,社区常用)
- 或 Python 3.11.x ✅
下载python低版本:https://www.python.org/downloads/release/python-31013/
推荐下载anaconda:Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
官网:Anaconda Documentation - Anaconda
这个是最新的:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Windows-x86_64.exe
使用conda命令来设置镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
更新conda以确保使用新的配置
conda update conda
验证配置
conda config --show channels
创建 Python 3.10 的 Conda 环境:
conda create -n roop310 python=3.10
创建完成后,激活它:
conda activate roop310
然后就可以安装项目依赖啦:
# 我注释了requirements.txt中这句,不知道为啥阿里镜像特别慢 # --extra-index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt
报错:
error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
打开这个链接(微软官网)
👉 https://visualstudio.microsoft.com/visual-cpp-build-tools/
点击下载 “Build Tools for Visual Studio”
下载后运行安装程序(vs_BuildTools.exe
),在安装选项中勾选:
✅ C++ build tools(我用的2022)
✅ 安装项中至少包含:
- MSVC v14.x
- Windows 10 SDK(或 Windows 11 SDK)
- CMake
- Ninja(可选)
安装完成后,重启电脑(推荐),我没重启
报错:
ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchaudio 2.6.0 requires torch==2.6.0, but you have torch 2.1.2 which is incompatible.
这个时候大概率是包冲突了,创建个新的虚拟环境
使用 pip
创建虚拟环境:
python -m venv myenv
激活虚拟环境:
-
Linux/macOS:
source myenv/bin/activate
-
Windows:
myenv\Scripts\activate
继续
pip install -r requirements.txt
出现安装成功了
Installing collected packages: wcwidth, tk, mpmath, lmdb, libclang, flatbuffers, easydict, addict, wrapt, wheel, urllib3, typing-extensions, tomli, tkinterdnd2, threadpoolctl, termcolor, tensorflow-io-gcs-filesystem, tensorflow-estimator, tensorboard-data-server, sympy, soupsieve, six, pyyaml, PySocks, pyreadline3, pyparsing, pyasn1, psutil, protobuf, prettytable, platformdirs, pillow, packaging, opt-einsum, oauthlib, numpy, networkx, MarkupSafe, markdown, llvmlite, kiwisolver, keras, joblib, idna, grpcio, gast, future, fsspec, fonttools, filelock, darkdetect, cython, cycler, colorama, charset-normalizer, certifi, cachetools, absl-py, yapf, werkzeug, tqdm, tifffile, scipy, rsa, requests, python-dateutil, pyasn1-modules, opencv-python-headless, opencv-python, onnx, numba, lazy-loader, jinja2, imageio, humanfriendly, h5py, google-pasta, customtkinter, contourpy, beautifulsoup4, astunparse, torch, tb-nightly, scikit-learn, scikit-image, requests-oauthlib, matplotlib, google-auth, coloredlogs, torchvision, qudida, onnxruntime-gpu, google-auth-oauthlib, gdown, filterpy, tensorboard, facexlib, basicsr, albumentations, tensorflow-intel, insightface, gfpgan, tensorflow, opennsfw2
Successfully installed MarkupSafe-3.0.2 PySocks-1.7.1 absl-py-2.2.2 addict-2.4.0 albumentations-1.3.1 astunparse-1.6.3 basicsr-1.4.2 beautifulsoup4-4.13.4 cachetools-5.5.2 certifi-2025.1.31 charset-normalizer-3.4.1 colorama-0.4.6 coloredlogs-15.0.1 contourpy-1.3.2 customtkinter-5.2.0 cycler-0.12.1 cython-3.0.12 darkdetect-0.8.0 easydict-1.13 facexlib-0.3.0 filelock-3.18.0 filterpy-1.4.5 flatbuffers-25.2.10 fonttools-4.57.0 fsspec-2025.3.2 future-1.0.0 gast-0.4.0 gdown-5.2.0 gfpgan-1.3.8 google-auth-2.39.0 google-auth-oauthlib-1.0.0 google-pasta-0.2.0 grpcio-1.71.0 h5py-3.13.0 humanfriendly-10.0 idna-3.10 imageio-2.37.0 insightface-0.7.3 jinja2-3.1.6 joblib-1.4.2 keras-2.13.1 kiwisolver-1.4.8 lazy-loader-0.4 libclang-18.1.1 llvmlite-0.44.0 lmdb-1.6.2 markdown-3.8 matplotlib-3.10.1 mpmath-1.3.0 networkx-3.4.2 numba-0.61.2 numpy-1.24.3 oauthlib-3.2.2 onnx-1.14.0 onnxruntime-gpu-1.15.1 opencv-python-4.8.0.74 opencv-python-headless-4.11.0.86 opennsfw2-0.10.2 opt-einsum-3.4.0 packaging-24.2 pillow-10.0.0 platformdirs-4.3.7 prettytable-3.16.0 protobuf-4.23.4 psutil-5.9.5 pyasn1-0.6.1 pyasn1-modules-0.4.2 pyparsing-3.2.3 pyreadline3-3.5.4 python-dateutil-2.9.0.post0 pyyaml-6.0.2 qudida-0.0.4 requests-2.32.3 requests-oauthlib-2.0.0 rsa-4.9.1 scikit-image-0.24.0 scikit-learn-1.6.1 scipy-1.15.2 six-1.17.0 soupsieve-2.6 sympy-1.13.3 tb-nightly-2.20.0a20250415 tensorboard-2.13.0 tensorboard-data-server-0.7.2 tensorflow-2.13.0 tensorflow-estimator-2.13.0 tensorflow-intel-2.13.0 tensorflow-io-gcs-filesystem-0.31.0 termcolor-3.0.1 threadpoolctl-3.6.0 tifffile-2025.3.30 tk-0.1.0 tkinterdnd2-0.3.0 tomli-2.2.1 torch-2.1.2 torchvision-0.16.2 tqdm-4.65.0 typing-extensions-4.5.0 urllib3-2.4.0 wcwidth-0.2.13 werkzeug-3.1.3 wheel-0.45.1 wrapt-1.17.2 yapf-0.43.0[notice] A new release of pip is available: 23.0.1 -> 25.0.1
[notice] To update, run: python.exe -m pip install --upgrade pip
idea中配置
现有环境配置上之前创建的那个环境的python.exe
找2图片放到项目目录,加上入参执行:
-s source_face.jpg -t target_image.jpg -o output_image.jpg --frame-processor face_swapper
报错提示[ROOP.CORE] ffmpeg is not installed.缺少ffmpeg :
安装ffmpeg
各个环境的Download FFmpeg
windows的ffmpeg-release-full.7z.ver .sha256
装好后配置环境变量,在idea配置入参一直找不到ffmpeg,所以在anaconda命令窗口执行
python run.py -s source_face.jpg -t target_image.jpg -o output_image.jpg --frame-processor face_swapper
报错:
File “D:\work\ai\roop-main\roop-main\roop\processors\frame\face_swapper.py”, line 37, in pre_check
conditional_download(download_directory_path, [‘https://huggingface.co/CountFloyd/deepfake/resolve/main/inswapper_128.onnx’])
这个时候需要魔法了,不然这个地址无法访问。
感觉还是很耗费流量的
这是比较喜欢这俩明星,所以用这俩图片吧,张替换章的图片,仅作为技术参考,如有侵权立即删除
第二天来了开开电脑没用魔法,直接在idea中运行也能成功了,应该是ffmpeg环境变量重启电脑生效了,使用的资源用魔法下载下来可以继续用。
用 Conda 命令速查表:
命令 | 功能 |
---|---|
conda create -n envname python=3.10 | 创建新环境 |
conda activate envname | 进入环境 |
conda deactivate | 退出环境 |
conda env list | 查看已有环境 |
conda remove -n envname --all | 删除环境 |
conda install packagename | 安装包 |
conda list | 查看当前环境的包 |