如何在 m1 Mac 上安装 pandas

问题描述 投票:0回答:8
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -DNPY_NO_DEPRECATED_API=0 -Ipandas/_libs/src/ujson/python -Ipandas/_libs/src/ujson/lib -Ipandas/_libs/src/datetime -I/Users/jesse/Desktop/ssc/pythonProject3/venv/lib/python3.8/site-packages/numpy/core/include -I/Users/jesse/Desktop/ssc/pythonProject3/venv/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c pandas/_libs/src/ujson/python/ujson.c -o build/temp.macosx-10.14.6-arm64-3.8/pandas/_libs/src/ujson/python/ujson.o -D_GNU_SOURCE -Wno-unused-function
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -DNPY_NO_DEPRECATED_API=0 -Ipandas/_libs/src/ujson/python -Ipandas/_libs/src/ujson/lib -Ipandas/_libs/src/datetime -I/Users/jesse/Desktop/ssc/pythonProject3/venv/lib/python3.8/site-packages/numpy/core/include -I/Users/jesse/Desktop/ssc/pythonProject3/venv/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c pandas/_libs/src/ujson/python/objToJSON.c -o build/temp.macosx-10.14.6-arm64-3.8/pandas/_libs/src/ujson/python/objToJSON.o -D_GNU_SOURCE -Wno-unused-function
    pandas/_libs/src/ujson/python/objToJSON.c:181:12: error: use of undeclared identifier 'NUMPY_IMPORT_ARRAY_RETVAL'
        return NUMPY_IMPORT_ARRAY_RETVAL;
               ^
    1 error generated.
    error: command 'clang' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/jesse/Desktop/ssc/pythonProject3/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ky/s4qqls154f9c4j5lfcfspbpm0000gn/T/pip-install-t5zlzk09/pandas_67e63708ec954c589e697c9f10e3730c/setup.py'"'"'; __file__='"'"'/private/var/folders/ky/s4qqls154f9c4j5lfcfspbpm0000gn/T/pip-install-t5zlzk09/pandas_67e63708ec954c589e697c9f10e3730c/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ky/s4qqls154f9c4j5lfcfspbpm0000gn/T/pip-record-cnus0d48/install-record.txt --single-version-externally-managed --compile --install-headers /Users/jesse/Desktop/ssc/pythonProject3/venv/include/site/python3.8/pandas Check the logs for full command output.
(base) 

我想使用 PyCharm 在 Mac mini 上下载 pandas。

我该怎么办?

python pandas macos pycharm apple-m1
8个回答
10
投票

此问题已得到回答:

在新 MacBook Air M1 上安装 Pandas 时遇到问题

python3 -m pip install virtualenv
virtualenv -p python3.8 venv
source venv/bin/activate
pip install --upgrade pip
pip install numpy cython
git clone https://github.com/pandas-dev/pandas.git
cd pandas
python3 setup.py install

1
投票

您必须在环境中安装

numpy
才能从源代码构建
pandas
的所有版本(不带
pandas
)的
pyproject.toml
。请先安装
numpy
,然后重试。


如果您的计算机上安装了

numpy
,您可能需要使用
pip install numpy -U
或通过 PyCharm GUI 执行的等效命令来更新版本。


1
投票

虽然 caeneb 的技巧非常有效,但我发现将 python 升级到更高版本并更新 pip 也有效。

对我来说,这些命令起到了作用(我使用

pyenv
管理我的 python 安装)

pyenv install 3.9.9
pyenv global 3.9.9 # use this python version as the default
pip install pandas # just works

我想如果没有 pyenv 你可以简单地运行以下命令(未经测试)

brew install [email protected]
$(brew --prefix)/bin/python3.9 -m pip install pandas # makes sure to use the right pip

1
投票

从手动查看 numpy git 日志,使用降级 numpy

pip install numpy==1.18.5
然后

OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=12.4 pip3 install pandas==0.25.3 --no-use-pep517     

安装 pandas 后,我可以再次升级 numpy


0
投票

我建议您使用

conda
,这样您就可以安装虚拟环境,也可以使用不同的python版本,并最终使用不同的R(以及node.js)。更简单,程序是预编译的(conda 就是为这种情况创建的)。

否则,您确定已安装

xcode
吗?去苹果商店查一下。 Xcode是Apple的“SDK”(开发者工具包),带有编译器:
clang
:你没有它,所以错误。它还为您提供了 pip 通常需要的其他工具。注意:您还应该手动执行一个 xcode 命令,以便能够接受 xcode 条件(否则您可能会在使用 xcode 的脚本上遇到问题)。


0
投票

这对我有用

pip install git+git://github.com/pandas-dev/pandas.git


0
投票

这是单行:

python3 -m venv venv && source venv/bin/activate && python3 -m pip install pandas

输出:

✦ ❯ python3 -m venv venv && source venv/bin/activate && python3 -m pip install pandas
Collecting pandas
  Downloading pandas-2.2.2-cp312-cp312-macosx_11_0_arm64.whl.metadata (19 kB)
Collecting numpy>=1.26.0 (from pandas)
  Downloading numpy-2.0.1-cp312-cp312-macosx_14_0_arm64.whl.metadata (60 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.9/60.9 kB 2.3 MB/s eta 0:00:00
Collecting python-dateutil>=2.8.2 (from pandas)
  Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl.metadata (8.4 kB)
Collecting pytz>=2020.1 (from pandas)
  Using cached pytz-2024.1-py2.py3-none-any.whl.metadata (22 kB)
Collecting tzdata>=2022.7 (from pandas)
  Using cached tzdata-2024.1-py2.py3-none-any.whl.metadata (1.4 kB)
Collecting six>=1.5 (from python-dateutil>=2.8.2->pandas)
  Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
Downloading pandas-2.2.2-cp312-cp312-macosx_11_0_arm64.whl (11.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.3/11.3 MB 58.9 MB/s eta 0:00:00
Downloading numpy-2.0.1-cp312-cp312-macosx_14_0_arm64.whl (5.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.0/5.0 MB 49.4 MB/s eta 0:00:00
Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 229.9/229.9 kB 19.3 MB/s eta 0:00:00
Using cached pytz-2024.1-py2.py3-none-any.whl (505 kB)
Using cached tzdata-2024.1-py2.py3-none-any.whl (345 kB)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: pytz, tzdata, six, numpy, python-dateutil, pandas
Successfully installed numpy-2.0.1 pandas-2.2.2 python-dateutil-2.9.0.post0 pytz-2024.1 six-1.16.0 tzdata-2024.1

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip

✦ ❯

-3
投票

$

pip install pandas

在 Mac 上安装 pip :

$curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

  • 使用自制软件安装python:

    brew install python

  • 确保正确的路径:

    $which python

  • 现在安装pandas:

    $pip install pandas

© www.soinside.com 2019 - 2024. All rights reserved.