将 pyenv python 链接到 homebrew 以避免安装 homebrew [email protected]

2024-03-28

一些来自brew的包需要[电子邮件受保护] /cdn-cgi/l/email-protection作为依赖。例如:

$ brew deps vim
gdbm
gettext
libyaml
lua
[email protected] /cdn-cgi/l/email-protection
perl
[email protected] /cdn-cgi/l/email-protection
readline
ruby
sqlite
xz

但是,我想用 pyenv 管理我所有的 python 安装,但我不想下载[电子邮件受保护] /cdn-cgi/l/email-protection与酿造。这意味着必须在两个不同的位置安装完全相同版本的 python,我想避免这种情况。通过阅读brew、pyenv 和python,我开始了解到将python 安装在系统的不同部分可能会在将来造成一些麻烦,我也想避免这种情况。不幸的是我似乎无法通过 pyenv 解决brew包中的python依赖关系。下面请按照我尝试克服这个问题的步骤进行操作。

我已经用brew安装了pyenv,并从那里安装了必要的python版本。

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

我尝试根据这个解决这个问题Github讨论 https://github.com/Homebrew/brew/issues/6590通过设置brew别名,例如:

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

由于这没有解决依赖性问题,我尝试创建一个链接[email protected] /cdn-cgi/l/email-protection in /usr/local/Cellar这将指向 pyenv python,某种程度上类似于这个问题 https://stackoverflow.com/questions/30499795/how-can-i-make-homebrews-python-and-pyenv-live-together with:

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

这不起作用,所以我还尝试将链接添加到“/usr/local/bin”:

ln -s  ~/.pyenv/versions/3.8.2 /usr/local/bin/[email protected] /cdn-cgi/l/email-protection

然而,运行brew info vim仍然表明[电子邮件受保护] /cdn-cgi/l/email-protection依赖性未得到满足。

$ 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 ✘, [email protected] /cdn-cgi/l/email-protection ✘, ruby ✘

任何想法如何我可以将我的 pyenv python 安装链接/连接到自制软件,以便额外的[电子邮件受保护] /cdn-cgi/l/email-protection是不是安装了?或者也许使用 pyenv global/local/shell 以另一种方式解决问题?我目前使用的是 macOS Catalina。

任何帮助是极大的赞赏!


2023-09-16 编辑

从brew版本开始4.1.0 https://brew.sh/2023/07/20/homebrew-4.1.0/(2023-07-20发布)有一个新命令称为pyenv-sync https://docs.brew.sh/Manpage#pyenv-sync

$  brew pyenv-sync --help
Usage: brew pyenv-sync

Create symlinks for Homebrew's installed Python versions in ~/.pyenv/versions.

Note that older patch version symlinks will be created and linked to the minor
version so e.g. Python 3.11.0 will also be symlinked to 3.11.3.

  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -v, --verbose                    Make some output more verbose.
  -h, --help                       Show this message.

虽然我还没有尝试过,但这听起来像是将 Homebrew 的 Python 与 pyenv 链接的最佳选择。

编辑结束


不幸的是“取消链接”python从所有公式来看,这有点不必要,因为每次更新您都必须“重新链接”它们。

Take black https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/black.rb, 举个例子:

