OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

ModuleNotFoundError: No module named 'torch' when installing xformers for Stable Diffusion on Macbook M2 Max

  • Thread starter Thread starter HowardC
  • Start date Start date
H

HowardC

Guest
I'm working on Stable Diffusion and try to install xformers to train my Lora.

My Computer is Macbook M2 Max and already installed latest python3.11 and pip 23.1.2

Code:
which python3
/Library/Frameworks/Python.framework/Versions/Current/bin/python3
python3 -V                                                                             
Python 3.11.3

which pip3
/Library/Frameworks/Python.framework/Versions/Current/bin/pip3
pip3 -V
pip 23.1.2 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)

But every time when I use below cmd:

Code:
pip3 install xformers

I'll get message as below:

Code:
Collecting xformers
  Using cached xformers-0.0.20.tar.gz (7.6 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [21 lines of output]
      Traceback (most recent call last):
        File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 488, in run_setup
          self).run_setup(setup_script=setup_script)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 23, in <module>
      ModuleNotFoundError: No module named 'torch'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

I've installed PyTorch using command from offical website:

Code:
pip3 install torch torchvision torchaudio

And when I run test.py using below code:

Code:
import torch
x = torch.rand(5, 3)
print(x)

I'll get correct result as below:

Code:
python3 a.py
tensor([[0.8204, 0.4140, 0.5262],
        [0.1857, 0.3604, 0.3496],
        [0.0620, 0.2303, 0.1033],
        [0.8081, 0.2826, 0.2922],
        [0.1685, 0.5701, 0.9935]])

It means torch has been installed correctly.

Also I can see torch using pip3 list

Code:
torch              2.0.1
torchaudio         2.0.2
torchvision        0.15.2

I also purged all pip3 cache using

Code:
pip cache purge

It doesn't work.

I also restart my computer, doesn't work either.

I saw a lot of Q&A talking about conda, I haven't installed conda so I believe it should not be a conda relative problem.

How to fix this problem? Thanks~
<p>I'm working on Stable Diffusion and try to install xformers to train my Lora.</p>
<p>My Computer is Macbook M2 Max and already installed latest python3.11 and pip 23.1.2</p>
<pre><code>which python3
/Library/Frameworks/Python.framework/Versions/Current/bin/python3
python3 -V
Python 3.11.3

which pip3
/Library/Frameworks/Python.framework/Versions/Current/bin/pip3
pip3 -V
pip 23.1.2 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)
</code></pre>
<p>But every time when I use below cmd:</p>
<pre><code>pip3 install xformers
</code></pre>
<p>I'll get message as below:</p>
<pre><code>Collecting xformers
Using cached xformers-0.0.20.tar.gz (7.6 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [21 lines of output]
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
self.run_setup()
File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 488, in run_setup
self).run_setup(setup_script=setup_script)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/private/var/folders/05/3wghcmr93436gfgb3ty5mnmm0000gn/T/pip-build-env-3da38ps7/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup
exec(code, locals())
File "<string>", line 23, in <module>
ModuleNotFoundError: No module named 'torch'
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
</code></pre>
<p>I've installed PyTorch using command from offical website:</p>
<pre><code>pip3 install torch torchvision torchaudio
</code></pre>
<p>And when I run test.py using below code:</p>
<pre><code>import torch
x = torch.rand(5, 3)
print(x)
</code></pre>
<p>I'll get correct result as below:</p>
<pre><code>python3 a.py
tensor([[0.8204, 0.4140, 0.5262],
[0.1857, 0.3604, 0.3496],
[0.0620, 0.2303, 0.1033],
[0.8081, 0.2826, 0.2922],
[0.1685, 0.5701, 0.9935]])
</code></pre>
<p>It means torch has been installed correctly.</p>
<p>Also I can see torch using pip3 list</p>
<pre><code>torch 2.0.1
torchaudio 2.0.2
torchvision 0.15.2
</code></pre>
<p>I also purged all pip3 cache using</p>
<pre><code>pip cache purge
</code></pre>
<p>It doesn't work.</p>
<p>I also restart my computer, doesn't work either.</p>
<p>I saw a lot of Q&A talking about conda, I haven't installed conda so I believe it should not be a conda relative problem.</p>
<p>How to fix this problem? Thanks~</p>
 

Latest posts

M
Replies
0
Views
1
Meliodas Dragon
M
Top