如何管理多个Python版本和路径-MacOS

我已经安装了许多Python版本和工具,却并不真正了解它们的工作方式,我已经陷入了地狱的深渊,我可以借助一些帮助来寻找出路。这篇文章的目的是通过了解如何导航我已有的东西来获得对我的Python版本的控制,或者可能更好地是消除不必要的路径和安装,并有一个地方可以管理我的机器上的Python使用情况。如果我必须擦除除默认操作系统版本的Python之外的所有内容,以便从头开始设置所有内容,那就这样吧。

我有默认的OSX Python2安装,Anaconda安装(我真的不知道如何使用)和Homebrew安装(我不知道如何访问)。

从终端:

brew info python shows:

python: stable 3.7.7 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.7 (4,006 files, 61.0MB)
  Poured from bottle on 2020-05-23 at 09:31:39
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: pkg-config ✘
Required: gdbm ✔, openssl@1.1 ✔, readline ✔, sqlite ✔, xz ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 229,317 (30 days), 1,113,249 (90 days), 5,317,787 (365 days)
install-on-request: 176,164 (30 days), 662,134 (90 days), 2,762,762 (365 days)
build-error: 0 (30 days)

which python and python --version show /opt/anaconda3/bin/python and Python 3.7.4 respectively in terminal and PyCharm terminal.

From VS Code terminal, which python shows /usr/bin/python and python --version shows Python 2.7.16, while which python3 shows /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 and python3 --version shows Python 3.7.4.

Using pipenv to create a virtual environment in VS Code uses /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 (3.7.4).

我的主要编码平台是VS Code。我刚刚下载了Anaconda,因为它预先捆绑了很多工具,我以为以后学到更多信息后可能会想要。

任何关于如何在此混乱中获得一致性和控制的建议将不胜感激。

edit: After exiting the conda environment I didn't realize I was in, using pipenv to create a virtual environment in VS Code sometimes uses /usr/local/Cellar/pipenv/2018.11.26_3/libexec/bin/python3.8 (3.8.1) and sometimes uses /Library/Frameworks/Python.framework/Versions/3.7/bin/python3. I can't see why it will sometimes be one vs the other.

评论