$ ls -al $(brew --prefix black)/libexec/bin
total 104
drwxr-xr-x  16 thecesrom  staff   512 Jun 11 08:32 .
drwxr-xr-x   6 thecesrom  staff   192 Jun 11 08:32 ..
-rw-r--r--   1 thecesrom  staff  8834 Jun 10 15:27 Activate.ps1
-rw-r--r--   1 thecesrom  staff  1916 Jun 11 08:32 activate
-rw-r--r--   1 thecesrom  staff   865 Jun 11 08:32 activate.csh
-rw-r--r--   1 thecesrom  staff  2005 Jun 11 08:32 activate.fish
-rwxr-xr-x   1 thecesrom  staff   256 Jun 11 08:32 black
-rwxr-xr-x   1 thecesrom  staff   251 Jun 11 08:32 black-primer
-rwxr-xr-x   1 thecesrom  staff   257 Jun 11 08:32 blackd
-rwxr-xr-x   1 thecesrom  staff  1000 Jun 11 08:32 chardetect
-rwxr-xr-x   1 thecesrom  staff   257 Jun 11 08:32 pip
-rwxr-xr-x   1 thecesrom  staff   257 Jun 11 08:32 pip3
-rwxr-xr-x   1 thecesrom  staff   257 Jun 11 08:32 pip3.9
lrwxr-xr-x   1 thecesrom  staff    84 Jun 10 15:27 python -> ../../../../../opt/[email protected] /cdn-cgi/l/email-protection/Frameworks/Python.framework/Versions/3.9/bin/python3.9
lrwxr-xr-x   1 thecesrom  staff    84 Jun 10 15:27 python3 -> ../../../../../opt/[email protected] /cdn-cgi/l/email-protection/Frameworks/Python.framework/Versions/3.9/bin/python3.9
lrwxr-xr-x   1 thecesrom  staff    84 Jun 10 15:27 python3.9 -> ../../../../../opt/py[email protected] /cdn-cgi/l/email-protection/Frameworks/Python.framework/Versions/3.9/bin/python3.9

请注意python, python3 and python3.9全部指向 Homebrew 的python依赖性。所以每次公式都取决于python已更新,您必须unlink所有符号链接并重新创建它们指向您的pyenv-安装版本。但这仍然无法删除python通过下载brew,并且您最终可能会在计算机上安装两次相同的 Python 版本。

查看此问题的另一种方法是添加brew's python to pyenv.

正如你所看到的,就我而言[email protected] /cdn-cgi/l/email-protection作为依赖项安装black和其他公式,所以这就是我所做的。

首先,创建一个symlink at ~/.pyenv/versions.

$ cd ~/.pyenv/versions
$ ln -sfv "$(brew --prefix [email protected] /cdn-cgi/l/email-protection)" 3.9
$ ls -al
total 0
drwxr-xr-x  4 thecesrom  staff  128 Aug 31 07:51 .
drwxr-xr-x  6 thecesrom  staff  192 Jun  8 10:58 ..
drwxr-xr-x  6 thecesrom  staff  192 Aug 31 07:48 2.7.18
lrwxr-xr-x  1 thecesrom  staff   25 Aug 31 07:51 3.9 -> /usr/local/opt/[email protected] /cdn-cgi/l/email-protection

2021-09-06 编辑:我建议使用3.9以避免每次 Python 升级时都必须更改符号链接。

因为我想包含相同的文件夹(bin, include, lib, share)作为我的其他 Python 安装(2.7.18),我通过安装pyenv,然后我创建了一个符号链接include.

$ cd "$(brew --prefix [email protected] /cdn-cgi/l/email-protection)"
$ ln -sfv Frameworks/Python.framework/Versions/3.9/include/python3.9 include
include -> Frameworks/Python.framework/Versions/3.9/include/python3.9

一旦我这样做了,我就创建了symlinks for idle, pip, python and wheel在以下位置:

$ cd "$(brew --prefix [email protected] /cdn-cgi/l/email-protection)/bin"
$ ln -sfv idle3 idle
idle -> idle3
$ ln -sfv pip3 pip 
pip -> pip3
$ ln -sfv python3 python
python -> python3
$ ln -sfv wheel3 wheel
wheel -> wheel3

我这样做是因为我运行时得到以下输出brew link [email protected] /cdn-cgi/l/email-protection:

$ brew link [email protected] /cdn-cgi/l/email-protection
Warning: Already linked: /usr/local/Cellar/[email protected] /cdn-cgi/l/email-protection/3.9.7
To relink, run:
  brew unlink [email protected] /cdn-cgi/l/email-protection && brew link [email protected] /cdn-cgi/l/email-protection

完成后,运行pyenv rehash根据推荐pyenv每当您安装新版本时。

$ pyenv rehash

然后,验证由以下人员管理的所有版本pyenv.

$ pyenv versions
  system
  2.7.18
* 3.9 (set by /Users/thecesrom/.pyenv/version)

最后配置pyenv如所须。就我而言,我设置3.9通过运行作为全局pyenv global 3.9,现在当我跑步时python --version我得到以下输出:

$ python --version
Python 3.9.7
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 pyenv python 链接到 homebrew 以避免安装 homebrew [email protected] 的相关文章

随机推荐