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

ars1skjm  于 2024-01-06  发布在  Python
关注(0)|答案(1)|浏览(402)

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

  1. Traceback (most recent call last):
  2. File "<frozen zipimport>", line 518, in _get_decompress_func
  3. ModuleNotFoundError: No module named 'zlib'
  4. During handling of the above exception, another exception occurred:
  5. Traceback (most recent call last):
  6. File "<frozen zipimport>", line 566, in _get_data
  7. File "<frozen zipimport>", line 521, in _get_decompress_func
  8. zipimport.ZipImportError: can't decompress data; zlib not available
  9. During handling of the above exception, another exception occurred:
  10. Traceback (most recent call last):
  11. File "<string>", line 6, in <module>
  12. File "<frozen runpy>", line 222, in run_module
  13. File "<frozen runpy>", line 148, in _get_module_details
  14. File "<frozen runpy>", line 112, in _get_module_details
  15. File "<frozen zipimport>", line 137, in get_code
  16. File "<frozen zipimport>", line 700, in _get_module_code
  17. File "<frozen zipimport>", line 568, in _get_data
  18. zipimport.ZipImportError: can't decompress data; zlib not available
  19. Traceback (most recent call last):
  20. File "<frozen runpy>", line 198, in _run_module_as_main
  21. File "<frozen runpy>", line 88, in _run_code
  22. File "/opt/Python-3.12.0/Lib/ensurepip/__main__.py", line 5, in <module>
  23. sys.exit(ensurepip._main())
  24. ^^^^^^^^^^^^^^^^^
  25. File "/opt/Python-3.12.0/Lib/ensurepip/__init__.py", line 284, in _main
  26. return _bootstrap(
  27. ^^^^^^^^^^^
  28. File "/opt/Python-3.12.0/Lib/ensurepip/__init__.py", line 200, in _bootstrap
  29. return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
  30. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  31. File "/opt/Python-3.12.0/Lib/ensurepip/__init__.py", line 101, in _run_pip
  32. return subprocess.run(cmd, check=True).returncode
  33. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  34. File "/opt/Python-3.12.0/Lib/subprocess.py", line 571, in run
  35. raise CalledProcessError(retcode, process.args,
  36. 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.
  37. Makefile:2024: recipe for target 'install' failed
  38. make: *** [install] Error 1

字符串

1、我电脑的env

  1. jihan@ubuntu:/opt/Python-3.12.0$ cat /etc/os-release
  2. NAME="Ubuntu"
  3. VERSION="18.04.6 LTS (Bionic Beaver)"
  4. ID=ubuntu
  5. ID_LIKE=debian
  6. PRETTY_NAME="Ubuntu 18.04.6 LTS"
  7. VERSION_ID="18.04"
  8. HOME_URL="https://www.ubuntu.com/"
  9. SUPPORT_URL="https://help.ubuntu.com/"
  10. BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
  11. PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
  12. VERSION_CODENAME=bionic
  13. UBUNTU_CODENAME=bionic
  14. jihan@ubuntu:/opt/Python-3.12.0$ lscpu
  15. Architecture: x86_64
  16. CPU op-mode(s): 32-bit, 64-bit
  17. Byte Order: Little Endian
  18. CPU(s): 8
  19. On-line CPU(s) list: 0-7
  20. Thread(s) per core: 1
  21. Core(s) per socket: 2
  22. Socket(s): 4
  23. NUMA node(s): 1
  24. Vendor ID: GenuineIntel
  25. CPU family: 6
  26. Model: 151
  27. Model name: 12th Gen Intel(R) Core(TM) i7-12700F
  28. Stepping: 2
  29. CPU MHz: 2111.999
  30. BogoMIPS: 4223.99
  31. Hypervisor vendor: VMware
  32. Virtualization type: full
  33. L1d cache: 48K
  34. L1i cache: 32K
  35. L2 cache: 1280K
  36. L3 cache: 25600K
  37. NUMA node0 CPU(s): 0-7
  38. 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
下面给出了一些制作后的提示,可能对分析问题有所帮助

  1. The following modules are *disabled* in configure script:
  2. _sqlite3
  3. The necessary bits to build these optional modules were not found:
  4. _bz2 _ctypes _ctypes_test
  5. _curses _curses_panel _dbm
  6. _gdbm _hashlib _lzma
  7. _ssl _tkinter _uuid
  8. readline zlib
  9. To find the necessary bits, look in configure.ac and config.log.
  10. Could not build the ssl module!
  11. Python requires a OpenSSL 1.1.1 or newer
  12. 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执行后提示的缺失内容安装了

  1. sudo apt-get install libbz2-dev libffi-dev libncurses-dev libreadline-dev libssl-dev zlib1g-dev
  2. 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命令后,它仍然存在

  1. The necessary bits to build these optional modules were not found:
  2. _tkinter
  3. To find the necessary bits, look in configure.ac and config.log.
  4. Checked 111 modules (31 built-in, 78 shared, 1 n/a on linux-x86_64, 0 disabled, 1 missing, 0 failed on import)

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

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

的字符串

展开查看全部

相关问题