Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradio and M1 macbook #1940

Closed
1 task done
keunwoochoi opened this issue Aug 2, 2022 · 13 comments
Closed
1 task done

Gradio and M1 macbook #1940

keunwoochoi opened this issue Aug 2, 2022 · 13 comments
Labels
bug Something isn't working

Comments

@keunwoochoi
Copy link

Describe the bug

Hi!

Related to #1369, I also can't run Gradio on my M1 Macbook.

Unlike the answer #1369, It doesn't seem to be about transformers library.

Here's the error message I get.

Traceback (most recent call last):
  File "/Users/keunwoo/Codes/ssg/deployment/prototype_v1/main.py", line 1, in <module>
    import gradio as gr
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/__init__.py", line 3, in <module>
    import gradio.components as components
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/components.py", line 36, in <module>
    from gradio import media_data, processing_utils
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/processing_utils.py", line 13, in <module>
    from gradio import encryptor
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/encryptor.py", line 2, in <module>
    from Crypto.Cipher import AES
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Cipher/__init__.py", line 27, in <module>
    from Crypto.Cipher._mode_ecb import _create_ecb_cipher
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Cipher/_mode_ecb.py", line 35, in <module>
    raw_ecb_lib = load_pycryptodome_raw_lib("Crypto.Cipher._raw_ecb", """
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/_raw_api.py", line 309, in load_pycryptodome_raw_lib
    raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-darwin.so', Cannot load '_raw_ecb.abi3.so': cannot load library '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so': dlopen(/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so, 0x0002): tried: '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so', Not found '_raw_ecb.so'

Macbook M1, miniforge, python3.9. it's coming from gradio/encryptor, line 2,

    from Crypto.Cipher import AES

Anyone having the same issue?

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

import gradio as gr

Screenshot

No response

Logs

Traceback (most recent call last):
  File "/Users/keunwoo/Codes/ssg/deployment/prototype_v1/main.py", line 1, in <module>
    import gradio as gr
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/__init__.py", line 3, in <module>
    import gradio.components as components
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/components.py", line 36, in <module>
    from gradio import media_data, processing_utils
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/processing_utils.py", line 13, in <module>
    from gradio import encryptor
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/gradio/encryptor.py", line 2, in <module>
    from Crypto.Cipher import AES
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Cipher/__init__.py", line 27, in <module>
    from Crypto.Cipher._mode_ecb import _create_ecb_cipher
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Cipher/_mode_ecb.py", line 35, in <module>
    raw_ecb_lib = load_pycryptodome_raw_lib("Crypto.Cipher._raw_ecb", """
  File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/_raw_api.py", line 309, in load_pycryptodome_raw_lib
    raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-darwin.so', Cannot load '_raw_ecb.abi3.so': cannot load library '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so': dlopen(/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so, 0x0002): tried: '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_raw_ecb.abi3.so' (no such file), '/usr/lib/_raw_ecb.abi3.so' (no such file).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so', Not found '_raw_ecb.so'

System Info

macbook m1, python3, gradio 2.21.

Severity

blocking upgrade to latest gradio version

@keunwoochoi keunwoochoi added the bug Something isn't working label Aug 2, 2022
@keunwoochoi
Copy link
Author

EDIT: oh, on another conda env with python3.10 it just works. i don't understand why but am closing this issue.

@noahgift
Copy link

Same issue using pip. A HUGE bummer I have to use conda vs pip on gradio. Is this really true?

@freddyaboulton
Copy link
Collaborator

Hi @noahgift ! I'm on an M1 and I can install gradio from pip. Can you post the error you're getting?

@noahgift
Copy link

noahgift commented Aug 29, 2022

(.diff) ➜  stable-diffusion-repo git:(main) ✗ ipython
Python 3.10.4 (main, Apr 26 2022, 19:36:29) [Clang 13.1.6 (clang-1316.0.21.2)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import
  Input In [1]
    import
          ^
SyntaxError: invalid syntax


In [2]: import gradio as gr
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 import gradio as gr

File ~/.diff/lib/python3.10/site-packages/gradio/__init__.py:3, in <module>
      1 import pkgutil
----> 3 import gradio.components as components
      4 import gradio.inputs as inputs
      5 import gradio.outputs as outputs

File ~/.diff/lib/python3.10/site-packages/gradio/components.py:38, in <module>
     35 from ffmpy import FFmpeg
     36 from markdown_it import MarkdownIt
---> 38 from gradio import media_data, processing_utils
     39 from gradio.blocks import Block
     40 from gradio.documentation import document, set_documentation_group

File ~/.diff/lib/python3.10/site-packages/gradio/processing_utils.py:17, in <module>
     14 from ffmpy import FFmpeg, FFprobe, FFRuntimeError
     15 from PIL import Image, ImageOps
---> 17 from gradio import encryptor
     19 with warnings.catch_warnings():
     20     warnings.simplefilter("ignore")  # Ignore pydub warning if ffmpeg is not installed

File ~/.diff/lib/python3.10/site-packages/gradio/encryptor.py:2, in <module>
      1 from Crypto import Random
----> 2 from Crypto.Cipher import AES
      3 from Crypto.Hash import SHA256
      6 def get_key(password: str) -> bytes:

File ~/.diff/lib/python3.10/site-packages/Crypto/Cipher/__init__.py:27, in <module>
      1 #
      2 # A block cipher is instantiated as a combination of:
      3 # 1. A base cipher (such as AES)
   (...)
     22 #
     23 # where mode_state is a a pointer to base_cipher_state plus mode-specific data.
     25 import os
---> 27 from Crypto.Cipher._mode_ecb import _create_ecb_cipher
     28 from Crypto.Cipher._mode_cbc import _create_cbc_cipher
     29 from Crypto.Cipher._mode_cfb import _create_cfb_cipher

File ~/.diff/lib/python3.10/site-packages/Crypto/Cipher/_mode_ecb.py:35, in <module>
     27 __all__ = [ 'EcbMode' ]
     29 from Crypto.Util._raw_api import (load_pycryptodome_raw_lib,
     30                                   VoidPointer, create_string_buffer,
     31                                   get_raw_buffer, SmartPointer,
     32                                   c_size_t, c_uint8_ptr,
     33                                   is_writeable_buffer)
---> 35 raw_ecb_lib = load_pycryptodome_raw_lib("Crypto.Cipher._raw_ecb", """
     36                     int ECB_start_operation(void *cipher,
     37                                             void **pResult);
     38                     int ECB_encrypt(void *ecbState,
     39                                     const uint8_t *in,
     40                                     uint8_t *out,
     41                                     size_t data_len);
     42                     int ECB_decrypt(void *ecbState,
     43                                     const uint8_t *in,
     44                                     uint8_t *out,
     45                                     size_t data_len);
     46                     int ECB_stop_operation(void *state);
     47                     """
     48                                         )
     51 class EcbMode(object):
     52     """*Electronic Code Book (ECB)*.
     53 
     54     This is the simplest encryption mode. Each of the plaintext blocks
   (...)
     65     :undocumented: __init__
     66     """

File ~/.diff/lib/python3.10/site-packages/Crypto/Util/_raw_api.py:309, in load_pycryptodome_raw_lib(name, cdecl)
    307     except OSError as exp:
    308         attempts.append("Cannot load '%s': %s" % (filename, str(exp)))
--> 309 raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))

OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-310-darwin.so', Cannot load '_raw_ecb.abi3.so': cannot load library '/Users/noahgift/.diff/lib/python3.10/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so': dlopen(/Users/noahgift/.diff/lib/python3.10/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so, 0x0002): tried: '/Users/noahgift/.diff/lib/python3.10/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/noahgift/.diff/lib/python3.10/site-packages/Crypto/Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/noahgift/.diff/lib/python3.10/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so', Not found '_raw_ecb.so'

@noahgift
Copy link

Also verified it fails on 3.9

(.diff39) ➜  stable-diffusion-repo git:(main) ✗ python3.9
Python 3.9.13 (main, May 24 2022, 21:13:51) 
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gradio as gr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/noahgift/.diff39/lib/python3.9/site-packages/gradio/__init__.py", line 3, in <module>
    import gradio.components as components
  File "/Users/noahgift/.diff39/lib/python3.9/site-packages/gradio/components.py", line 38, in <module>
    from gradio import media_data, processing_utils
  File "/Users/noahgift/.diff39/lib/python3.9/site-packages/gradio/processing_utils.py", line 17, in <module>
    from gradio import encryptor
  File "/Users/noahgift/.diff39/lib/python3.9/site-packages/gradio/encryptor.py", line 2, in <module>
    from Crypto.Cipher import AES
  File "/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Cipher/__init__.py", line 27, in <module>
    from Crypto.Cipher._mode_ecb import _create_ecb_cipher
  File "/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Cipher/_mode_ecb.py", line 35, in <module>
    raw_ecb_lib = load_pycryptodome_raw_lib("Crypto.Cipher._raw_ecb", """
  File "/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Util/_raw_api.py", line 309, in load_pycryptodome_raw_lib
    raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-darwin.so', Cannot load '_raw_ecb.abi3.so': cannot load library '/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so': dlopen(/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so, 0x0002): tried: '/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/noahgift/.diff39/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so', Not found '_raw_ecb.so'

@freddyaboulton
Copy link
Collaborator

@noahgift This is similar to the original error @keunwoochoi posted and it's the one in this thread but I'm not sure what the best fix is.

This is what works for me - I do create a fresh env with conda but install via pip:

conda create -n test2 python=3.10 pip -y
pip install gradio

@noahgift
Copy link

@freddyaboulton I was not able to replicate that fix, and preferably a non conda install would be ideal.

I believe the issue is that gradio needs to link to an arm64e i.e. M1 compiled package for Crypto. Happy to compile this myself if forced to, but seems like a package issue with gradio on M1.

b
    raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-darwin.so', Cannot load '_raw_ecb.abi3.so': cannot load library '/Users/noahgift/.diff/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so': dlopen(/Users/noahgift/.diff/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so, 0x0002): tried: '/Users/noahgift/.diff/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/noahgift/.diff/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/noahgift/.diff/lib/python3.9/site-packages/Crypto/Util/../Cipher/_raw_ecb.abi3.so', Not found '_raw_ecb.so'
>>> exit()

@steysie
Copy link

steysie commented Dec 16, 2022

The issue is still there for MacOS with M1

System Info
MacOS with M1, gradio 3.14.0, pycryptodome 3.16 (also checked downgrading to 3.14)

Are there any stable solutions to this problem?

@ariraz513
Copy link

ariraz513 commented Dec 27, 2022

what worked for me is installing miniconda and placing it in a directory named opt
/Users/your username/opt/miniconda3
for installing auto 1111 stable diffusion web ui.

don't know why.

@steysie
Copy link

steysie commented Dec 29, 2022

Gradio finally worked on M1 after uninstalling pycryptodome through pip and installing it back from conda. Looks like when we install gradio from pip, it installs the pip version of pycryptodome which doesn't have M1 bindings.

pip uninstall pycryptodome
conda install pycryptodome

@abidlabs
Copy link
Member

Thanks for the info @steysie! @aliabid94 I think we should just remove the encryption module in 4.0 since it's rarely ever used

@Rayman96
Copy link

Rayman96 commented Jan 5, 2023

conda install pycryptodome

Thanks so much, it works on my m1 mac

@simonron
Copy link

Sadly, in Sonoma, on my M1 it fails.

Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [18 lines of output]
Traceback (most recent call last):
File "", line 2, in
File "", line 34, in
File "/private/var/folders/8s/b4wcv68d365d0gfk5z9cqwc00000gn/T/pip-install-ux0lwrl1/ffmpy_975325ddf67943829231d5cfc9633169/setup.py", line 6, in
setup(
File "/Users/simonanthony/miniconda3/lib/python3.11/site-packages/setuptools/init.py", line 106, in setup
_install_setup_requires(attrs)
File "/Users/simonanthony/miniconda3/lib/python3.11/site-packages/setuptools/init.py", line 77, in _install_setup_requires
dist.parse_config_files(ignore_option_errors=True)
File "/Users/simonanthony/miniconda3/lib/python3.11/site-packages/setuptools/dist.py", line 902, in parse_config_files
self._parse_config_files(filenames=inifiles)
File "/Users/simonanthony/miniconda3/lib/python3.11/site-packages/setuptools/dist.py", line 745, in _parse_config_files
parser.read_file(reader)
File "/Users/simonanthony/miniconda3/lib/python3.11/configparser.py", line 734, in read_file
self._read(f, source)
File "/Users/simonanthony/miniconda3/lib/python3.11/configparser.py", line 1112, in _read
raise DuplicateOptionError(sectname, optname,
configparser.DuplicateOptionError: While reading from '/Users/simonanthony/.pydistutils.cfg' [line 3]: option 'include_dirs' in section 'build_ext' already exists
[end of output]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants