pyenv 安装任何 python 版本都会导致 ModuleNotFoundError:没有名为 '_ssl' 的模块

问题描述 投票:0回答:1

作为 ubuntu WSL 系统上的新用户,我正在使用 pyenv 安装 python 版本来管理多个版本,我正在使用标准说明:

我安装了自制程序:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

更新了brew并使用homebrew安装了pyenv(目前推荐的过程)

brew update
brew install pyenv

使用这个新安装的 pyenv 安装任何 python 版本:

pyenv install 3.10.13

我收到以下错误:

Downloading Python-3.10.13.tar.xz...
-> https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tar.xz
Installing Python-3.10.13...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/adam/.pyenv/versions/3.10.13/lib/python3.10/ssl.py", line 99, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Ubuntu 20.04 using python-build 2.3.35-5-g2d850751)

Inspect or clean up the working tree at /tmp/python-build.20231227145009.23362
Results logged to /tmp/python-build.20231227145009.23362.log

Last 10 log lines:
        LD_LIBRARY_PATH=/tmp/python-build.20231227145009.23362/Python-3.10.13 ./python -E -m ensurepip \
                $ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmprqhmro5y
Processing /tmp/tmprqhmro5y/setuptools-65.5.0-py3-none-any.whl
Processing /tmp/tmprqhmro5y/pip-23.0.1-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: The scripts pip3 and pip3.10 are installed in '/home/adam/.pyenv/versions/3.10.13/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.0.1 setuptools-65.5.0

对于原因有什么想法吗? 我尝试了以下方法但没有成功:

sudo apt install libssl-dev
python linux openssl homebrew pyenv
1个回答
0
投票

TLDR:删除brew 的 openssl 解决了该问题。

信用到期的信用: 在发布这个问题后不久,我在 linux mint 论坛上找到了这个错误的解决方案: https://forums.linuxmint.com/viewtopic.php?t=402803

我不会关闭问题,而是回答它以供将来参考:

通过以下输出,brew 安装了 openssl,即使我没有意识到我已经明确让brew 执行此操作 - 我相信当它安装 pyenv openssl 的依赖项时一定是其中之一。

adam:~/project$ brew list | grep openssl
openssl@3

这导致了一个问题,并通过从brew安装中删除openssl来修复:

brew uninstall --ignore-dependencies openssl

以这种方式简单地删除 openssl 就可以为 pyenv 提供成功的环境:

pyenv install 3.10.13
Downloading Python-3.10.13.tar.xz...
-> https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tar.xz
Installing Python-3.10.13...
Installed Python-3.10.13 to /home/adam/.pyenv/versions/3.10.13
© www.soinside.com 2019 - 2024. All rights reserved.