Ubuntu中的Pyenv 22.04:错误:未编译Python SSL扩展。缺少openssl lib?

发布于 2025-02-12 12:52:41 字数 1809 浏览 0 评论 0 原文

使用新的安装(我在另一个分区中有Ubuntu 20)搬到Ubuntu 22,而最后一件我需要使用它来使Pyenv运行正常。

尝试 pyenv install x.xx.x 在此错误中失败: 错误:未编译Python SSL扩展名。缺少openssl lib?

我“尝试尝试”官方文档提出

我说“尝试尝试”,因为我不明白我要做什么。 他们给出了这些命令:

CPPFLAGS="-I<openssl install prefix>/include" \
LDFLAGS="-L<openssl install prefix>/lib" \
pyenv install -v <python version>

但是我不知道“ OpenSSL安装前缀”是什么意思。我以为是openssl安装dir,所以我做到了:

openssl version -d
OPENSSLDIR: "/home/linuxbrew/.linuxbrew/etc/[email protected]"

即使我在此文件夹中看到arent'任何 incept lib subfolders,我还是通过这样做尝试了:

CPPFLAGS="-I/home/linuxbrew/.linuxbrew/etc/[email protected]/include" \
LDFLAGS="-L/home/linuxbrew/.linuxbrew/etc/[email protected]/lib" \
pyenv install -v 3.10.0

最终获得了相同的错误消息。

要说,我尝试了许多在其他地方发现的其他东西,但没有任何效果,但是为了简单起见,我坚持官方的迹象。

如果您遇到了同样的问题,而解决方案来自除这些命令以外的其他地方,请分享!

非常感谢:)

更新

&lt; openssl install install prefix&gt; 仅引用基本路径或基本文件夹,只是该自制者决定发明一个新名称,因为...好吧,我猜是一些非常重要的原因。

仅通过替换&lt; openssl install precix&gt; $(brew -prefix openssl)来解决此部分。

请参阅我对下面问题的回答,以了解它如何对我有效,但是根据我一直在看到和尝试的所有不同解决方案来判断,每种情况可能都需要不同的解决方案。祝你好运!

Moving to Ubuntu 22 with a fresh install (I have Ubuntu 20 in another partition) and the last piece I need to use it for working it to have pyenv running fine.

When trying to pyenv install x.xx.x it fails with this error:
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

I "tried to try" what the official docs proposes:

I said "tried to try" because I don't understand what I have to do.
They give these commands:

CPPFLAGS="-I<openssl install prefix>/include" \
LDFLAGS="-L<openssl install prefix>/lib" \
pyenv install -v <python version>

But I don't know what the "openssl install prefix" means. I assumed it's the openssl installation dir, so I did:

openssl version -d
OPENSSLDIR: "/home/linuxbrew/.linuxbrew/etc/[email protected]"

Even though I see that in this folder there arent' any include or lib subfolders, I tried it anyway by doing this:

CPPFLAGS="-I/home/linuxbrew/.linuxbrew/etc/[email protected]/include" \
LDFLAGS="-L/home/linuxbrew/.linuxbrew/etc/[email protected]/lib" \
pyenv install -v 3.10.0

Which ended up with the same error message.

Gotta say, I tried a lot of other stuff that I found in other places and nothing worked, but for the sake of simplicity I'm sticking with the official indications.

If you faced the same problem and the solution came from somewhere else than these commands, please share!

Many thanks :)

Update

<openssl install prefix> just refers to the base path or base folder, just that Homebrew decided to invent a new name because... well, some very important reason I guess.

This part gets solved by just replacing <openssl install prefix> by $(brew --prefix openssl).

See my own answer to the question below to see how it worked for me, but judging for all the different solutions that I've been seeing and trying, every case might need a different solution. Good luck!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

疏忽 2025-02-19 12:52:45

Ubuntu 16.04。旗帜对我不起作用。配置LDCONFIG帮助:

1. sudo nano /etc/ld.so.conf.d/lib.conf
write path to ssl lib: "/usr/local/ssl"
2. sudo ldconfig
3. pyenv install 3.11 
4. Profit!

可能需要从来源安装OpenSSL:

  1. wget http://www.openssl.org/source/openssl-3.0.7.ta​​r.gz (因为 https://www.openssl.org/news/secadv/20221101.txt
  2. tar -xzf openssl-3.0.7.ta​​r.gz
  3. make&amp; amp;&amp;&amp; Sudo进行安装

Ubuntu 16.04. The flags didn't work for me. Configuring ldconfig helped:

1. sudo nano /etc/ld.so.conf.d/lib.conf
write path to ssl lib: "/usr/local/ssl"
2. sudo ldconfig
3. pyenv install 3.11 
4. Profit!

May need to install openssl from source:

  1. wget http://www.openssl.org/source/openssl-3.0.7.tar.gz (because https://www.openssl.org/news/secadv/20221101.txt )
  2. tar -xzf openssl-3.0.7.tar.gz
  3. make && sudo make install
抱着落日 2025-02-19 12:52:45

只是为了创建答案作为选项。问题很可能是 python3.10 的开发标题尚未在 python3-dev 中。安装 python3.10-dev ,您应该很好。

Just to create an answer as an option. The problem is most likely that the dev headers for python3.10 is not yet in python3-dev. Install python3.10-dev and you should be good to go.

巷雨优美回忆 2025-02-19 12:52:45

在尝试其他几个选择后,这为我解决了问题。

echo 'export PATH="/home/linuxbrew/.linuxbrew/opt/openssl@3/bin:$PATH"' >> /home/*user*/.bashrc

This solved the issue for me after attempting several other options.

echo 'export PATH="/home/linuxbrew/.linuxbrew/opt/openssl@3/bin:$PATH"' >> /home/*user*/.bashrc
避讳 2025-02-19 12:52:44

关于&lt; openssl安装前缀&gt; 的疑问是,我将编辑澄清的问题。

关于如何使Pyenv安装版本成功地尝试了我发现有关该主题的所有内容,这是对我有用的唯一内容:

LDFLAGS="-Wl,-rpath,$(brew --prefix openssl)/lib" \
CPPFLAGS="-I$(brew --prefix openssl)/include" \
CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" \
pyenv install -v 3.9.5

对于每个新版本,我都使用此命令并有效。

请注意:

  • 我尝试以几种不同的方式在启动时设置这些Vars,而仅通过执行 pyenv install xx.xx ,它并没有起作用,我总是必须使用完整的命令no不管是什么。
  • 不会安装任何3.7.x版本。我知道在文档中,命令设置了一个特定的变化,设置了3.7的变量:不仅我尝试过并且仍然无法使用,而且可以使用3.7的变体,这是我需要使用的。安装其他版本。幸运的是,我可以将3.7的唯一项目更新为较新的Python版本,因此我不再需要3.7。

对所有这些混乱都不满意,但至少现在我可以使用22.04进行工作。

编辑:我尝试了Jakob的建议将其添加到.bashrc,因此:

export LDFLAGS="-Wl,-rpath,$(brew --prefix openssl)/lib"
export CPPFLAGS="-I$(brew --prefix openssl)/include"
export CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)"

然后我做了 $ shell 重新加载它,然后 pyenv install xx.xx.xx.xx 工作正常。

About the doubt on what <openssl install prefix> is, I'll edit the question clarifying it.

About how to make pyenv install versions successfully, after trying everything I found about the topic that's the only thing that worked for me:

LDFLAGS="-Wl,-rpath,$(brew --prefix openssl)/lib" \
CPPFLAGS="-I$(brew --prefix openssl)/include" \
CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" \
pyenv install -v 3.9.5

For every new version, I use this command and it works.

Note that:

  • I tried to set these vars at startup, in a couple of different ways, and it didn't work by just doing pyenv install xx.xx, I always have to use the full command no matter what.
  • It won't install any 3.7.x version. I know in the docs there's a specific variation of the command setting a variable for the 3.7: not only I tried that and still doesn't work, but the variation that's suposed to work with 3.7, is what I needed to use in order to install the other versions. Luckily I could update the only project I had with 3.7 to a newer Python version so I don't need 3.7 anymore.

Not happy at all with all this mess but at least now I can use 22.04 for working.

Edit: I tried Jakob's suggestion to add it to .bashrc, like this:

export LDFLAGS="-Wl,-rpath,$(brew --prefix openssl)/lib"
export CPPFLAGS="-I$(brew --prefix openssl)/include"
export CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)"

Then I did $SHELL to reload it, and then pyenv install xx.xx.xx worked fine.

无需解释 2025-02-19 12:52:44

我通过在Ubuntu 22.04.1 LTS上安装libssl-dev来解决此错误

   sudo apt install libssl-dev 

I managed to solve this error by installing libssl-dev on Ubuntu 22.04.1 LTS

   sudo apt install libssl-dev 
神经大条 2025-02-19 12:52:44

上下文

我遇到了POP!_OS 22.04(基于Ubuntu 22.04)的错误,我将其用作Homebrew作为包装管理人员之一。

