hacksider / Deep-Live-Cam

real time face swap and one-click video deepfake with only a single image
GNU Affero General Public License v3.0
40.44k stars 5.9k forks source link

No module named 'torch' #73

Closed inobyte closed 3 months ago

inobyte commented 3 months ago

Traceback (most recent call last): File "D:\Download\Deep-Live-Cam\Deep-Live-Cam-DML\run.py", line 3, in from modules import core File "D:\Download\Deep-Live-Cam\Deep-Live-Cam-DML\modules\core.py", line 14, in import torch ModuleNotFoundError: No module named 'torch'

i installed/reinstalled everything, but it slill does not work And yes, a have toutch installed

moaeddy commented 3 months ago

pip install pytorch

mars7233 commented 3 months ago

Traceback (most recent call last): File "D:\Download\Deep-Live-Cam\Deep-Live-Cam-DML\run.py", line 3, in from modules import core File "D:\Download\Deep-Live-Cam\Deep-Live-Cam-DML\modules\core.py", line 14, in import torch ModuleNotFoundError: No module named 'torch'

i installed/reinstalled everything, but it slill does not work And yes, a have toutch installed

After I reused conda to download all the dependent packages, I solved a series of problems such as tourch and other dependencies.

ochristianlove commented 3 weeks ago

HERE IS A SOLUTION FROM FIX I HAD SAME WITH WINWON 11

Steps to Fix: 1) Activate your virtual environment (if not already activated):

C:\Users\Christian\Deep-Live-Cam>venv\Scripts\activate

venv\Scripts\activate

2) Install numpy: Run this command to install numpy in your virtual environment: pip install numpy

3) pip install onnxruntime: pip install onnxruntime

4)Run the script again: Once the required modules are installed, try running your script again: python run.py --execution-provider cuda

YOU MAY GET THIS ERROR

File "C:\Users\Christian\Deep-Live-Cam\run.py", line 3, in from modules import core File "C:\Users\Christian\Deep-Live-Cam\modules\core.py", line 16, in import tensorflow ModuleNotFoundError: No module named 'tensorflow

TO FIX THE ABOVE ERROR: nstall tensorflow: Use the following command to install the TensorFlow package: pip install tensorflow

Note: If you're using a GPU and want to leverage it for TensorFlow, you should install tensorflow-gpu instead: pip install tensorflow-gpu

Run the script again: After installing TensorFlow, run your script again: python run.py --execution-provider cuda

AFATER THIS YOU MAY STILL GET ERROR: ile "C:\Users\Christian\Deep-Live-Cam\run.py", line 3, in from modules import core File "C:\Users\Christian\Deep-Live-Cam\modules\core.py", line 20, in import modules.ui as ui File "C:\Users\Christian\Deep-Live-Cam\modules\ui.py", line 3, in import customtkinter as ctk ModuleNotFoundError: No module named 'customtkinter'

TO FIX THIS: Install customtkinter: You can install the customtkinter package by running: pip install customtkinter

Run the script again: After installing the package, try running the script again: python run.py --execution-provider cuda

YOUR MAY GET THIS ERROR: (venv) C:\Users\Christian\Deep-Live-Cam>python run.py --execution-provider cuda Traceback (most recent call last): File "C:\Users\Christian\Deep-Live-Cam\run.py", line 3, in from modules import core File "C:\Users\Christian\Deep-Live-Cam\modules\core.py", line 20, in import modules.ui as ui File "C:\Users\Christian\Deep-Live-Cam\modules\ui.py", line 5, in import cv2 ModuleNotFoundError: No module named 'cv2'

TO FIX THIS:

Install OpenCV (cv2): You can install OpenCV using the following command: pip install opencv-python

If you also need additional OpenCV functionalities (like video processing support), you might want to install the following package as well: pip install opencv-python-headless

Run the script again: After installing OpenCV, try running the script again: python run.py --execution-provider cuda

YOU MAY GET THIS ERROR: venv) C:\Users\Christian\Deep-Live-Cam>python run.py --execution-provider cuda Traceback (most recent call last): File "C:\Users\Christian\Deep-Live-Cam\run.py", line 3, in from modules import core File "C:\Users\Christian\Deep-Live-Cam\modules\core.py", line 20, in import modules.ui as ui File "C:\Users\Christian\Deep-Live-Cam\modules\ui.py", line 6, in from cv2_enumerate_cameras import enumerate_cameras # Add this import ModuleNotFoundError: No module named 'cv2_enumerate_cameras'

