-
Notifications
You must be signed in to change notification settings - Fork 278
[Install Log] macOS (arm)
注意
system version: macOS 15.3.1
Device: Mac mini M4
在安装conda环境以及所有库之后,可以启动程序。由于Python3.8版本以后macOS系统multiprocessing库创建子进程的方式由fork改为spawn
Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess. See bpo-33725.
所以打开程序后会遇到此问题
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/unitree/miniconda3/envs/tv/lib/python3.8/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/Users/unitree/miniconda3/envs/tv/lib/python3.8/multiprocessing/spawn.py", line 126, in _main
self = reduction.pickle.load(from_parent)
TypeError: __new__() takes 1 positional argument but 6 were given一种可能的解决方法可能是在 teleop/open_television/television.py文件开头处直接强制修改子进程的创建方式:
from multiprocessing import context
Value = context._default_context.Value
# this is for macOS, because macOS use spawn rather than fork when python>=3.8
import multiprocessing as mp
mp.set_start_method("fork")
class TeleVision:
def __init__(self, binocular, img_shape, img_shm_name, cert_file="./cert.pem", key_file="./key.pem", ngrok=False):
self.binocular = binocular但是添加上述代码后,启动程序后会增加警告信息,暂时未测试该程序的可用性:
objc[12075]: +[MPSGraphObject initialize] may have been in progress in another thread when fork() was called.
objc[12075]: +[MPSGraphObject initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.2. macOS系统下使用 orbstack 安装 arm 架构 Ubuntu 20.04 虚拟机运行
主要问题有两个:
nlopt 对 arm 架构系统的支持不是很良好。直接使用 pip install 很难安装完成,会报出一些错误 https://github.com/DanielBok/nlopt-python/issues/13 .
直接使用 conda install 安装,看似成功,但在程序中并不能正常import。在安装完最新版 cmake 之后,可以自己手动编译 nlopt 库。git 克隆 nlopt 库之后,如官方文档所描述的那样进行安装。需要注意的是,使用 cmake .. 命令时要指定我们要绑定的 python 解释器路径。以下是我的使用示例(我使用 miniconda3 ):
cd ~
#安装依赖库
sudo apt install swig
#安装nlopt
git clone https://github.com/stevengj/nlopt
cd nlopt
mkdir build && cd build
# 这里要指定Python解释器的路径
cmake -DPYTHON_EXECUTABLE=/home/unitree/miniconda3/envs/tv/bin/python ..
make -j8
sudo make install
# 此时运行 pip install 即可成功完成在 arm 架构系统下 nlopt 的安装
pip install nlopt步骤较为简单。第一,在 orbstack 的 Ubuntu20.04 虚拟机终端下安装 x11 相关库,并设置转发
sudo apt update
sudo apt install -y libxcb-xinerama0 libxcb1 libx11-xcb1 libxcb-util1 libxrender1 libxkbcommon-x11-0 libxext6
sudo apt install -y x11-apps
export DISPLAY=host.docker.internal:0第二,在 macOS 系统下从 XQuartz 官网 下载并安装 XQuartz。安装后在终端下运行命令
open -a XQuartz然后在 XQuartz 终端输入下面命令,若输出 /private/tmp/****/org.xquartz:0等含有:0 信息则说明正常
echo $DISPLAY
第三,在 XQuartz 设置窗口的安全性选项卡中打开 允许从网络客户端连接 选项,并重启 XQuartz。
第四,在 macOS 系统终端下输入命令 xhost + ,手动授权 X11 访问。
第五,此时在 orbstack 的 Ubuntu20.04 虚拟机终端下输入命令 xclock,如果 macOS 系统的界面弹出一个时钟窗口即说明成功。
After installing the Conda environment and all required libraries, the program can be launched. However, since macOS changed the default subprocess creation method from fork to spawn starting from Python 3.8, this issue may occur:
Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess. See bpo-33725. When launching the program, you may encounter this error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/unitree/miniconda3/envs/tv/lib/python3.8/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/Users/unitree/miniconda3/envs/tv/lib/python3.8/multiprocessing/spawn.py", line 126, in _main
self = reduction.pickle.load(from_parent)
TypeError: __new__() takes 1 positional argument but 6 were givenOne possible workaround is to explicitly set the subprocess creation method at the beginning of teleop/open_television/television.py:
from multiprocessing import context
Value = context._default_context.Value
# This is for macOS because macOS uses spawn rather than fork when Python >= 3.8
import multiprocessing as mp
mp.set_start_method("fork")
class TeleVision:
def __init__(self, binocular, img_shape, img_shm_name, cert_file="./cert.pem", key_file="./key.pem", ngrok=False):
self.binocular = binocularHowever, adding this code may introduce the following warning when launching the program, and its stability remains untested:
objc[12075]: +[MPSGraphObject initialize] may have been in progress in another thread when fork() was called.
objc[12075]: +[MPSGraphObject initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.2. Running on an arm-based Ubuntu 20.04 Virtual Machine with orbstack
nlopt does not have good support for arm architectures. Installing via pip install often fails, as seen in this issue: https://github.com/DanielBok/nlopt-python/issues/13.
Using conda install may appear successful, but the library might still not be importable in Python. A solution is to compile nlopt manually after installing the latest version of CMake. Clone the nlopt repository and follow the official installation instructions: NLopt Installation Guide.
During cmake .., make sure to specify the Python interpreter path. Here’s an example using miniconda3:
cd ~
git clone https://github.com/stevengj/nlopt
cd nlopt
mkdir build && cd build
# Specify the Python interpreter path
cmake -DPython_EXECUTABLE=/home/unitree/miniconda3/envs/tv/bin/python ..
make -j8
sudo make install
# Now install nlopt via pip should ok
pip install nloptFollow these steps:
- Install X11-related libraries in the Ubuntu 20.04 virtual machine and configure display forwarding:
sudo apt update
sudo apt install -y libxcb-xinerama0 libxcb1 libx11-xcb1 libxcb-util1 libxrender1 libxkbcommon-x11-0 libxext6
sudo apt install -y x11-apps
export DISPLAY=host.docker.internal:0- Install XQuartz on macOS Download and install XQuartz. After installation, run:
open -a XQuartz
Then, check if the display variable is set correctly:
echo $DISPLAY
If the output contains /private/tmp/****/org.xquartz:0, it means XQuartz is running correctly.
-
Enable X11 network access In XQuartz Preferences, go to the Security tab and enable Allow connections from network clients. Restart XQuartz afterward.
-
Grant X11 access permissionsOn macOS, run:
xhost +
- Test the X11 display in the Ubuntu virtual machine In the Ubuntu 20.04 terminal inside Orbstack, run:
xclock
If a clock window appears on macOS, it means the setup is successful.