操作系统:CentOS Linux release 8.5.2111
Python:3.10.14
参考 https://wiki.python.org/moin/BuildStatically 进行编译:
```
./configure LDFLAGS="-static" CFLAGS="-static" CPPFLAGS="-static" --disable-shared --enable-optimizations
make LDFLAGS="-static" LINKFORSHARED=" "
make altinstall
```
最后一步 `make altinstall` 失败:
```
copying build/scripts-3.10/pydoc3.10 -> /usr/local/bin
copying build/scripts-3.10/idle3.10 -> /usr/local/bin
copying build/scripts-3.10/2to3-3.10 -> /usr/local/bin
changing mode of /usr/local/bin/pydoc3.10 to 755
changing mode of /usr/local/bin/idle3.10 to 755
changing mode of /usr/local/bin/2to3-3.10 to 755
rm /usr/local/lib/python3.10/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py
rm -r /usr/local/lib/python3.10/lib-dynload/__pycache__
/usr/bin/install -c -m 644 ./Misc/python.man \
/usr/local/share/man/man1/python3.10.1
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--altinstall --upgrade" ;; \
install|*) ensurepip="--altinstall" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Traceback (most recent call last):
File "/root/Python-3.10.14/Lib/subprocess.py", line 69, in <module>
import msvcrt
ModuleNotFoundError: No module named 'msvcrt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/Python-3.10.14/Lib/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/root/Python-3.10.14/Lib/runpy.py", line 146, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/root/Python-3.10.14/Lib/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/root/Python-3.10.14/Lib/ensurepip/__init__.py", line 4, in <module>
import subprocess
File "/root/Python-3.10.14/Lib/subprocess.py", line 74, in <module>
import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
make: *** [Makefile:1290: altinstall] Error 1
```
实际上以及编译安装成功,只是 `pip3` 无法使用:
```
# pip3
Traceback (most recent call last):
File "/usr/local/lib/python3.10/subprocess.py", line 69, in <module>
import msvcrt
ModuleNotFoundError: No module named 'msvcrt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/main_parser.py", line 5, in <module>
import subprocess
File "/usr/local/lib/python3.10/subprocess.py", line 74, in <module>
import _posixsubprocess
ImportError: /usr/local/lib/python3.10/lib-dynload/_posixsubprocess.cpython-310-x86_64-linux-gnu.so: undefined symbol: PyTuple_Type
```
```
# python3
Python 3.10.14 (main, Aug 15 2024, 10:07:53) [GCC 8.5.0 20210514 (Red Hat 8.5.0-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
Traceback (most recent call last):
File "/usr/local/lib/python3.10/subprocess.py", line 69, in <module>
import msvcrt
ModuleNotFoundError: No module named 'msvcrt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/subprocess.py", line 74, in <module>
import _posixsubprocess
ImportError: /usr/local/lib/python3.10/lib-dynload/_posixsubprocess.cpython-310-x86_64-linux-gnu.so: undefined symbol: PyTuple_Type
``` |
|