简体   繁体   English

Python/pip 进程在 virtualenv 中被杀死(Apple M1 芯片)

[英]Python/pip process are killed in virtualenv (Apple M1 chip)

When I execute pip or python in MacBook M1 chip virtualenv, the process always terminates immediately with message like:当我在 MacBook M1 芯片 virtualenv 中执行 pip 或 python 时,该过程总是立即终止并显示如下消息:

[1]    29116 killed     pip

or或者

[1]    29141 killed     python

Python and pip in M1 MacBook native environment run fine. M1 MacBook 原生环境中的 Python 和 pip 运行良好。

Only in the virtualenv they don't work.仅在 virtualenv 中它们不起作用。

After some research, I find out it is related with "x86_64" and "arm 64" architecture.经过一番研究,我发现它与“x86_64”和“arm 64”架构有关。 To solve the problem, you have to run virtualenv python/pip in x86_64 mode.要解决这个问题,你必须在 x86_64 模式下运行 virtualenv python/pip。

Steps:脚步:

  1. Disable SIP : reboot MacBook in Recover Mode.禁用 SIP :在恢复模式下重新启动 MacBook。 Open Utilities > Terminal enter csrutil disable .打开Utilities > Terminal输入csrutil disable ref: Disabling and Enabling System Integrity Protection ref: 禁用和启用系统完整性保护
  2. Run SHELL as x86_64 mode : enter arch -x86_64 $SHELL in Terminal.以 x86_64 模式运行 SHELL :在终端中输入arch -x86_64 $SHELL
  3. Execute python/pip successfully成功执行python/pip

After that, I enable SIP again and keep using arch -x86_64 $SHELL every time.之后,我再次启用 SIP,并且每次都继续使用arch -x86_64 $SHELL It will execute python/pip in virtualenv succesfully.它将成功执行 virtualenv 中的 python/pip。

To save my time, I add an alias in my .zshrc :为了节省时间,我在.zshrc中添加了一个别名:

alias x86="arch -x86_64 $SHELL"别名 x86="arch -x86_64 $SHELL"

Now if I need execute some process in x86_64 mode, I just type x86 to open the x86_64 shell.现在,如果我需要在 x86_64 模式下执行某些进程,我只需键入x86即可打开 x86_64 shell。

Note: MxJ24 on github provides this solution and lists some useful scripts for python/django/brew: https://gist.github.com/MxJ24/e1386c9012f533cfbedfed5114da3e60 Note: MxJ24 on github provides this solution and lists some useful scripts for python/django/brew: https://gist.github.com/MxJ24/e1386c9012f533cfbedfed5114da3e60

Python 2 virtualenvs are just not working on Macs with Apple Silicon chip as of now. Python 2 virtualenvs 目前还不能在带有 Apple Silicon 芯片的 Mac 上工作。 See https://github.com/pypa/virtualenv/issues/2024 for more information.有关详细信息,请参阅https://github.com/pypa/virtualenv/issues/2024

The workarounds involving disabling System Integrity Protection and using x86_64 emulation may be unsafe and inefficient and I suggest against following them.涉及禁用系统完整性保护和使用 x86_64 仿真的解决方法可能不安全且效率低下,我建议不要遵循它们。


The best solution would obviously be to switch/migrate/upgrade to Python 3 , for which virtualenv works like a charm.最好的解决方案显然是切换/迁移/升级到Python 3 ,virtualenv 就像一个魅力。


If that's not a viable option, then I would consider using Docker instead of virtualenv .如果这不是一个可行的选择,那么我会考虑使用Docker 而不是 virtualenv python:2 Docker image has the latest Python 2.7.18 version and is available on aarch64 architecture, so it will run without x86_64 emulation. python:2 Docker 映像具有最新的 Python 2.7.18 版本,可用于 aarch64 架构,因此无需 x86_4 仿真即可运行。 I don't know your use case, but I am using IntelliJ IDEA/PyCharm and it supports using Docker as the SDK, so after a one-time setup it's seamless.我不知道您的用例,但我使用的是 IntelliJ IDEA/PyCharm,它支持使用 Docker 作为 SDK,因此在一次性设置后它是无缝的。

use SHELL as x86_64 mode by executing arch -x86_64 $SHELL this comand in the terminal通过在终端中执行 arch -x86_64 $SHELL 这个命令,使用 SHELL 作为 x86_64 模式

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

相关问题 无法在 Apple1 芯片中为 python Z2B9AFB89A6ACC1575B159BFCA38D10 安装 firebase-admin pip package - Unable to install firebase-admin pip package for python django in Apple M1 chip zsh:杀死代码。 MacOs M1芯片蒙特雷机上的命令 - zsh: killed code . command on MacOs M1 chip monterey machine 使用 python 请求库时 Apple Mac Book Pro M1 芯片分段错误 - Apple Mac Book Pro M1 Chip segmentation Error when using python requests library 在具有 M1 芯片(基于 ARM 的 Apple Silicon)的 Mac 上安装早期版本的 Python(3.8 之前)失败 - Installation of earlier versions of Python (prior to 3.8) fails on Mac with M1 Chip (ARM based Apple Silicon) 使用M1芯片在Mac上安装python@2 - Install python@2 on Mac with M1 chip 在带有 m1 芯片的 mac 上安装 python 表 - Installing python tables on mac with m1 chip 使用新的 m1 芯片在 MacOS 上安装 pip 问题 - pip installations issues on MacOS with new m1 chip 在配备 Apple M1 芯片的 MacBook Air 上安装 keras、TensorFlow2 - Installing keras, TensorFlow2 on MacBook Air with Apple M1 Chip 无法在带有 Apple M1 芯片的 macOS 12.2.1 上安装 orjson 3.3.0 - Unable to install orjson 3.3.0 on macOS 12.2.1 with Apple M1 chip 虚拟环境 Apple M1 芯片的错误架构问题 - Wrong architecture issue on virtual environment Apple M1 Chip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM