将pyenv python链接到自制软件以避免安装homebrew python@3.8 [英] Linking pyenv python to homebrew in order to avoid homebrew python@3.8 installation

查看:154
本文介绍了将pyenv python链接到自制软件以避免安装homebrew python@3.8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

brew的某些软件包需要python@3.8作为依赖项。例如:

Some packages from brew require python@3.8 as a dependency. For example:

$ brew deps vim
gdbm
gettext
libyaml
lua
openssl@1.1
perl
python@3.8
readline
ruby
sqlite
xz

但是,我想用pyenv管理我所有的python安装,并且我不想用brew下载python@3.8。这意味着必须在2个不同的位置安装完全相同的python版本,我想避免这种情况。通过阅读brew,pyenv和python,我了解到将python安装在系统的不同部分可能会在将来引起一些麻烦,我也想避免这种麻烦。不幸的是,我似乎无法通过pyenv解决brew软件包中的python依赖关系。下面按照我尝试克服的步骤进行操作。

However, I want to manage all my python installations with pyenv and I would not like to download python@3.8 with brew. This would imply having to exactly same versions of python installed in 2 different locations, which I would like to avoid. Reading up on brew, pyenv and python I´ve come to understand that having python installed in different parts of the system may cause some trouble in the future, which I'd also like to avoid. Unfortunately I cannot seem to resolve the python dependency in brew packages through pyenv. Below follow the steps I've tried to overcome this.

我已经安装了brew和pyenv以及必要的python版本。

I have installed pyenv with brew, and necessary python versions from there.

$ pyenv versions
  system
* 3.8.2 (set by PYENV_VERSION environment variable)

我已尝试根据此通过设置Brew别名,例如:

I have tried solving this according to this Github discussion by setting a brew alias such as:

alias brew='env PATH=${PATH//$(pyenv root)\/shims:/} brew'

因为那没有解决依赖问题,我尝试在 / usr / local / Cellar 中为 python@3.8 创建一个链接pyenv python,在某种程度上类似于此问题 with:

As that did not resolve the dependency issue, I tried create a link for python@3.8 in /usr/local/Cellar which would point to the pyenv python, somehow similar to this issue with:

ln -s  ~/.pyenv/versions/3.8.2 $(brew --cellar python)@3.8

这没有用,所以我也尝试将链接添加到 / usr / local / bin:

This did not work, so I have also tried adding the link to ´/usr/local/bin´:

ln -s  ~/.pyenv/versions/3.8.2 /usr/local/bin/python@3.8

但是,运行 brew info vim 仍然显示python@3.8依赖项是

However, running brew info vim still shows that the python@3.8 dependency is not satisfied.

$ brew info vim
vim: stable 8.2.0900 (bottled), HEAD
Vi 'workalike' with many additional features
https://www.vim.org/
Conflicts with:
  ex-vi (because vim and ex-vi both install bin/ex and bin/view)
  macvim (because vim and macvim both install vi* binaries)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/vim.rb
==> Dependencies
Required: gettext ✘, lua ✘, perl ✘, python@3.8 ✘, ruby ✘

任何想法如何将pyenv python安装链接/连接到自制软件,以便不安装其他python@3.8?或者也许使用pyenv global / local / shell以另一种方式解决问题?我目前正在使用macOs Catalina。

Any ideas how can I link/connect my pyenv python installation to homebrew so that the additional python@3.8 is not installed? Or maybe solve the issue in another manner using pyenv global/local/shell? I am currently using macOs Catalina.

任何帮助将不胜感激!

推荐答案

首先,我希望将冗余度降至最低!我很遗憾地看到没有答案,但我想,我已经想通了。 您可以这样做,尽管Homebrew 警告它,并且您正在涉足依靠自己的理解来支持该用例的领域(就像Homebrew在其帖子中所指出的那样)。您链接到的 SO问题具有链接的正确想法,但据我所知,他们没有获得正确的链接。我全心全意地尝试和学习(这是唯一的方法吗?),所以一定要去做,但是如果您不能深入研究自己的,那么您也不会得到太多支持。 $ PATH 并遵循您自己设置的链接。

First of all, I appreciate the desire to keep redundancy to a minimum! I was sad to see no answers, but I think that I've figured it out. You can do this, though Homebrew warns against it and you're wading into the territory of relying on your own understanding to support this use case (as Homebrew states in their post). The SO issue you linked to has the right idea with the links, but from what I can tell they don't get the links quite right. I'm all for experimenting and learning (it's the only way?), so by all means go for it, but again you won't get much support if you're not able to dig into your own $PATH and follow the links that you've set up yourself.

如果您已经有了Homebrew python3的任何痕迹,请首先清除它们( brew取消链接python3 brew卸载python3 )。如果您已经从Homebrew获得python@3.8,则在卸载它时,请注意依赖于它的软件包(例如 ffmpeg ),然后在以后重新安装。

If you already have any traces of Homebrew's python3, first get rid of them (brew unlink python3 and brew uninstall python3). If you already had python@3.8 from Homebrew, when uninstalling it, note the packages that depended on it (for example, ffmpeg), and reinstall them after.

截至本文,Homebrew预计将使用Python 3.8.6,因为它是python@3.8,因此请首先使用pyenv 遵循他们的文档

As of this post, Homebrew is expected Python 3.8.6 for it's python@3.8, so first install that version with pyenv following their documentation:

pyenv install 3.8.6

(默认情况下)会将实际的Python安装放在

That will put (by default) the actual Python install in

~/.pyenv/versions/3.8.6

现在,我们只需要添加一个链接,然后让brew完成其余的工作即可。我将在此处使用完整路径,因此您可以在任何地方运行此路径(并记住将 ln -s ... ... 读为 Link -Symbolic Target LinkName):

Now we just need to add one link, and then let brew do the rest. I'll use full paths here, so you can run this from anywhere (and remember to read ln -s ... ... in your head as Link -Symbolic Target LinkName):

ln -s ~/.pyenv/versions/3.8.6 $(brew cellar python)/3.8.6

使用 -f 标志,您可以省略结尾的 /3.8.6 ,因为 ln 将使用目标的名称。为了尽可能明确地显示链接,您应该

With the -f flag, you could have omitted the trailing /3.8.6, as ln will use the name of the target. To be as explicit as possible on the link, you should have

ln -s ~/.pyenv/versions/3.8.6 /usr/local/Cellar/python@3.8/3.8.6

结果如下所示:

➜  ~ ll $(brew --cellar python) 
total 0
lrwxr-xr-x  1 [my username]  admin    36B Oct 14 16:52 3.8.6 -> 
/Users/[my username]/.pyenv/versions/3.8.6

最后,让Homebrew管理其余必要的链接:

Finally, let Homebrew manage the rest of necessary linking:

brew link python3

这篇关于将pyenv python链接到自制软件以避免安装homebrew python@3.8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