ubuntu “ModuleNotFoundError:No module named 'zlib',python3.12.0 install failed

ars1skjm  于 5个月前  发布在  Python
关注(0)|答案(1)|浏览(116)

在ubuntu上通过源代码安装python3.12.0时,出现如下错误:

Traceback (most recent call last):
  File "<frozen zipimport>", line 518, in _get_decompress_func
ModuleNotFoundError: No module named 'zlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen zipimport>", line 566, in _get_data
  File "<frozen zipimport>", line 521, in _get_decompress_func
zipimport.ZipImportError: can't decompress data; zlib not available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "<frozen runpy>", line 222, in run_module
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "<frozen zipimport>", line 137, in get_code
  File "<frozen zipimport>", line 700, in _get_module_code
  File "<frozen zipimport>", line 568, in _get_data
zipimport.ZipImportError: can't decompress data; zlib not available
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/Python-3.12.0/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
             ^^^^^^^^^^^^^^^^^
  File "/opt/Python-3.12.0/Lib/ensurepip/__init__.py", line 284, in _main
    return _bootstrap(
           ^^^^^^^^^^^
  File "/opt/Python-3.12.0/Lib/ensurepip/__init__.py", line 200, in _bootstrap
    return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/Python-3.12.0/Lib/ensurepip/__init__.py", line 101, in _run_pip
    return subprocess.run(cmd, check=True).returncode
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/Python-3.12.0/Lib/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/opt/Python-3.12.0/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmpl_xaqhta/pip-23.2.1-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmpl_xaqhta\', \'--root\', \'/\', \'--upgrade\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
Makefile:2024: recipe for target 'install' failed
make: *** [install] Error 1

字符串

1、我电脑的env

jihan@ubuntu:/opt/Python-3.12.0$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

jihan@ubuntu:/opt/Python-3.12.0$ lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  1
Core(s) per socket:  2
Socket(s):           4
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               151
Model name:          12th Gen Intel(R) Core(TM) i7-12700F
Stepping:            2
CPU MHz:             2111.999
BogoMIPS:            4223.99
Hypervisor vendor:   VMware
Virtualization type: full
L1d cache:           48K
L1i cache:           32K
L2 cache:            1280K
L3 cache:            25600K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves arat umip gfni vaes vpclmulqdq rdpid flush_l1d arch_capabilities

安装流程下载python3.12.0源码包

第一个月
解压缩源代码
tar -zxvf Python-3.12.0.tgz
配置编译参数
cd Python-3.12.0
./configure --prefix=/usr/local/Python-3.12.0
编译源代码
make
下面给出了一些制作后的提示,可能对分析问题有所帮助

The following modules are *disabled* in configure script:
_sqlite3                                                       

The necessary bits to build these optional modules were not found:
_bz2                  _ctypes               _ctypes_test       
_curses               _curses_panel         _dbm               
_gdbm                 _hashlib              _lzma              
_ssl                  _tkinter              _uuid              
readline              zlib                                     
To find the necessary bits, look in configure.ac and config.log.

Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer

Checked 111 modules (31 built-in, 64 shared, 1 n/a on linux-x86_64, 1 disabled, 14 missing, 0 failed on import)


安装python
sudo make install

然后是上面提到的错误

我尝试了以下方法来解决它,发现它不起作用。
1.运行命令安装zlib
sudo apt updatesudo apt install zlib1g zlib1g-dev
1.重新安装原始python版本并从头开始重新安装
1.尝试新的安装命令sudo make altinstall
1.清理旧的构建文件sudo make clean

dtcbnfnu

dtcbnfnu1#

@ewokx你的回答给了我一个好主意,我按照make执行后提示的缺失内容安装了

sudo apt-get install libbz2-dev libffi-dev libncurses-dev libreadline-dev libssl-dev zlib1g-dev

sudo apt-get install libsqlite3-dev libdb-dev libgdbm-dev liblzma-dev tk-dev uuid-dev

字符串

我最终得到以下提示,但在执行sudo apt-get update和sudo apt-get install tk-dev命令后,它仍然存在

The necessary bits to build these optional modules were not found:
_tkinter                                                       
To find the necessary bits, look in configure.ac and config.log.

Checked 111 modules (31 built-in, 78 shared, 1 n/a on linux-x86_64, 0 disabled, 1 missing, 0 failed on import)

最后重新执行以下命令安装,成功,谢谢

./configure --prefix=/usr/local/Python-3.12.0.
make
sudo make install
jihan@ubuntu:/usr/local/Python-3.12.0./bin$ ./python3
Python 3.12.0 (main, Nov 22 2023, 23:19:25) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

的字符串

相关问题