-1

I bought MacBook Air on m1 and downloaded PyCharm for work. When I try run my project on aiogram, it does not work. It gives this traceback:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 70, in <module>
    import cchardet as chardet
ModuleNotFoundError: No module named 'cchardet'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/danilapachev/Desktop/projects/06_07_bot_organization/bot.py", line 1, in <module>
    from aiogram import Bot, Dispatcher, executor, types
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiogram/__init__.py", line 9, in <module>
    from . import bot
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiogram/bot/__init__.py", line 1, in <module>
    from . import api
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiogram/bot/api.py", line 6, in <module>
    import aiohttp
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/__init__.py", line 6, in <module>
    from .client import (
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/client.py", line 59, in <module>
    from .client_reqrep import (
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 72, in <module>
    import charset_normalizer as chardet  # type: ignore[no-redef]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path, is_binary
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/charset_normalizer/cd.py", line 9, in <module>
    from .md import is_suspiciously_successive_range
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/charset_normalizer/md.cpython-311-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/charset_normalizer/md.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/charset_normalizer/md.cpython-311-darwin.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/charset_normalizer/md.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')) 

I try this commands:

$ arch -arm64 brew install llvm

$ sudo gem install ffi

and try

pipx uninstall aiogram 

pipx install aiogram
Carson
  • 2,700
  • 11
  • 24
Danya
  • 7
  • 2
  • This seems to be a bug in `charset_normalizer`. `pip uninstall charset-normalizer; pip install chardet`. – AKX Jul 18 '23 at 17:28
  • Oh, thanks, but I type pip install charset_normalizer after pip install chardet – Danya Jul 18 '23 at 17:31
  • It looks like this is the same issue as [this](https://stackoverflow.com/questions/72920577/mach-o-file-but-is-an-incompatible-architecture-have-arm64-need-x86-64) – Carson Jul 18 '23 at 17:32
  • @ДаняПачев Please _uninstall_ `charset_normalizer` - `aiohttp` should work fine without it if `chardet` is installed. – AKX Jul 18 '23 at 17:33
  • 1
    Error message means exactly what it says; you're trying to load an Intel library from a native-ARM Python interpreter. One way to avoid this, btw, is to use [Nix](https://nixos.org/) to install both your Python interpreter _and_ your Python libraries; it does all its builds in isolated sandboxes so you can't get a mix of some things from one toolchain and some other things from another, as can happen with pip and other more conventional tools. – Charles Duffy Jul 18 '23 at 17:44
  • @CharlesDuffy Maybe telling people to use Nix instead of, you know, virtualenvs to begin with, is a bit of a drastic move... – AKX Jul 18 '23 at 17:52
  • @AKX, it surely is, which is why I'm keeping it to a comment; for answers I try to be more serious. (But for my own use, I _do_ consider nix devshells far superior; it's some extra work, but work that buys a lot of reproducibility/portability/etc) – Charles Duffy Jul 18 '23 at 17:57

1 Answers1

0

In my situation the issue is resolved with the following commands:

pip uninstall charset-normalizer
pip install charset-normalizer

thanks community

postylem
  • 1,185
  • 12
  • 26
Danya
  • 7
  • 2