简体   繁体   中英

Errors with installing a python dependency on a Mac M1

I am trying to pip install a dependency named fastrank that is currently installing on 2 different apple intel chip. However, when I try running it on two different mac's with M1 chips, I get the following error below:

***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.

Does anyone have any idea how to solve this error? I have tried using a Rosseta terminal, tried downloading and running various packages thinking they would help, but none has worked. Would appreciate a response.

  1. In the rosetta terminal install home-brew for x86 like explained here
  2. Then with this command install a python version (eg 3.7)
arch -x86_64 brew install python@3.7
  1. Then using the correct x86 version of pip (which is located next to the x86 python installation) install fastrank
/usr/local/Cellar/python@3.7/3.7.13_1/bin/pip3 install fastrank

To make everything easier (so you don't have to provide the full path every time) you can create an alias for intel x86 pip and python like so in .zhsrc:

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'

and use ipip and ipython whenever you want to use the intel x86 versions

There is a possible workaround for this problem if you use conda. The idea is to create an X86 environment on the Mac and do your pip install after that.

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

Here I choose python 3.8, but you can choose another version.

This is to add further details to @Marcelo Archanjo's reply above. Conda worked for me, and here are the steps:

DISCLAIMER - I am a newbie. If what I did looks odd, you know why:)

  1. If your Mac m1 doesn't have Rosetta2, install and enable it - see source

    ** I only followed the steps up to "verify that you are using a Rosetta terminal"

  2. Install Miniconda3 x86_64 in the Rosetta2 enabled terminal - source

  3. If the error "zsh: command not found: conda" appears in the last step, in the same terminal, activate Miniconda using

source /Users/[user name here]/opt/miniconda3/bin/activate
  1. Navigate to your editor (mine was vs code)'s terminal. If you are not under the miniconda3 intel environment you have set up already, then do the following to see the list of conda environments you installed
conda env list 
  1. Activate the Intel environment. It is "conda activate" followed by the path in the env list. It should look like this
conda activate /Users/[user name here]/[intel env name here]
  1. Under the conda intel env, install the desired python version and dependencies

MORE INFO

  • Installing python with pyenv and using venv did not work

  • Using VS Code's build in Create Env tool did not work source

  • Ensure absolutely all dependencies you need are installed under this env if you are still seeing errors in your repo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM