python - 在 macbook m1 上安装 h5py 一直失败
问题描述
我正在尝试在我的 macbook m1 上安装 h5py。我首先brew install hdf5
按照文档中的描述运行。然后我跑了pip3 install h5py
,但这总是导致以下错误消息。我还尝试了这篇文章中的解决方案(How to install h5py (need for Keras) on MacOS with M1?),但结果相同。
Error compiling Cython file:
------------------------------------------------------------
...
"""(UINT index) => STRING
Get the directory path at the given index (starting from 0) in the
plugin search path. Returns a Python bytes object.
"""
cpdef size_t n
^
------------------------------------------------------------
h5py/h5pl.pyx:64:14: Variables cannot be declared with 'cpdef'. Use 'cdef' instead.
Error compiling Cython file:
------------------------------------------------------------
...
Get the directory path at the given index (starting from 0) in the
plugin search path. Returns a Python bytes object.
"""
cpdef size_t n
cpdef char* buf = NULL
^
------------------------------------------------------------
h5py/h5pl.pyx:65:14: Variables cannot be declared with 'cpdef'. Use 'cdef' instead.
Error compiling Cython file:
------------------------------------------------------------
...
cpdef size():
"""() => UINT
Get the number of directories currently in the plugin search path.
"""
cpdef unsigned int n = 0
^
------------------------------------------------------------
h5py/h5pl.pyx:80:14: Variables cannot be declared with 'cpdef'. Use 'cdef' instead.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-install-agzrcn_9/h5py_07ca596659e44c58afabe948244bd411/setup.py", line 140, in <module>
setup(
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/setuptools/__init__.py", line 145, in setup
return distutils.core.setup(**attrs)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/install.py", line 561, in run
self.run_command('build')
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/private/var/folders/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-install-agzrcn_9/h5py_07ca596659e44c58afabe948244bd411/setup_build.py", line 207, in run
self.extensions = cythonize(self._make_extensions(config),
File "/private/var/folders/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-install-agzrcn_9/h5py_07ca596659e44c58afabe948244bd411/.eggs/Cython-3.0.0a9-py3.8.egg/Cython/Build/Dependencies.py", line 1116, in cythonize
cythonize_one(*args)
File "/private/var/folders/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-install-agzrcn_9/h5py_07ca596659e44c58afabe948244bd411/.eggs/Cython-3.0.0a9-py3.8.egg/Cython/Build/Dependencies.py", line 1283, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /private/var/folders/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-install-agzrcn_9/h5py_07ca596659e44c58afabe948244bd411/h5py/h5pl.pyx
----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Developer/CommandLineTools/usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-install-agzrcn_9/h5py_07ca596659e44c58afabe948244bd411/setup.py'"'"'; __file__='"'"'/private/var/folders/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-install-agzrcn_9/h5py_07ca596659e44c58afabe948244bd411/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/y4/x78nk9h91fz6gtdc549t55g00000gn/T/pip-record-b42l5c9z/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /Users/adrianwestphal/Library/Python/3.8/include/python3.8/h5py Check the logs for full command output.
解决方案
“已修复”。我通过 macport 进行了尝试,现在可以使用。但是,我仍然不知道为什么它不能通过 pip 工作。这是我使用的代码:
- (安装 macport) https://www.macports.org/install.php
sudo port install py38-h5py
- 确保您使用 python 的 macport 版本
推荐阅读
- r - 如何在 R 中添加数据框的所有重复值?
- python - 邻接表和邻接矩阵能够在逻辑上呈现非线性数据结构
- visual-studio-code - 如何在 VSCode SSH TARGETS 中为服务器设置多个文件夹?
- python - Values from .txt become null
- python - create one dict from list of dicts in DataFrame
- java - I can*t run Spring Boot application because of "java.lang.UnsupportedClassVersionError: Preview features are not enabled for AAA.class"
- javascript - Laravel AJAX 响应加载错误的路由/窗口
- xslt - 获取每个特定子节点的父节点值
- fortran - cgeev sovle Non Hermitan 矩阵不正确
- django - Django登录 - 不要去注册新用户