我在 Ubuntu 21.10 上尝试安装 Python 3.5 时遇到分段错误。
$ guettli@p15:~$ pyenv install 3.5.8
Downloading Python-3.5.8.tar.xz...
-> https://www.python.org/ftp/python/3.5.8/Python-3.5.8.tar.xz
Installing Python-3.5.8...
BUILD FAILED (Ubuntu 21.10 using python-build 20180424)
Inspect or clean up the working tree at /tmp/python-build.20211119144903.305257
Results logged to /tmp/python-build.20211119144903.305257.log
Last 10 log lines:
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Segmentation fault (core dumped)
当我安装 Python-3.5.10.tar.xz(没有 pyenv)时,也会发生同样的情况。我现在该怎么办?
版本:Ubuntu 21.10
输出configure
:https://pastebin.com/rie17s8Z
输出make
:https://pastebin.com/F3C4evR6
输出make install
:https://paste2.org/LKxHUYkM
使用 PYTHONFAULTHANDLER:
guettli@p15:~/Downloads/Python-3.5.10$ PYTHONFAULTHANDLER=1 LANG=C python3.5 -m ensurepip
Fatal Python error: Segmentation fault
Current thread 0x00007fb703b40740 (most recent call first):
File "/usr/local/lib/python3.5/ctypes/__init__.py", line 276 in _reset_cache
File "/usr/local/lib/python3.5/ctypes/__init__.py", line 541 in <module>
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 697 in exec_module
File "<frozen importlib._bootstrap>", line 673 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/usr/local/lib/python3.5/uuid.py", line 464 in <module>
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 697 in exec_module
File "<frozen importlib._bootstrap>", line 673 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/filepost.py", line 4 in <module>
File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/request.py", line 7 in <module>
File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 41 in <module>
File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/__init__.py", line 8 in <module>
File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1015 in _handle_fromlist
File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/__init__.py", line 27 in <module>
File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/__init__.py", line 62 in <module>
File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/__init__.py", line 21 in <module>
File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 968 in _find_and_load
File "/usr/local/lib/python3.5/ensurepip/__init__.py", line 40 in _run_pip
File "/usr/local/lib/python3.5/ensurepip/__init__.py", line 116 in bootstrap
File "/usr/local/lib/python3.5/ensurepip/__init__.py", line 209 in _main
File "/usr/local/lib/python3.5/ensurepip/__main__.py", line 4 in <module>
File "/usr/local/lib/python3.5/runpy.py", line 85 in _run_code
File "/usr/local/lib/python3.5/runpy.py", line 193 in _run_module_as_main
Segmentation fault (core dumped)
答案1
我在这里找到了解决方案:https://giters.com/pyenv/pyenv/issues/1889
步骤1:创建文件segfault.patch,内容如下:
--- Include/objimpl.h
+++ Include/objimpl.h
@@ -250,7 +250,7 @@
union _gc_head *gc_prev;
Py_ssize_t gc_refs;
} gc;
- double dummy; /* force worst-case alignment */
+ long double dummy; /* force worst-case alignment */
} PyGC_Head;
extern PyGC_Head *_PyGC_generation0;
--- Objects/obmalloc.c
+++ Objects/obmalloc.c
@@ -643,8 +643,8 @@
*
* You shouldn't change this unless you know what you are doing.
*/
-#define ALIGNMENT 8 /* must be 2^N */
-#define ALIGNMENT_SHIFT 3
+#define ALIGNMENT 16 /* must be 2^N */
+#define ALIGNMENT_SHIFT 4
/* Return the number of bytes in size class I, as a uint. */
#define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT)
第 2 步:应用补丁:
user@host:Python-3.5.10$ patch -p0 < segfault.patch
步骤3:
user@host:Python-3.5.10$ make -j 8 # adapt to your number of CPU cores
步骤4:
任何一个:
user@host:Python-3.5.10$ sudo make altinstall # if you want only python3.6
或者
user@host:Python-3.5.10$ sudo make install # if you want systemwide python as well
答案2
显然,在 Ubuntu 22.04 LTS 上构建 Python 3.5 和 3.6 之前进行设置就足够了CC=gcc-10
,按照pyenv 问题:
sudo apt install gcc-10
CC=gcc-10 pyenv install 3.6.13
(我自己没有使用 Pyenv,而是从源代码进行编译,这个解决方法为我修复了段错误。)
答案3
米尼康达
我建议安装 miniconda 来管理您的虚拟环境,并在新创建的环境中安装所需的 python 版本。
在我看来,它是一个不错的解决方案,不像 anaconda 那样臃肿,你仍然可以使用 pip、poetry 或任何你喜欢的包管理软件。
答案4
我尝试了这个,得到了同样的错误;也尝试了此版本中最好的 3.5.10,但仍然一样。我以为是 pyenv 的问题,并尝试了 2.2.0,但结果仍然相同。所以我下载了 Python 3.5.8 并继续手动安装(在安装目录中,请参阅 Python文档) 和:
./configure --with-pydebug --enable-optimizations --with-lto
make
但是在make
python 中测试分布时卡住了。因此建议不要使用任何选项./configure
。然后运行:
make
sudo make install
或者sudo make altinstall
此版本 3.5.8 中存在多个问题,其中 pyenv 无法工作的主要原因似乎是由于以下原因:
/home/<me>/Python-3.5.8/Modules/nismodule.c:17:10: fatal error: rpc/rpc.h: No such file or directory 17 | #include <rpc/rpc.h>
然后使用 Pycharm 来构建您的项目或者简单地使用 venv 或 virtulenv。