soten355 / MetalDiffusion

Stable Diffusion for Intel and Silicon Mac's. Forked from @divamgupta's work
Other
68 stars 5 forks source link

Numpy and other modules not recognized #5

Open mooseknuckleking opened 1 year ago

mooseknuckleking commented 1 year ago

Not recognizing numpy?

Loading program...

...System modules loaded... ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /Users/trevor/MetalDiffusion/dream.py:42 in │ │ │ │ 39 print("\n...[bold]System[/bold] modules loaded...") │ │ 40 │ │ 41 ### Math modules │ │ ❱ 42 import numpy as np │ │ 43 │ │ 44 ### Import Stable Diffusion modules │ │ 45 from stableDiffusionTensorFlow.stableDiffusion import StableDiffusion │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ argparse = <module 'argparse' from │ │ │ │ '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py'> │ │ │ │ box = <module 'rich.box' from │ │ │ │ '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages… │ │ │ │ gc = <module 'gc' (built-in)> │ │ │ │ install = <function install at 0x10a8b27a0> │ │ │ │ os = <module 'os' (frozen)> │ │ │ │ Panel = <class 'rich.panel.Panel'> │ │ │ │ print = <function print at 0x10a5d0360> │ │ │ │ random = <module 'random' from │ │ │ │ '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/random.py'> │ │ │ │ Text = <class 'rich.text.Text'> │ │ │ │ time = <module 'time' (built-in)> │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ModuleNotFoundError: No module named 'numpy' (venv) (base) trevor@Shreks-MBP MetalDiffusion % pip3 install numpy Requirement already satisfied: numpy in /Users/trevor/venv/lib/python3.11/site-packages (1.23.5)

soten355 commented 11 months ago

Strange! Sounds like numpy wasn't installed properly...but then you tried to reinstall it and it was. Have you tried reinstalling MetalDiffusion enitrely?

raffetazarius commented 9 months ago

I'm also running into this! See https://github.com/soten355/MetalDiffusion/discussions/11 Did you manage to resolve it @mooseknuckleking ?

I feel like the Virtual Python Environment "venv" that we're running MetalDiffusion inside (if following your instructions @soten355 ) should not be looking in:

  1. the MacOS System-level Python installation folder ("/Library/Frameworks/Python.framework/Versions/...."), since following your instructions https://github.com/soten355/MetalDiffusion/wiki/Installation

Creating a virtual environment for Python using: python -m venv venv

and activating source venv/bin/activate

and installing dependencies pip install -r requirements.txt --no-cache-dir

actually seems to install:

(a) scripts into a "bin" folder inside the "venv" directory:

/Users//MetalDiffusion/venv/bin

and the dependency "site-packages" into a "lib" folder inside the "venv" directory:

/Users//MetalDiffusion/venv/lib/python3.9/site-packages

  1. Anywhere else on the user's drive, as in my case on https://github.com/soten355/MetalDiffusion/discussions/11

│ │ argparse = <module 'argparse' from │ │ │ │ '/Library/Developer/CommandLineTools/Library/Frameworks/Pyth… │ │ │ │ box = <module 'rich.box' from │ │ │ │ '/Users/username/Library/Python/3.9/lib/python/site-pac… │ │ │ │ gc = <module 'gc' (built-in)> │ │ │ │ install = <function install at 0x10b5e2ca0> │ │ │ │ os = <module 'os' from │ │ │ │ '/Library/Developer/CommandLineTools/Library/Frameworks/Pyth… │ │ │ │ Panel = <class 'rich.panel.Panel'> │ │ │ │ print = <function print at 0x10af85af0> │ │ │ │ random = <module 'random' from │ │ │ │ '/Library/Developer/CommandLineTools/Library/Frameworks/Pyth… │ │ │ │ Text = <class 'rich.text.Text'> │ │ │ │ time = <module 'time' (built-in)> │ │

it's trying to find the modules in the Xcode CommandLineTools folder!

/Library/Developer/CommandLineTools/Library/Frameworks/....

and

/Users/username/Library/Python/3.9/lib/python/....


@soten355 - I think you've missed a step in your installation instructions - somehow the venv environment we're using for MetalDiffusion needs to be configured to look in the correct location for modules/frameworks/etc. It seems like dream.py is looking in unpredictable locations based on how the user has their MacOS Python installation(??) configured (which shouldn't matter if you're directing us to run MetalDiffusion within a Python venv inside the MetalDiffusion folder, right?).

Where/how can we SET the configuration paths for MetalDiffusion correctly?

soten355 commented 9 months ago

@raffetazarius This is so strange! The reason I designed the installation around virtual environments is to avoid just this.

When using a virtual environment, it will install the library dependencies into the /venv/lib/python3.9/site-packages. This keeps the virtual environment independent of the global environment.

Are you running MetalDiffusion in the virtual environment? For example:

source venv/bin/activate
python dream.py
raffetazarius commented 9 months ago

@raffetazarius This is so strange! The reason I designed the installation around virtual environments is to avoid just this.

When using a virtual environment, it will install the library dependencies into the /venv/lib/python3.9/site-packages. This keeps the virtual environment independent of the global environment.

Are you running MetalDiffusion in the virtual environment? For example:

source venv/bin/activate
python dream.py

Yes, I was running it in the virtual environment.

It seems that my system was looking in non-venv locations for Python though. I did a big cleanup of all the Python versions I had installed on my machine though, but I also decided to remove MetalDiffusion and just focus on getting A1111 up and running on my rig. I'll update this thread if I decide to test out MetalDiffusion again.

Do you leverage tensorflow-metal in MetalDiffusion? https://developer.apple.com/metal/tensorflow-plugin/

soten355 commented 9 months ago

Hmmm, you might be missing a step during installation or did something extra on accident. When running a code in a virtual environment, it will only reference the libraries in the environment; it's kind of a basic Python method.


Yes, MetalDiffusion utiliizes TensforFlow as a render framework. To use it, go to Advanced Settings and select TensorFlow as the render framework. Couple notes:

It will use the GPU

It will not use Diffusers models, but it WILL use safetenors and ckpt's

It does not currently support SDXL or LoRA's (either XL or not)


If you have any other questions regarding TensorFlow, please open a new issue. For now, let's keep this convo strictly about library dependencies in a virtual environment.