InvokeAI icon indicating copy to clipboard operation
InvokeAI copied to clipboard

[bug]: ModuleNotFoundError: No module named 'ldm'

Open smoran opened this issue 2 years ago • 20 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

OS

Windows

GPU

cuda

VRAM

11

What happened?

After installing using Install.bat, running Invoke.bat adds this error.

Do you want to generate images using the
1. command-line
2. browser-based UI
3. open the developer console
Please enter 1, 2 or 3: 2
Starting the InvokeAI browser-based UI..
Traceback (most recent call last):
  File "E:\invokeAI\scripts\invoke.py", line 2, in <module>
    import ldm.invoke.CLI
ModuleNotFoundError: No module named 'ldm'

Adding sys.path.append(".") to invoke.py fixes this, but than the next module is not loaded. It seems the "scripts" folder, doesn't recognize all the modules from the root folder.

Screenshots

image

Additional context

No response

Contact Details

[email protected]

smoran avatar Dec 08 '22 13:12 smoran

I was able to fix this by editing invoke.bat and adding this to the file (has to be done after install.bat as that file is overwritten during install) set PYTHONPATH=%PYTHONPATH%;%cd%

However then I get a failure of (actual path replaced with <path>)

Do you want to generate images using the
1. command-line
2. browser-based UI
3. open the developer console
Please enter 1, 2 or 3: 2
Starting the InvokeAI browser-based UI..
Traceback (most recent call last):
  File "C:\<path>\invokeAI\scripts\invoke.py", line 3, in <module>
    import ldm.invoke.CLI
  File "C:\<path>\invokeAI\ldm\invoke\CLI.py", line 9, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

I think these are different issues but maybe related? Also on Windows

imbeyondboredom avatar Dec 08 '22 18:12 imbeyondboredom

I had the same problem, and added set PYTHONPATH=%PYTHONPATH%;%cd% too, but instead of yaml error, this is what I got:

