使用PyCharm编写python代码。我将终端设置为Rosetta模拟,并通过终端安装了Numpy。现在我可以从终端内部运行我的Numpy代码了,但是当我尝试在PyCharm中编译它时,我得到了错误提示:
* The Python version is: Python3.9 from "/Users/kubab/PycharmProjects/fix/venv/bin/python"
* The NumPy version is: “1.20.3"
ImportError: dlopen(/Users/kubab/PycharmProjects/fix/venv/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): no suitable image found. Did find:
/Users/kubab/PycharmProjects/fix/venv/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so: mach-o, but wrong architecture
/Users/kubab/PycharmProjects/fix/venv/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so: mach-o, but wrong architecture
解决方案
如果您想使用m1版本,只需在非rosetta终端中使用miniforge安装numpy即可:
brew install miniforge
(将“boost”替换为您想要的任何内容)
conda create -n boost
conda activate boost
conda install python=3.9.4
conda install numpy
然后在M1 PyCharm中选择miniforge python。
在PyCharm中选择Miniforge Python解释器的步骤如下:
-
打开PyCharm,然后打开你的项目。
-
在菜单栏中,选择 "File" -> "Settings" (Windows/Linux) 或 "PyCharm" -> "Preferences" (Mac)。
-
在左侧的导航栏中,展开 "Project: <your_project_name>",然后选择 "Python Interpreter"。
-
在右侧的Python解释器列表中,点击右上角的齿轮图标,然后选择 "Add..."。
-
在弹出的窗口中,选择 "Existing environment",然后点击右侧的"..."按钮。
-
在文件选择器中,导航到你的Miniforge Python解释器的位置。如果你不确定它的位置,你可以在终端中输入以下命令来查找:
which python
这将显示你当前环境中Python解释器的路径。如果你已经激活了你的Miniforge环境,那么这应该是你的Miniforge Python解释器的路径。
- 在PyCharm的文件选择器中,选择你的Miniforge Python解释器,然后点击 "OK"。
-
现在,你应该可以在PyCharm中使用你的Miniforge Python解释器来运行你的代码了。