TO FIX THIS:

Install cv2_enumerate_cameras: You can try installing it using pip: pip install cv2-enumerate-cameras

If cv2_enumerate_cameras is not available on PyPI, it may be part of a custom module or repository. In that case, you may need to:

Check the project's documentation or code repository for installation instructions. Alternatively, search for the GitHub repository (or similar) for the module and install it from there. For example, if it’s hosted on GitHub: pip install git+https://github.com/username/cv2_enumerate_cameras.git

Run the script again: Once the module is installed, try running the script again: python run.py --execution-provider cuda

IT MAY SHOW YOU THIS ERROR venv) C:\Users\Christian\Deep-Live-Cam>python run.py --execution-provider cuda Traceback (most recent call last): File "C:\Users\Christian\Deep-Live-Cam\run.py", line 3, in from modules import core File "C:\Users\Christian\Deep-Live-Cam\modules\core.py", line 20, in import modules.ui as ui File "C:\Users\Christian\Deep-Live-Cam\modules\ui.py", line 7, in from PIL import Image, ImageOps ModuleNotFoundError: No module named 'PIL'

TO FIX THIS: Install Pillow (which includes PIL): Run the following command to install Pillow: pip install Pillow

Run the script again: After installing Pillow, try running your script again: python run.py --execution-provider cuda

IT MAY SHOW YOU THIS ERROR aceback (most recent call last): File "C:\Users\Christian\Deep-Live-Cam\run.py", line 3, in from modules import core File "C:\Users\Christian\Deep-Live-Cam\modules\core.py", line 20, in import modules.ui as ui File "C:\Users\Christian\Deep-Live-Cam\modules\ui.py", line 13, in from modules.face_analyser import ( File "C:\Users\Christian\Deep-Live-Cam\modules\face_analyser.py", line 4, in import insightface ModuleNotFoundError: No module named 'insightface'

TO FIX THIS: Install insightface: Install the package using pip: pip install insightface

Run the script again: After the installation completes, try running your script again: python run.py --execution-provider cuda

IT MAY SHOW YOU THIS ERROR:

uilding 'insightface.thirdparty.face3d.mesh.cython.mesh_core_cython' extension 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/ [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for insightface Failed to build insightface ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (insightface)

TO FIX THIS: The error you're encountering indicates that a C++ compiler is required to build the insightface package from source. Specifically, you need Microsoft Visual C++ 14.0 or greater. It happen because didn't check the box for c++ (at the right hand side) during the installer so make sure to check the box for "Desktop development with C++" during installation, download check the box (all c++ build tools and only 1 win 11 sdk) then lunch and continue the fix on Deep Live terminal

3) Install insightface again: After the build tools are installed, you can attempt to install insightface again: pip install insightface

Run the script again: After successful installation, try running your script: python run.py --execution-provider cuda

YOU MAY GET THIS ERROR: RROR: 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. tensorboard 2.10.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 5.28.2 which is incompatible. tensorflow-gpu 2.10.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 5.28.2 which is incompatible. tensorflow-intel 2.17.0 requires keras>=3.2.0, but you have keras 2.10.0 which is incompatible. tensorflow-intel 2.17.0 requires protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3, but you have protobuf 5.28.2 which is incompatible. tensorflow-intel 2.17.0 requires tensorboard<2.18,>=2.17, but you have tensorboard 2.10.1 which is incompatible. Successfully installed PyYAML-6.0.2 albucore-0.0.17 albumentations-1.4.18 annotated-types-0.7.0 colorama-0.4.6 contourpy-1.3.0 cycler-0.12.1 cython-3.0.11 easydict-1.13 eval-type-backport-0.2.0 fonttools-4.54.1 imageio-2.36.0 insightface-0.7.3 joblib-1.4.2 kiwisolver-1.4.7 lazy-loader-0.4 matplotlib-3.9.2 onnx-1.17.0 prettytable-3.11.0 protobuf-5.28.2 pydantic-2.9.2 pydantic-core-2.23.4 pyparsing-3.2.0 python-dateutil-2.9.0.post0 scikit-image-0.24.0 scikit-learn-1.5.2 scipy-1.14.1 threadpoolctl-3.5.0 tifffile-2024.9.20 tqdm-4.66.5 wcwidth-0.2.13

TO FIX THIS:

Uninstall conflicting packages: First, let's uninstall the problematic packages:

pip uninstall protobuf tensorboard keras tensorflow-gpu tensorflow-intel (KERAS and tensorflow only uninstall, it may bring other options to uninstall along)

Install compatible versions: Now, install versions that are compatible with each other: Install the required version of protobuf: pip install protobuf==3.20.3

Install the required version of tensorboard (for TensorFlow 2.17.0): pip install tensorboard==2.17.0

Install a compatible version of tensorflow-gpu or tensorflow-intel (depending on your hardware setup). If you're using a GPU: pip install tensorflow-gpu==2.17.0 (if it show small error ignore, "Could not find a version that satisfies the requirement' but it works)