Starting the InvokeAI browser-based UI..
* Initializing, be patient...
>> Initialization file C:\Users\Barafu/.invokeai found. Loading...
>> InvokeAI runtime directory is "C:\Users\Barafu\invokeai"
Downloading: "https://github.com/DagnyT/hardnet/raw/master/pretrained/train_liberty_with_aug/checkpoint_liberty_with_aug.pth" to C:\Users\Barafu/.cache\torch\hub\checkpoints\checkpoint_liberty_with_aug.pth
100%|██████████████████████████████████████████████████████████████████████████████████████████████| 5.10M/5.10M [00:03<00:00, 1.64MB/s]
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ C:\Software\invokeAI\scripts\invoke.py:4 in <module>                                             │
│                                                                                                  │
│   1 #!/usr/bin/env python                                                                        │
│   2                                                                                              │
│   3 import ldm.invoke.CLI                                                                        │
│ ❱ 4 ldm.invoke.CLI.main()                                                                        │
│   5                                                                                              │
│   6                                                                                              │
│                                                                                                  │
│ C:\Software\invokeAI\ldm\invoke\CLI.py:54 in main                                                │
│                                                                                                  │
│    51 │   print(f'>> InvokeAI runtime directory is "{Globals.root}"')                            │
│    52 │                                                                                          │
│    53 │   # loading here to avoid long delays on startup                                         │
│ ❱  54 │   from ldm.generate import Generate                                                      │
│    55 │                                                                                          │
│    56 │   # these two lines prevent a horrible warning message from appearing                    │
│    57 │   # when the frozen CLIP tokenizer is imported                                           │
│                                                                                                  │
│ C:\Software\invokeAI\ldm\generate.py:133 in <module>                                             │
│                                                                                                  │
│    130 """                                                                                       │
│    131                                                                                           │
│    132                                                                                           │
│ ❱  133 class Generate:                                                                           │
│    134 │   """Generate class                                                                     │
│    135 │   Stores default values for multiple configuration items                                │
│    136 │   """                                                                                   │
│                                                                                                  │
│ C:\Software\invokeAI\ldm\generate.py:267 in Generate                                             │
│                                                                                                  │
│    264 │   │   ), 'call to img2img() must include the init_img argument'                         │
│    265 │   │   return self.prompt2png(prompt, outdir, **kwargs)                                  │
│    266 │                                                                                         │
│ ❱  267 │   from ldm.invoke.generator.inpaint import infill_methods                               │
│    268 │                                                                                         │
│    269 │   def prompt2image(                                                                     │
│    270 │   │   │   self,                                                                         │
│                                                                                                  │
│ C:\Software\invokeAI\ldm\invoke\generator\inpaint.py:25 in <module>                              │
│                                                                                                  │
│    22 infill_methods: list[str] = list()                                                         │
│    23                                                                                            │
│    24 if Globals.try_patchmatch:                                                                 │
│ ❱  25 │   from patchmatch import patch_match                                                     │
│    26 │   if patch_match.patchmatch_available:                                                   │
│    27 │   │   print('>> Patchmatch initialized')                                                 │
│    28 │   │   infill_methods.append('patchmatch')                                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named 'patchmatch'

Barafu avatar Dec 09 '22 06:12 Barafu

I did a full reinstallation of everything - removed the invokeai folder, the anaconda environment... Everything except the downloaded models. Now it works without problems.

Barafu avatar Dec 09 '22 08:12 Barafu

reinstall did not help me.. BUT I have probably 3 different stable diffusion installs so I wonder if the dependencies are conflicting in some way.

imbeyondboredom avatar Dec 09 '22 14:12 imbeyondboredom

I did a clean installation of both, Python 3.10.9 (via the Microsoft Store) and InvokeAI on Windows 11/x64 (10.0.19045.0). I get the following error:

D:\invokeai> . .\invoke.bat
Do you want to generate images using the
1. command-line
2. browser-based UI
3. open the developer console
Please enter 1, 2 or 3: 2
Starting the InvokeAI browser-based UI..
Traceback (most recent call last):
  File "D:\InvokeAI\invokeai\.venv\Scripts\invoke.py", line 3, in <module>
    import ldm.invoke.CLI
ModuleNotFoundError: No module named 'ldm'

I get the same error using:

D:\InvokeAI\invokeai> & D:/InvokeAI/invokeai/.venv/Scripts/Activate.ps1
(.venv) D:\InvokeAI\invokeai\.venv> . ..\invoke.bat

However, when opening the invoke.py file with an IDE, the import is resolved without issues.

I guess there might be a problem with how the environment is set up during install.

MovGP0 avatar Dec 12 '22 21:12 MovGP0

I think the issue is with the Module Search Path. On my system this is:

D:\InvokeAI\invokeai> . .\invoke.bat
Do you want to generate images using the
1. command-line
2. browser-based UI
3. open the developer console
Please enter 1, 2 or 3: 3
Developer Console
Python command is:
C:\Users\movgp\AppData\Local\Microsoft\WindowsApps\python.exe
Python version is:
Python 3.10.9
*************************
You are now in the system shell, with the local InvokeAI Python virtual environment activated,
so that you can troubleshoot this InvokeAI installation as necessary.
*************************
*** Type `exit` to quit this shell and deactivate the Python virtual environment ***
(.venv) D:\InvokeAI\invokeai> python
>>> import sys
>>> sys.path
['', 
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\\python310.zip', 
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\\DLLs', 
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\\lib', 
'C:\\Users\\movgp\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0', 
'C:\\Users\\movgp\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages', 
'C:\\Users\\movgp\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\win32', 
'C:\\Users\\movgp\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\win32\\lib', 
'C:\\Users\\movgp\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\Pythonwin', 
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0', 
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\\lib\\site-packages'
]

However, the packages are located in

D:\InvokeAI\invokeai\.venv\Lib\site-packages

MovGP0 avatar Dec 12 '22 22:12 MovGP0

However, when opening the invoke.py file with an IDE, the import is resolved without issues.

How to Resolve The Issue i'm Stuck With it not working via opening with IDE

nazeerPro avatar Dec 13 '22 07:12 nazeerPro

Ok. Took me a while but finally found a solution. I added an empty init.py (image) file to the scripts directory. This makes the scripts folder a part of a package and allows loading models from the other directories.

image

smoran avatar Dec 13 '22 08:12 smoran

Ok. Took me a while but finally found a solution. I added an empty init.py (image) file to the scripts directory. This makes the scripts folder a part of a package and allows loading models from the other directories.

image

👋 could you please help me I'm newbie stuck with that problem

nazeerPro avatar Dec 13 '22 09:12 nazeerPro

Ok. Took me a while but finally found a solution. I added an empty init.py (image) file to the scripts directory. This makes the scripts folder a part of a package and allows loading models from the other directories. image

👋 could you please help me I'm newbie stuck with that problem

Simply go to the root folder where you installed InvokeAI, and you will see a folder there called "scripts". In it, create a file called "init.py". it should be an empty file. That should do the trick.

smoran avatar Dec 13 '22 12:12 smoran

Not working for me

Ok. Took me a while but finally found a solution. I added an empty init.py (image) file to the scripts directory. This makes the scripts folder a part of a package and allows loading models from the other directories. image

👋 could you please help me I'm newbie stuck with that problem

Simply go to the root folder where you installed InvokeAI, and you will see a folder there called "scripts". In it, create a file called "init.py". it should be an empty file. That should do the trick.

Didn't work for me

nazeerPro avatar Dec 13 '22 13:12 nazeerPro

Not working for me

Ok. Took me a while but finally found a solution. I added an empty init.py (image) file to the scripts directory. This makes the scripts folder a part of a package and allows loading models from the other directories. image

👋 could you please help me I'm newbie stuck with that problem

Simply go to the root folder where you installed InvokeAI, and you will see a folder there called "scripts". In it, create a file called "init.py". it should be an empty file. That should do the trick.

Didn't work for me

You made sure the file name includes underscores? also, please make sure your command line is with admin privileges. If both are true and you still can't make it work, please send a screenshot of the response you are getting.

smoran avatar Dec 13 '22 13:12 smoran

Not working for me

Ok. Took me a while but finally found a solution. I added an empty init.py (image) file to the scripts directory. This makes the scripts folder a part of a package and allows loading models from the other directories. image

👋 could you please help me I'm newbie stuck with that problem

Simply go to the root folder where you installed InvokeAI, and you will see a folder there called "scripts". In it, create a file called "init.py". it should be an empty file. That should do the trick.

Didn't work for me

You made sure the file name includes underscores? also, please make sure your command line is with admin privileges. If both are true and you still can't make it work, please send a screenshot of the response you are getting. 1 2 3 4

After Step 4 When i Enter 1 or 2 it doest work but when i enter 3 it is working for developer console

nazeerPro avatar Dec 13 '22 15:12 nazeerPro

When I installed I don't have a .venv folder. I have re-installed a few times and still no folder. I saw that a few of you all opened a file with an IDE or something. I assumed that kicked off some form of dependency update?

Do you any other steps than the normal install.bat command to create the .venv folder?

imbeyondboredom avatar Dec 14 '22 07:12 imbeyondboredom

When I installed I don't have a .venv folder. I have re-installed a few times and still no folder. I saw that a few of you all opened a file with an IDE or something. I assumed that kicked off some form of dependency update?

Do you any other steps than the normal install.bat command to create the .venv folder?

I should Do Clean Installation

nazeerPro avatar Dec 14 '22 09:12 nazeerPro

Not working for me

Ok. Took me a while but finally found a solution. I added an empty init.py (image) file to the scripts directory. This makes the scripts folder a part of a package and allows loading models from the other directories. image

👋 could you please help me I'm newbie stuck with that problem

Simply go to the root folder where you installed InvokeAI, and you will see a folder there called "scripts". In it, create a file called "init.py". it should be an empty file. That should do the trick.

Didn't work for me

You made sure the file name includes underscores? also, please make sure your command line is with admin privileges. If both are true and you still can't make it work, please send a screenshot of the response you are getting. 1 2 3 4

After Step 4 When i Enter 1 or 2 it doest work but when i enter 3 it is working for developer console

Don't put it in the venv script, rather in the root folder. this is the same folder where invoke.py resides: image image

smoran avatar Dec 14 '22 09:12 smoran

Thanks @smoran I Found The Solution ! In The Begining i installed invokeai in a folder called "new" After Installation i renamed that folder

nazeerPro avatar Dec 14 '22 09:12 nazeerPro

@smoran I've created a new file .\invokeai\.venv\Scripts\__init__.py, but running into the same issue. It's the only folder with an invoke.py file and there doesn't exist a .\invokeai\Scripts folder.

MovGP0 avatar Dec 14 '22 19:12 MovGP0

I ~~soved~~ workarounded the issue by making the following changes to .\invokeai\.venv\Scripts\invoke.py:

#!D:\invokeai\.venv\Scripts\python.exe

import sys
sys.path.insert(0,'D:\invokeai\.venv\Lib\site-packages')

import ldm.invoke.CLI
ldm.invoke.CLI.main()

MovGP0 avatar Dec 14 '22 19:12 MovGP0

I ran into the next issue with a concatenation of path names:

** model stable-diffusion-1.5 could not be loaded: [Errno 2] No such file or directory: 'D:\\InvokeAI\\invokeai\\models\\openai/clip-vit-large-patch14\\models--openai--clip-vit-large-patch14\\refs\\main'
Traceback (most recent call last):
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\ldm\invoke\model_cache.py", line 80, in get_model
    requested_model, width, height, hash = self._load_model(model_name)
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\ldm\invoke\model_cache.py", line 233, in _load_model
    model = instantiate_from_config(omega_config.model)
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\ldm\util.py", line 90, in instantiate_from_config
    return get_obj_from_str(config['target'])(
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\ldm\models\diffusion\ddpm.py", line 658, in __init__
    self.instantiate_cond_stage(cond_stage_config)
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\ldm\models\diffusion\ddpm.py", line 769, in instantiate_cond_stage
    model = instantiate_from_config(config)
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\ldm\util.py", line 90, in instantiate_from_config
    return get_obj_from_str(config['target'])(
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\ldm\modules\encoders\modules.py", line 247, in __init__
    self.tokenizer = CLIPTokenizer.from_pretrained(
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\transformers\tokenization_utils_base.py", line 1760, in from_pretrained
    resolved_vocab_files[file_id] = cached_file(
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\transformers\utils\hub.py", line 409, in cached_file
    resolved_file = hf_hub_download(
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\huggingface_hub\utils\_validators.py", line 124, in _inner_fn
    return fn(*args, **kwargs)
  File "D:\InvokeAI\invokeai\.venv\Lib\site-packages\huggingface_hub\file_download.py", line 1150, in hf_hub_download
    with open(ref_path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\InvokeAI\\invokeai\\models\\openai/clip-vit-large-patch14\\models--openai--clip-vit-large-patch14\\refs\\main'

The path does exist:

D:\InvokeAI\invokeai\models\openai\clip-vit-large-patch14\models--openai--clip-vit-large-patch14\refs> ls

    Directory: D:\InvokeAI\invokeai\models\openai\clip-vit-large-patch14\models--openai--clip-vit-large-patch14\refs

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          14/12/2022    20:48             40 main

So I guess the / instead of the \\ is to blame here. Usually this comes from using string concatenation using + instead of os.path.join(...).

MovGP0 avatar Dec 14 '22 19:12 MovGP0

the easiest solution to this problem is to start the script and select the developers option then run pip install

I ran into this problem after updating today and it was missing the safetensors module...

MordesMortes avatar Jan 19 '23 02:01 MordesMortes

Thanks @smoran I Found The Solution ! In The Begining i installed invokeai in a folder called "new" After Installation i renamed that folder

That was my problem as well. I had to update the VIRTUAL_ENV environment variable in activate.bat to reflect the new directory name.

Bug64 avatar Jan 24 '23 00:01 Bug64

CIRCUMSTANTIAL SOLUTION

I had this exact issue. I erroneously assumed that this was a stand alone app (in that it didn't have a file system "home" and could run from any arbitrary location) since it didn't have the usual windows install experience, when in fact, the directory it is installed in is hardcoded into many of the files during installation as an absolute path.

That said, I experienced the OP's issue because I had moved InvokeAI to a different location in my file system when I decided to consolidate my various SD UIs into one SD subfolder. Moving it back had it working properly. So my two choices, I believe, are ...

  1. be happy with where it is
  2. reinstall it at the location I  really want it

Hope this helps others that in a similar situation.

TimMHoefer avatar Mar 09 '23 16:03 TimMHoefer