我无法获得上述工作的任何答案,也无法提出任何建议 https:https: //github.com/pyenv/pyenv/wiki/common-build-problems 上班。

解决方案

对我有用的是(暂时)卸载Homebrew OpenSSL软件包,确保通过APT-GET安装OpenSSL V3,然后(选择)通过Homebrew重新安装OpenSSL。

  1. (暂时)卸载自制openssl
      brew unistall  -  ignore依赖性 [电子邮件&nbsp; prected] 
     
  2. 确保通过APT-GET安装OpenSSL V3
      sudo apt-get更新
    sudo apt-get安装openssl libssl-dev
     
  3. (可选)重新安装自制openssl
      brew install 受保护] 
     

注意 :这不是解决方案,而是解决方案。这不是每个人,但希望这对我以外的人有帮助。

Context

I had the same error from Pop!_OS 22.04 (based on Ubuntu 22.04), which I use Homebrew as one of the package managers for.

I could not get any of the answers above to work, nor any of the suggestions https://github.com/pyenv/pyenv/wiki/Common-build-problems to work.

Workaround

What worked for me was (temporarily) uninstalling the Homebrew openssl package, making sure openssl v3 was installed via apt-get, and then (optionally) reinstalling openssl via Homebrew.

  1. (temporarily) uninstall Homebrew openssl
    brew uninstall --ignore-dependencies [email protected]
    
  2. make sure openssl v3 is installed via apt-get
    sudo apt-get update
    sudo apt-get install openssl libssl-dev
    
  3. (optionally) reinstall Homebrew openssl
    brew install [email protected]
    

Note: This isn't a solution so much as a workaround. It's not for everyone, but hopefully it's helpful for someone beyond me.

谁的新欢旧爱 2025-02-19 12:52:44

整个下午,我都在同一问题上苦苦挣扎,上面没有解决方案,并且在一点点挖掘方面,将问题跟踪到 pyenv install 使用的GCC问题。 (请参阅,例如,在这里在这里。)

简而言之, Python正在安装与自制的建筑依赖关系;但是, pyenv install 似乎使用System GCC代替Homebrew的GCC,这会引起问题。一个对我有用的简单解决方案是用 pyenv install 指向Homebrew的GCC,以让Pyenv在世界上运行:

CC="$(brew --prefix gcc)/bin/gcc-12" \
pyenv install --verbose 3.9.7

注意:检查正确的GCC版本( gcc-ccc-11 GCC-12 等)来自目录 $(BREW-PREW-PREFIX GCC)/bin

为了避免每次运行 pyenv install 时必须手动指向Homebrew的GCC,请为由Homebrew管理的Pyenv安装创建一个别名:

alias pyenv-install-with-brew='CC="$(brew --prefix gcc)/bin/gcc-12" pyenv install'

I struggled with the same issue for a whole afternoon, with none of the solutions above working, and with a little bit of digging, tracked the problem down to issues with the gcc that pyenv install uses. (See, e.g., here and here.)

In short, Python is being installed with Homebrew-managed build dependencies; however, pyenv install seems to use system gcc instead of Homebrew's gcc, which causes issues. A simple solution that worked for me is to point at Homebrew's gcc with pyenv install to let pyenv operate in the world it knows:

CC="$(brew --prefix gcc)/bin/gcc-12" \
pyenv install --verbose 3.9.7

Note: check the correct gcc version (gcc-11, gcc-12, etc.) from the directory $(brew --prefix gcc)/bin.

To avoid having to manually point to Homebrew's gcc every time running pyenv install, create an alias for Homebrew-managed pyenv installation:

alias pyenv-install-with-brew='CC="$(brew --prefix gcc)/bin/gcc-12" pyenv install'
梦在夏天 2025-02-19 12:52:44

我也遇到了这个问题,不必要地解决了它。所以我希望这会有所帮助。

1-确保您遵循ubuntu的pyenv构建指南中的步骤noreferrer“> https://github.com/pyenv/pyenv/wiki#suggested-build-environment )并安装了所有必要的APT软件包。

