简体   繁体   English

在 Mac M1 上安装 python 包时出现问题

[英]Problems installing python packages on Mac M1

I want to install python packages listed in the requirements file of my github repo.我想安装 github repo 的需求文件中列出的 python 包。 However, I have problems installing those python packages into my conda environment.但是,我在将这些 python 包安装到我的 conda 环境中时遇到问题。

First of all, I installed conda with Miniforge3-MacOSX-arm64 which supports the M1 with arm64 architecture.首先,我用 Miniforge3-MacOSX-arm64 安装了 conda,它支持带有 arm64 架构的 M1。 However, some specific python packages like onnxruntime I wasn't able to install, because I encountered error messages like that:但是,我无法安装一些特定的 python 软件包,例如 onnxruntime,因为我遇到了这样的错误消息:

ERROR: Could not find a version that satisfies the requirement onnxruntime
ERROR: No matching distribution found for onnxruntime 

I assumed that for those specific python packages there is no support yet for the M1.我假设对于那些特定的 python 包,尚不支持 M1。

Therefore, I pursued another approach.因此,我采用了另一种方法。 I set the settings of Terminal to "Open with Rosetta".我将终端的设置设置为“使用 Rosetta 打开”。 The plan is to install the applications of the intel x86_64 architecture and let Rossetta create the binaries to let run on arm64.计划是安装 intel x86_64 架构的应用程序,并让 Rossetta 创建二进制文件以在 arm64 上运行。 Then I uninstalled miniforge for arm64 and installed miniforge for x86_64 named Miniforge3-MacOSX-x86_64.然后我卸载了 arm64 的 miniforge 并安装了名为 Miniforge3-MacOSX-x86_64 的 x86_64 的 miniforge。 With that setup I was able to install all listed python packages of the requirement file and with pip freeze I can also confirm that they have been installed.通过该设置,我能够安装需求文件的所有列出的 python 包,并且通过pip freeze ,我还可以确认它们已安装。 However, I am somehow not able to use those python packages.但是,我不知何故无法使用那些 python 包。 For instance if I want to run pytest I get the following error:例如,如果我想运行 pytest 我会收到以下错误:

zsh: illegal hardware instruction pytest

I assumed Rossetta takes care of that, that I can use applications for x86_64 also on arm64.我假设 Rossetta 会处理这个问题,我也可以在 arm64 上使用 x86_64 的应用程序。 But somehow it doesn't work.但不知何故,它不起作用。 I tried a lot of different things and am out of ideas.我尝试了很多不同的东西并且没有想法。

Does anyone know what the problem is?有谁知道问题是什么? I would be also thankful for advice and suggestions how to properly set up a python environment on Mac M1.我也将感谢有关如何在 Mac M1 上正确设置 python 环境的建议和建议。

I had the same problem back in 2days ago, I'm using m1 pro .两天前我遇到了同样的问题,我正在使用m1 pro I was trying to install the python packages only using pip but I got a numbers of errors, then I decided to install with conda .我试图仅使用pip安装 python 软件包,但出现了许多错误,然后我决定使用conda安装。

In my case it worked, here is what I've done so far is:就我而言,它起作用了,到目前为止我所做的是:

First Enable the open with rosetta in your zsh.首先在你的 zsh 中启用open with rosetta And then,接着,

# create environment in conda
conda create -n venv python=3.8 # with your python version

# activate
conda activate venv

and visit the conda website to look for the packages: check packages并访问 conda 网站查找包:检查包

For suppose if you are looking for pytest packages then you can search it, and you'll get a result like this, with the available package and channel.假设如果你正在寻找pytest包,那么你可以搜索它,你会得到这样的结果,有可用的 package 和频道。

在此处输入图像描述

You need to enable that specific channel to get that package with this command:您需要使用以下命令启用该特定通道以获取 package:

# config channel
conda config --append channels conda-forge # available channel name

# then install
conda install --yes --file requirements.txt

Make sure, your have the same version of pytest in your requirements.txt file.确保您在requirements.txt文件中拥有相同版本的pytest (eg:pytest==6.2.5)

Hope this should work, if not try to install it with pip like: pip install -r requirements.txt after environment enable.希望这应该可行,如果不尝试使用pip安装它,例如: pip install -r requirements.txt在环境启用后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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