我正在尝试在 M1 Mac 上安装 pytables(使用自制软件安装的 MacOS 12.6.1、python 3.11 和 hdf5 1.12.2)。按照 https://stackoverflow.com/a/74276925中的建议 我执行了以下操作:
pip install cython
brew install hdf5
brew install c-blosc
export HDF5_DIR=/opt/homebrew/opt/hdf5
export BLOSC_DIR=/opt/homebrew/opt/c-blosc
pip install tables
pip install tables
产生以下输出:
Collecting tables
Using cached tables-3.7.0.tar.gz (8.2 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy>=1.19.0 in /opt/homebrew/lib/python3.11/site-packages (from tables) (1.24.0)
Collecting numexpr>=2.6.2
Using cached numexpr-2.8.4-cp311-cp311-macosx_11_0_arm64.whl (89 kB)
Requirement already satisfied: packaging in /opt/homebrew/lib/python3.11/site-packages (from tables) (22.0)
Building wheels for collected packages: tables
Building wheel for tables (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for tables (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [307 lines of output]
Error in sitecustomize; set PYTHONVERBOSE for traceback:
AssertionError:
/var/folders/82/c0s0s7md2m1c5nzd6s08j1tn09h343/T/lzo_version_dateuyld430w.c:2:5: error: implicit declaration of function 'lzo_version_date' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
lzo_version_date();
^
1 error generated.
/var/folders/82/c0s0s7md2m1c5nzd6s08j1tn09h343/T/lzo_version_date4yl230lw.c:2:5: error: implicit declaration of function 'lzo_version_date' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
lzo_version_date();
^
1 error generated.
/var/folders/82/c0s0s7md2m1c5nzd6s08j1tn09h343/T/BZ2_bzlibVersionowbloxlk.c:2:5: error: implicit declaration of function 'BZ2_bzlibVersion' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
BZ2_bzlibVersion();
^
1 error generated.
cpuinfo failed, assuming no CPU features: No module named 'cpuinfo'
* Using Python 3.11.0 (main, Oct 25 2022, 13:57:33) [Clang 14.0.0 (clang-1400.0.29.202)]
* Found cython 0.29.32
* USE_PKGCONFIG: True
* Found HDF5 headers at ``/opt/homebrew/opt/hdf5/include``, library at ``/opt/homebrew/opt/hdf5/lib``.
* Could not find LZO 2 headers and library; disabling support for it.
* Could not find LZO 1 headers and library; disabling support for it.
* Could not find bzip2 headers and library; disabling support for it.
* pkg-config header dirs for blosc: /opt/homebrew/Cellar/c-blosc/1.21.3/include
* pkg-config library dirs for blosc: /opt/homebrew/Cellar/c-blosc/1.21.3/lib
* Found blosc headers at ``/opt/homebrew/Cellar/c-blosc/1.21.3/include``, library at ``/opt/homebrew/Cellar/c-blosc/1.21.3/lib``.
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-12-arm64-cpython-311
creating build/lib.macosx-12-arm64-cpython-311/tables
[snip]
clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -DNDEBUG=1 -DHAVE_BLOSC_LIB=1 -Ihdf5-blosc/src -I/usr/local/include -I/sw/include -I/opt/include -I/opt/local/include -I/usr/include -I/include -I/opt/homebrew/opt/hdf5/include -I/opt/homebrew/Cellar/c-blosc/1.21.3/include -I/opt/homebrew/lib/python3.11/site-packages/numpy/core/include -I/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c tables/utilsextension.c -o build/temp.macosx-12-arm64-cpython-311/tables/utilsextension.o -Isrc -DH5_USE_18_API -DH5Acreate_vers=2 -DH5Aiterate_vers=2 -DH5Dcreate_vers=2 -DH5Dopen_vers=2 -DH5Eclear_vers=2 -DH5Eprint_vers=2 -DH5Epush_vers=2 -DH5Eset_auto_vers=2 -DH5Eget_auto_vers=2 -DH5Ewalk_vers=2 -DH5E_auto_t_vers=2 -DH5Gcreate_vers=2 -DH5Gopen_vers=2 -DH5Pget_filter_vers=2 -DH5Pget_filter_by_id_vers=2 -DH5Tarray_create_vers=2 -DH5Tget_array_dims_vers=2 -DH5Z_class_t_vers=2 -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
tables/utilsextension.c:8032:52: warning: comparison of integers of different signs: 'hsize_t' (aka 'unsigned long long') and 'long long' [-Wsign-compare]
__pyx_t_2 = (((__pyx_v_maxdims[__pyx_v_i]) == -1LL) != 0);
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~
tables/utilsextension.c:12367:33: warning: comparison of integers of different signs: 'int' and 'hsize_t' (aka 'unsigned long long') [-Wsign-compare]
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
~~~~~~~~~ ^ ~~~~~~~~~
tables/utilsextension.c:15186:35: warning: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Wsign-compare]
for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
~~~~~~~~~ ^ ~~~~~~~~~
tables/utilsextension.c:15413:52: warning: comparison of integers of different signs: 'hsize_t' (aka 'unsigned long long') and 'long long' [-Wsign-compare]
__pyx_t_3 = (((__pyx_v_maxdims[__pyx_v_j]) == -1LL) != 0);
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~
tables/utilsextension.c:22030:23: error: no member named 'exc_type' in 'struct _err_stackitem'
while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
~~~~~~~~ ^
tables/utilsextension.c:22030:53: error: no member named 'exc_type' in 'struct _err_stackitem'
while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
~~~~~~~~ ^
tables/utilsextension.c:22044:23: error: no member named 'exc_type' in 'struct _err_stackitem'
*type = exc_info->exc_type;
~~~~~~~~ ^
tables/utilsextension.c:22046:21: error: no member named 'exc_traceback' in 'struct _err_stackitem'
*tb = exc_info->exc_traceback;
~~~~~~~~ ^
tables/utilsextension.c:22060:26: error: no member named 'exc_type' in 'struct _err_stackitem'
tmp_type = exc_info->exc_type;
~~~~~~~~ ^
tables/utilsextension.c:22062:24: error: no member named 'exc_traceback' in 'struct _err_stackitem'
tmp_tb = exc_info->exc_traceback;
~~~~~~~~ ^
tables/utilsextension.c:22063:15: error: no member named 'exc_type' in 'struct _err_stackitem'
exc_info->exc_type = type;
~~~~~~~~ ^
tables/utilsextension.c:22065:15: error: no member named 'exc_traceback' in 'struct _err_stackitem'
exc_info->exc_traceback = tb;
~~~~~~~~ ^
tables/utilsextension.c:22147:30: error: no member named 'exc_type' in 'struct _err_stackitem'
tmp_type = exc_info->exc_type;
~~~~~~~~ ^
tables/utilsextension.c:22149:28: error: no member named 'exc_traceback' in 'struct _err_stackitem'
tmp_tb = exc_info->exc_traceback;
~~~~~~~~ ^
tables/utilsextension.c:22150:19: error: no member named 'exc_type' in 'struct _err_stackitem'
exc_info->exc_type = local_type;
~~~~~~~~ ^
tables/utilsextension.c:22152:19: error: no member named 'exc_traceback' in 'struct _err_stackitem'
exc_info->exc_traceback = local_tb;
~~~~~~~~ ^
tables/utilsextension.c:22201:43: warning: 'ob_shash' is deprecated [-Wdeprecated-declarations]
hash1 = ((PyBytesObject*)s1)->ob_shash;
^
/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/cpython/bytesobject.h:7:5: note: 'ob_shash' has been explicitly marked deprecated here
Py_DEPRECATED(3.11) Py_hash_t ob_shash;
^
/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/pyport.h:336:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
tables/utilsextension.c:22202:43: warning: 'ob_shash' is deprecated [-Wdeprecated-declarations]
hash2 = ((PyBytesObject*)s2)->ob_shash;
^
/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/cpython/bytesobject.h:7:5: note: 'ob_shash' has been explicitly marked deprecated here
Py_DEPRECATED(3.11) Py_hash_t ob_shash;
^
/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/pyport.h:336:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
^
tables/utilsextension.c:22347:26: error: no member named 'exc_type' in 'struct _err_stackitem'
tmp_type = exc_info->exc_type;
~~~~~~~~ ^
tables/utilsextension.c:22349:24: error: no member named 'exc_traceback' in 'struct _err_stackitem'
tmp_tb = exc_info->exc_traceback;
~~~~~~~~ ^
tables/utilsextension.c:22350:15: error: no member named 'exc_type' in 'struct _err_stackitem'
exc_info->exc_type = *type;
~~~~~~~~ ^
tables/utilsextension.c:22352:15: error: no member named 'exc_traceback' in 'struct _err_stackitem'
exc_info->exc_traceback = *tb;
~~~~~~~~ ^
tables/utilsextension.c:23020:5: error: incomplete definition of type 'struct _frame'
__Pyx_PyFrame_SetLineNumber(py_frame, py_line);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tables/utilsextension.c:445:62: note: expanded from macro '__Pyx_PyFrame_SetLineNumber'
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
~~~~~~~^
/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/pytypedefs.h:22:16: note: forward declaration of 'struct _frame'
typedef struct _frame PyFrameObject;
^
6 warnings and 17 errors generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for tables
Failed to build tables
ERROR: Could not build wheels for tables, which is required to install pyproject.toml-based projects
https://stackoverflow.com/a/65696724/2066572
建议对上述输出中的错误
no member named 'exc_type' in 'struct _err_stackitem'
的可能解决方案是将
pip install pytables
替换为
pip install --global-option build --global-option --force tables
但是,这会失败并出现不同的错误:
Collecting tables
Using cached tables-3.7.0.tar.gz (8.2 MB)
Installing build dependencies ... error
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [145 lines of output]
DEPRECATION: --no-binary currently disables reading from the cache of locally built wheels. In the future --no-binary will not influence the wheel cache. pip 23.1 will enforce this behaviour change. A possible replacement is to use the --no-cache-dir option. You can use the flag --use-feature=no-binary-enable-wheel-cache to test the upcoming behaviour. Discussion can be found at https://github.com/pypa/pip/issues/11453
Collecting setuptools>=42.0
Using cached setuptools-65.6.3.tar.gz (2.6 MB)
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Collecting wheel
Using cached wheel-0.38.4.tar.gz (67 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting oldest-supported-numpy
Using cached oldest-supported-numpy-2022.11.19.tar.gz (4.9 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting packaging
Using cached packaging-22.0.tar.gz (125 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Collecting Cython>=0.29.21
Using cached Cython-0.29.32.tar.gz (2.1 MB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting numpy==1.23.2
Using cached numpy-1.23.2.tar.gz (10.7 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'error'
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [97 lines of output]
Error in sitecustomize; set PYTHONVERBOSE for traceback:
AssertionError:
<string>:71: RuntimeWarning: NumPy 1.23.2 may not yet support Python 3.11.
Running from numpy source directory.
<string>:86: DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html
running egg_info
running build_src
INFO: build_src
creating numpy.egg-info
writing numpy.egg-info/PKG-INFO
writing dependency_links to numpy.egg-info/dependency_links.txt
writing entry points to numpy.egg-info/entry_points.txt
writing top-level names to numpy.egg-info/top_level.txt
writing manifest file 'numpy.egg-info/SOURCES.txt'
/opt/homebrew/lib/python3.11/site-packages/setuptools/command/egg_info.py:643: SetuptoolsDeprecationWarning: Custom 'build_py' does not implement 'get_data_files_without_manifest'.
Please extend command classes from setuptools instead of distutils.
warnings.warn(
INFO: unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.11/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 351, in <module>
main()
File "/opt/homebrew/lib/python3.11/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 333, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
self.run_setup()
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/build_meta.py", line 484, in run_setup
self).run_setup(setup_script=setup_script)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/build_meta.py", line 335, in run_setup
exec(code, locals())
File "<string>", line 493, in <module>
File "<string>", line 485, in setup_package
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/__init__.py", line 87, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
return run_commands(dist)
^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
dist.run_commands()
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 968, in run_commands
self.run_command(cmd)
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/dist.py", line 1217, in run_command
super().run_command(command)
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
cmd_obj.run()
File "/private/var/folders/82/c0s0s7md2m1c5nzd6s08j1tn09h343/T/pip-install-lomp8yz3/numpy_c85c0322750845cfba16acab1a65e8fa/numpy/distutils/command/egg_info.py", line 25, in run
_egg_info.run(self)
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 308, in run
self.find_sources()
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 316, in find_sources
mm.run()
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 560, in run
self.add_defaults()
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 597, in add_defaults
sdist.add_defaults(self)
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/sdist.py", line 107, in add_defaults
self._add_defaults_build_sub_commands()
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/sdist.py", line 127, in _add_defaults_build_sub_commands
self.filelist.extend(chain.from_iterable(files))
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 503, in extend
self.files.extend(filter(self._safe_path, paths))
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/sdist.py", line 126, in <genexpr>
files = (c.get_source_files() for c in cmds if hasattr(c, "get_source_files"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/command/sdist.py", line 125, in <genexpr>
cmds = (self.get_finalized_command(c) for c in missing_cmds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 306, in get_finalized_command
cmd_obj.ensure_finalized()
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/private/var/folders/82/c0s0s7md2m1c5nzd6s08j1tn09h343/T/pip-install-lomp8yz3/numpy_c85c0322750845cfba16acab1a65e8fa/numpy/distutils/command/config_compiler.py", line 69, in finalize_options
v = getattr(c, a)
^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/Cython/Distutils/old_build_ext.py", line 157, in __getattr__
return _build_ext.build_ext.__getattr__(self, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 105, in __getattr__
raise AttributeError(attr)
AttributeError: fcompiler. Did you mean: 'compiler'?
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
搜索上述错误
AttributeError: fcompiler. Did you mean: 'compiler'?
对我来说已经很枯燥了。
如何在这个环境中安装 pytables?有没有办法避免从源代码构建?如果没有,如何才能成功构建?
看起来遇到的问题是 PyTables 和尝试使用的 Python 版本(3.11)之间的兼容性。PyTables 可能尚未完全支持 Python 3.11,这会导致看到的错误。
以下是一些解决此问题的步骤:
1. 创建虚拟环境:
始终建议在虚拟环境中安装 Python 包。这可以防止不同项目之间的版本冲突。可以使用
venv
创建虚拟环境:
bash
python3 -m venv env
source env/bin/activate
2. 安装旧版本的 NumPy:
遇到的第二个错误与 NumPy 1.23.2 和 Python 3.11 的兼容性有关。尝试安装一个较旧的 NumPy 版本:
bash
pip install numpy==1.22.4
3. 安装 PyTables:
现在尝试再次安装 PyTables,但不要使用
--global-option
参数:
bash
pip install tables
如果问题仍然存在,请尝试以下操作:
4. 从源代码安装 PyTables (如果有 C 编译器):
如果上述步骤都不起作用,可能需要从源代码构建 PyTables。这将需要系统上安装 C 编译器。
bash
pip install cython
pip install numpy
brew install hdf5
brew install c-blosc
export HDF5_DIR=/opt/homebrew/opt/hdf5
export BLOSC_DIR=/opt/homebrew/opt/c-blosc
pip install --no-binary=tables tables
5. 降级 Python 版本:
如果以上所有方法都失败,可以考虑降级 Python 版本到 PyTables 支持的版本。可以查看 PyTables 文档以了解支持的 Python 版本。
其他提示:
-
确保的
pip
是最新的:pip install --upgrade pip
-
尝试清除 pip 缓存:
pip cache purge
请记住,软件包兼容性问题在使用新版本的软件时很常见。尝试这些步骤应该可以帮助在 M1 Mac 上成功安装 PyTables。
标签:python,macos,pip,homebrew,pytables From: 74870318