[英]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:脚步:
Utilities > Terminal
enter csrutil disable
.Utilities > Terminal
输入csrutil disable
。 ref: Disabling and Enabling System Integrity Protection arch -x86_64 $SHELL
in Terminal.arch -x86_64 $SHELL
。 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.