使用poetry和pip安装pydantic会引发错误。

huangapple go评论98阅读模式
英文:

Install pydantic using poetry and pip throws ERROR

问题

我使用 poetry 安装了 pydantic。它可以正常工作,但在安装后尝试使用 Pydantic 时会出现以下错误:

E   ImportError: dlopen(/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so, 0x0002): tried: '/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so' (no such file), '/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

然后我尝试了以下操作:

pip uninstall pydantic && python3.9 -m pip install --no-binary :all: pydantic --nocache-dir

来自 poetry 环境,但我收到了以下错误:

creating build/lib.macosx-10.9-universal2-cpython-39/maturin
copying maturin/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/maturin
copying maturin/import_hook.py -> build/lib.macosx-10.9-universal2-cpython-39/maturin
copying maturin/__main__.py -> build/lib.macosx-10.9-universal2-cpython-39/maturin
running egg_info
creating maturin.egg-info
writing maturin.egg-info/PKG-INFO
writing dependency_links to maturin.egg-info/dependency_links.txt
writing requirements to maturin.egg-info/requires.txt
writing top-level names to maturin.egg-info/top_level.txt
writing manifest file 'maturin.egg-info/SOURCES.txt'
reading manifest file 'maturin.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.json' under directory 'src/python_interpreter'
writing manifest file 'maturin.egg-info/SOURCES.txt'
running build_ext
running build_rust
error: can't find Rust compiler

If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.

To update pip, run:

pip install --upgrade pip

and then retry package installation.

If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for maturin
Failed to build maturin
ERROR: Could not build wheels for maturin, which is required to install pyproject.toml-based projects
[end of output]

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

× pip subprocess to install build dependencies 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.

注:我正在使用 arm64 架构的 macOS,而不是您已在日志中注意到的 x86 架构。有任何线索吗?先谢谢了。

英文:

I install pydantic with poetry. It works fine But when try to use Pydantic after installing it throws

E   ImportError: dlopen(/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so, 0x0002): tried: '/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so' (no such file), '/Users/sazzad/Library/Caches/pypoetry/virtualenvs/my-test-project-qHFD2Grb-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

Then I tried this
pip uninstall pydantic && python3.9 -m pip install --no-binary :all: pydantic --nocache-dir from pottery venv

I get this error

            creating build/lib.macosx-10.9-universal2-cpython-39/maturin
            copying maturin/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/maturin
            copying maturin/import_hook.py -> build/lib.macosx-10.9-universal2-cpython-39/maturin
            copying maturin/__main__.py -> build/lib.macosx-10.9-universal2-cpython-39/maturin
            running egg_info
            creating maturin.egg-info
            writing maturin.egg-info/PKG-INFO
            writing dependency_links to maturin.egg-info/dependency_links.txt
            writing requirements to maturin.egg-info/requires.txt
            writing top-level names to maturin.egg-info/top_level.txt
            writing manifest file 'maturin.egg-info/SOURCES.txt'
            reading manifest file 'maturin.egg-info/SOURCES.txt'
            reading manifest template 'MANIFEST.in'
            warning: no files found matching '*.json' under directory 'src/python_interpreter'
            writing manifest file 'maturin.egg-info/SOURCES.txt'
            running build_ext
            running build_rust
            error: can't find Rust compiler
      
            If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
      
            To update pip, run:
      
                pip install --upgrade pip
      
            and then retry package installation.
      
            If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for maturin
      Failed to build maturin
      ERROR: Could not build wheels for maturin, which is required to install pyproject.toml-based projects
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies 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.

Note: I am using macos which arm64 not x86 as you already noticed in the log.

Any clue? thanks in advance.

答案1

得分: 0

pip install --no-binary :all: pydantic==1.10.8

英文:

I used an older version of Pydantic to solve the issue. If someone has a better solution, I am happy to follow.

pip install --no-binary :all: pydantic==1.10.8

huangapple
  • 本文由 发表于 2023年7月28日 01:08:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76782041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定