2-如果中的第一个项目,其中Openssl 显示了酿造码的路径。您可能想更改此问题。您只需卸载openssl@3和 [email&nbsp; email&nbsp;然后,默认情况下,它应该使用openssl的公共安装。

我首先试图使其与Brew OpenSSL安装一起使用,但没有真正起作用。只有在从Brew中卸载OpenSSL之后,它就没有任何问题了。

I also had this problem and it took unnecessarily long to solve it. So I hope this helps.

1- Make sure that you followed the steps in the build guide of pyenv for Ubuntu (https://github.com/pyenv/pyenv/wiki#suggested-build-environment) and installed all the necessary apt packages.

2- If the first item in where openssl shows a path to brew dirs. You might want to change this. You can simply uninstall openssl@3 and [email protected] via brew. Then it should use the apt installation of openssl by default.

I first tried to make it work with brew openssl installation but nothing really worked. Only after uninstalling openssl from brew it worked without any issues.

書生途 2025-02-19 12:52:44

我也有同样的问题。
我在Ubuntu上使用Linuxbrew 20.04。以上答案对我不起作用,因此我选择保持简单,根本不使用Brew

Unstall Pyenv

BREW UNSTALL PYENV

从源中安装Pyenv的PyEnv,

git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv
    
#install needed dependencies (without brew)
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \
liblzma-dev python-openssl git


#setup path
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

现在您可以安装

pyenv install 3.11 install 3.11 .2

注意:Pyenv将在您打开新外壳后立即停止工作。因此,您需要强制初始化。只需更新您的〜/.. profile或〜/.bash_profile(在这种情况下,您需要注销)或更新您的〜/.bashrc

### Add pyenv if exists 
if [ -d "$HOME/.pyenv" ]; then
    #setup python
    export PYENV_ROOT="$HOME/.pyenv"
    command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"
fi

希望它适合像我一样对我的人读书。我花了比一天更长的时间来弄清楚最好的解决方案是避免brew for pyenv。
该解决方案也很优雅,因为它不需要您从酿造中添加任何别名或卸载OpenSSL。

I had your same exact issue.
I am using linuxbrew on Ubuntu 20.04. None of the above answers worked for me, so I opted for keeping it simple and simply not using pyenv provided by brew

uninstall pyenv

brew uninstall pyenv

Install pyenv from source

git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv
    
#install needed dependencies (without brew)
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \
liblzma-dev python-openssl git


#setup path
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

now you can install

pyenv install 3.11.2

note: pyenv will stop working as soon as you open a new shell. You therefore need to force initialisation. Just update your ~/.profile or ~/.bash_profile ( in this case you need to logout after that) or update your ~/.bashrc

### Add pyenv if exists 
if [ -d "$HOME/.pyenv" ]; then
    #setup python
    export PYENV_ROOT="$HOME/.pyenv"
    command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"
fi

Hope it works for the folks reading like it did for me. It took me longer than a day to figure out the best solution was simply avoid brew for pyenv.
This solution is also elegant because it does not require you to add any alias or uninstall openssl from your brew.

轻许诺言 2025-02-19 12:52:44

在我的主机上,我必须执行 brew install openssl ,它安装openssl@3但是 brew -prefix openssl 仍然链接到openssl@1

我需要完全输入建造Python的路径3.9.13。也许有更好的方法来执行前缀链接。

LDFLAGS="-Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib" \
CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/openssl@3/include" \
CONFIGURE_OPTS="--with-openssl=/home/linuxbrew/.linuxbrew/opt/openssl@3" \
pyenv install -v 3.9.13

on my host I have to do a brew install openssl, it install openssl@3 but brew --prefix openssl still links to openssl@1

I need to fully type out the path to build python 3.9.13. maybe there is a better way to do a prefix link.

LDFLAGS="-Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib" \
CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/openssl@3/include" \
CONFIGURE_OPTS="--with-openssl=/home/linuxbrew/.linuxbrew/opt/openssl@3" \
pyenv install -v 3.9.13
煞人兵器 2025-02-19 12:52:44
  1. wget (因为 httpps://www.openssl.org/news/news/news/news/news/secadv/secadv/20221101111111.txtxt ))
  2. tar -xzf openssl -3.0.7.ta​​r.gz
  3. &amp;&amp; sudo make install
  4. pyenv安装3.xx(全部很好)
  1. wget http://www.openssl.org/source/openssl-3.0.7.tar.gz (because https://www.openssl.org/news/secadv/20221101.txt )
  2. tar -xzf openssl-3.0.7.tar.gz
  3. make && sudo make install
  4. pyenv install 3.x.x (all fine)
↙厌世 2025-02-19 12:52:43

遇到了同样的麻烦,对我来说,它在运行关注命令后起作用(check https:// github:// github .com/pyenv/pyenv/wiki#建议建立 - 环境)。

sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

可以安装而没有其他标志。

pyenv install -v 3.9.13

Had same trouble, for me it worked after ran following command(check https://github.com/pyenv/pyenv/wiki#suggested-build-environment).

sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

Could install without additional flags.

pyenv install -v 3.9.13
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文