If you prefer the Intel-optimized version: pip install tensorflow-intel==2.17.0

Install the compatible version of keras: pip install keras==3.2.0

Run your script again: After fixing these dependencies, try running your script again: python run.py --execution-provider cuda

YOU MAY GET THIS ERROR (venv) C:\Users\Christian\Deep-Live-Cam>python run.py --execution-provider cuda usage: run.py [-h] [-s SOURCE_PATH] [-t TARGET_PATH] [-o OUTPUT_PATH] [--frame-processor {face_swapper,face_enhancer} [{face_swapper,face_enhancer} ...]] [--keep-fps] [--keep-audio] [--keep-frames] [--many-faces] [--nsfw-filter] [--map-faces] [--video-encoder {libx264,libx265,libvpx-vp9}] [--video-quality [0-51]] [--live-mirror] [--live-resizable] [--max-memory MAX_MEMORY] [--execution-provider {azure,cpu} [{azure,cpu} ...]] [--execution-threads EXECUTION_THREADS] [-v] run.py: error: argument --execution-provider: invalid choice: 'cuda' (choose from 'azure', 'cpu')

TO FIX THIS: Note that the cuda run code "python run.py --execution-provider cuda " it trying to use the gpu in my pc, this above error show i haven't intalled the requirement for this command and that only cup command can works, for those who dont have gpu you can lunch the Deep Live from here with this command

python run.py --execution-provider cpu

For those with GPU lets proceed to install dependencies with for gpu for this command to work

1) ensure nvidia cuda gpu is installed or repeat to ensure it works : Install CUDA Toolkit 11.8 from

lunch cuda toolkit and let it run

2) Install dependencies: uninstall Existing onnxruntime and onnxruntime-gpu: This ensures that you have a clean environment before installing the specific version: pip uninstall onnxruntime onnxruntime-gpu

Install the Correct Version of onnxruntime-gpu: Install the GPU-enabled version: pip install onnxruntime-gpu==1.16.3

3) Run the Script: Now try running your script with the cuda execution provider: python run.py --execution-provider cuda

it should work now, enjoy cheers

hacksider commented 3 weeks ago

@ochristianlove this is awesome! Can you post this on the Wiki as well? Thanks a lot bro!

ochristianlove commented 3 weeks ago

Also i discovered that even after this it conflicting with older versions of installed requirements files, so it didn't work properly TO FIX: 1) Delete all directory of deeo live cam 2)cd path\to\your\project 3) clone the url from git get clone htts://URL 5) cd to the downloaded clone directory (deep live cam) πŸ˜‚ Am not with my pc so bear with me typing from my phone

And do all this in any prompt Terminal I used powershell as administrator

3) create virtual environment python -m venv venv

4) activate venviromen venv\Scripts\activate

5) it came with it own default requirement.txt so we just make the command pip install -r requirements.txt

6) download the model and put in the model directory in deep live cam folde, also note: inswapper_128_fp16.onnx will be rename again in the model path to old in inswapper_128.onnx (am not sure i renamed were well but the 4kb file is there just use the same file name)

7) uninstall and reinstall

pip uninstall onnxruntime onnxruntime-gpu
pip install onnxruntime-gpu==1.16.3

8)- run the program python run.py --execution-provider cuda

Enjoy (am very impressed 😁 with this tech) tip Enable many faces to keep constant track with your face, bye

hacksider commented 3 weeks ago

Thanks @ochristianlove I will put this on the wiki (will credit you with it as well). Thanks a lot for the help!