简体   繁体   English

如何在macOS Catalina中将python自制版本设置为默认值

[英]How to set python homebrew version as default in macos Catalina

For quite some time now I have been having problems configuring python and as a result I have many versions installed.很长一段时间以来,我一直在配置 python 时遇到问题,因此我安装了许多版本。 When I enter the command which -a python python2 python2.7 python3 python3.6 python3.7 python3.8 I get the following:当我输入which -a python python2 python2.7 python3 python3.6 python3.7 python3.8命令时,我得到以下信息:

/usr/bin/python
/usr/bin/python2
/usr/bin/python2.7
/usr/local/bin/python3
/usr/bin/python3
/usr/local/bin/python3.7

But searching by hand I also found:但是手动搜索我也发现:

/usr/local/Cellar/python
/usr/local/Cellar/python@2
/usr/local/Cellar/python@3.8

which python shows that the default python is pointing to systems python, not homebrew which python显示默认 python 指向系统 python,而不是自制软件

/usr/bin/python

My .bash_profile config is:我的.bash_profile配置是:

export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/opt/:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin

I want to achieve a few things:我想实现几件事:

  1. Control python from Homebrew only.仅从 Homebrew 控制 python。
  2. Maintain the factory python installations in MACOS Catalina and remove those that are not needed.维护 MACOS Catalina 中的工厂 python 安装并删除那些不需要的。
  3. Set homebrew's python as my default installation.将 homebrew 的 python 设置为我的默认安装。

Edit 1: After following all the instruction given by @Akbar30bill I have the following error:编辑 1:按照@Akbar30bill 给出的所有说明后,出现以下错误:

Stevens-MacBook-Pro:~ setegonz$ python ––version 

/Users/setegonz/.pyenv/versions/3.8.1/bin/python: can't open file '––version': [Errno 2] No such file or directory

i highly suggest using pyenv its brew compatible and managing python version is easy to install just use我强烈建议使用pyenv ,它的 brew 兼容和管理 python 版本易于安装,只需使用

$ brew update
$ brew install pyenv

Add pyenv init to your shell将 pyenv init 添加到您的 shell

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

Restart your shell重启你的 shell

$ exec "$SHELL"

Install Python versions into $(pyenv root)/versions将 Python 版本安装到 $(pyenv root)/versions

$ pyenv install 3.8.1
$ pyenv global 3.8.1

it also manages pip version to be linked with current python instalation它还管理与当前 python 安装链接的 pip 版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM