问题描述
当我在 MacBook M1 芯片 virtualenv 中执行 pip 或 python 时,进程总是立即终止并显示如下消息:
When I execute pip or python in MacBook M1 chip virtualenv, the process always terminates immediately with message like:
[1] 29116 killed pip
或
[1] 29141 killed python
Python 和 pip 在 M1 MacBook 本机环境中运行良好.
Python and pip in M1 MacBook native environment run fine.
仅在 virtualenv 中它们不起作用.
Only in the virtualenv they don't work.
推荐答案
经过一番研究,我发现它与x86_64"有关和臂64"建筑学.要解决这个问题,你必须在 x86_64 模式下运行 virtualenv python/pip.
After some research, I find out it is related with "x86_64" and "arm 64" architecture. To solve the problem, you have to run virtualenv python/pip in x86_64 mode.
步骤:
- 禁用 SIP:在恢复模式下重启 MacBook.打开
Utilities >终端
输入csrutil disable
.参考:禁用和启用系统完整性保护 - 以 x86_64 模式运行 SHELL:在终端中输入
arch -x86_64 $SHELL
. - 成功执行python/pip
- Disable SIP: reboot MacBook in Recover Mode. Open
Utilities > Terminal
entercsrutil disable
. ref: Disabling and Enabling System Integrity Protection - Run SHELL as x86_64 mode: enter
arch -x86_64 $SHELL
in Terminal. - Execute python/pip successfully
之后,我再次启用 SIP 并每次都继续使用 arch -x86_64 $SHELL
.它将成功执行 virtualenv 中的 python/pip.
After that, I enable SIP again and keep using arch -x86_64 $SHELL
every time. It will execute python/pip in virtualenv succesfully.
为了节省时间,我在 .zshrc 中添加了一个别名:
To save my time, I add an alias in my .zshrc:
别名 x86=arch -x86_64 $SHELL"
现在如果我需要在 x86_64 模式下执行某个进程,我只需输入 x86
来打开 x86_64 shell.
Now if I need execute some process in x86_64 mode, I just type x86
to open the x86_64 shell.
注意:github 上的 MxJ24 提供了这个解决方案并列出了一些有用的 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/pip 进程在 virtualenv 中被杀死(Apple M1 芯片)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!