zlib1g-dev已安装,但显示ModuleNotFoundError:没有名为“ zlib”的模块

问题描述

在我的Debian 10操作系统中,我有多个Python版本,分别是2.7、3.7和3.8。对于Python 3.8,pip不起作用(无模块名称pip),我尝试使用'sudo python3.8 get-pip.py'为Python 3.8安装pip,它显示以下错误

Traceback (most recent call last):
  File "<frozen zipimport>",line 520,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 568,in _get_data
  File "<frozen zipimport>",line 523,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 "get-pip.py",line 23704,in <module>
    main()
  File "get-pip.py",line 198,in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py",line 82,in bootstrap
    from pip._internal.cli.main import main as pip_entry_point
  File "<frozen zipimport>",line 241,in load_module
  File "<frozen zipimport>",line 709,in _get_module_code
  File "<frozen zipimport>",line 570,in _get_data
zipimport.ZipImportError: can't decompress data; zlib not available

然后,我尝试使用'sudo apt install zlib1g-dev'来安装zlib,但它表明该软件包已在系统中。

Reading package lists... Done
Building dependency tree       
Reading state @R_943_4045@ion... Done
zlib1g-dev is already the newest version (1:1.2.11.dfsg-1).
The following packages were automatically installed and are no longer required:
  adb android-libadb android-libbase android-libboringssl
  android-libcrypto-utils android-libcutils android-liblog
  android-sdk-platform-tools-common arch-test bridge-utils cloud-image-utils
  debootstrap distro-info genisoimage libayatana-appindicator3-1
  libayatana-ido3-0.4-0 libayatana-indicator3-7 libboost-log1.67.0
  libboost-program-options1.67.0 libboost-regex1.67.0
  libboost-serialization1.67.0 liblxc1 libmotif-common libnma0 libpam-cgfs
  libprotobuf-lite17 libsdl2-image-2.0-0 libu2f-udev libxm4 lxc lxc-templates
  lxcfs network-manager-gnome qemu-utils squashfs-tools uidmap
Use 'sudo apt autoremove' to remove them.
0 upgraded,0 newly installed,0 to remove and 127 not upgraded.

解决方法

您可以尝试执行以下操作: sudo apt-get install zlib1g-dev