在Mac M1上安装python依赖项时出现错误

vuktfyat  于 2023-01-01  发布在  Python
关注(0)|答案(3)|浏览(435)

我正在尝试pip安装一个依赖名为fastrank,目前正在安装在2个不同的苹果英特尔芯片.然而,当我尝试运行它在两个不同的mac的M1芯片,我得到下面的错误:

***Collecting fastrank
  Using cached fastrank-0.7.0.tar.gz (52 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      ⚠️  Warning: Please use maturin in pyproject.toml with a version constraint, e.g. `requires = ["maturin>=0.12,<0.13"]`. This will become an error.
      💥 maturin failed
        Caused by: Cargo metadata failed. Does your crate compile with `cargo build`?
        Caused by: `cargo metadata` exited with an error:     Updating crates.io index
      warning: spurious network error (2 tries remaining): http parser error: stream ended at an unexpected time; class=Http (34)
      warning: spurious network error (1 tries remaining): http parser error: stream ended at an unexpected time; class=Http (34)
      error: failed to get `bzip2` as a dependency of package `fastrank v0.7.0 (/private/var/folders/5l/sppq3g8556nffpc74l_54zv40000gn/T/pip-install-ugbpj9al/fastrank_b60c765ae0df4f76b49d90ab4a21f9f2)`
      
      Caused by:
        failed to load source for dependency `bzip2`
      
      Caused by:
        Unable to update registry `crates-io`
      
      Caused by:
        failed to fetch `https://github.com/rust-lang/crates.io-index`
      
      Caused by:
        network failure seems to have happened
        if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
        https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
      
      Caused by:
        http parser error: stream ended at an unexpected time; class=Http (34)
      Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/private/var/folders/5l/sppq3g8556nffpc74l_54zv40000gn/T/pip-modern-metadata-hdyh51_d', '--interpreter', '/Users/chinwekele/.pyenv/versions/3.7.13/bin/python3']' returned non-zero exit status 1.
      Checking for Rust toolchain....
      Running `maturin pep517 write-dist-info --metadata-directory /private/var/folders/5l/sppq3g8556nffpc74l_54zv40000gn/T/pip-modern-metadata-hdyh51_d --interpreter /Users/chinwekele/.pyenv/versions/3.7.13/bin/python3`
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

有人知道如何解决这个错误吗?我试过使用Rosseta终端,试过下载和运行各种软件包,以为它们会有帮助,但都没有工作。请回复。

gblwokeq

gblwokeq1#

对于Mac,如果你使用Conda,这个问题有一个可能的解决方法。这个方法是在Mac上创建一个x86环境,然后进行PIP安装。

conda create -n <name>
conda activate <name>
conda config --env --set subdir osx-64
conda install python=3.8

这里我选择了Python 3.8,但是您也可以选择其他版本。

9w11ddsr

9w11ddsr2#

1.在rosetta终端中安装x86自制程序,如here所述
1.然后使用此命令安装python版本(例如3.7)

arch -x86_64 brew install python@3.7

1.然后使用正确的x86版本的pip(位于x86python安装旁边)安装fastrank

/usr/local/Cellar/python@3.7/3.7.13_1/bin/pip3 install fastrank

为了让一切变得更简单(这样你就不必每次都提供完整的路径),你可以在.zhsrc中为intel x86 pip和python创建一个别名:

alias ipython='/usr/local/Cellar/python@3.7/3.7.13_1/bin/python3.7'
alias ipip='/usr/local/Cellar/python@3.7/3.7.13_1/bin/pip3'

并在您希望使用英特尔x86版本时使用ipipipython

vxqlmq5t

vxqlmq5t3#

这是对@Marcelo Archanjo上面回复的进一步补充。康达为我工作,以下是步骤:
免责声明-我是个新手。如果我所做的看起来很奇怪,你知道为什么:)
1.如果您的Mac m1没有Rosetta2,请安装并启用它-see source

    • 我只执行了"验证您使用的是Rosetta终端"的步骤

1.在启用Rosetta2的终端中安装Miniconda3 x86_64-source
1.如果出现错误"zsh:未找到命令:conda "出现在最后一步中,在同一终端中,使用

source /Users/[user name here]/opt/miniconda3/bin/activate

1.导航到编辑器的终端--我的终端是VSCode。如果你还没有使用Miniconda3intel环境,那么请执行以下操作来查看你安装的Conda环境列表

conda env list

1.激活Intel环境。它是"conda activate",后跟env列表中的路径。它应该如下所示

conda activate /Users/[user name here]/[intel env name here]

1.在condaintelenv下,安装所需的python版本和依赖项
我在康达之前尝试过,但没有成功:

  • 使用pyenv和venv安装python
  • 使用VS代码的内置创建环境工具source

如果你仍然在你的repo中看到错误,确保你需要的所有依赖项都安装在这个环境下

相关问题