2

I have installed a lot of Python versions and tools without really knowing how they work, and I've dug myself into version hell, and I could use some help digging my way out. The aim of this post is to gain control of my Python versions either by coming to understand how to navigate what I already have, or, probably better, to eliminate unnecessary paths and installations and have one place from which to manage Python use on my machine. If I have to wipe all but the default OS version of Python to set everything up right from the ground up, so be it.

I have the default OSX Python2 installation, an Anaconda installation, which I don't really know how to use, and a Homebrew installation which I don't know how to access.

From the terminal:

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).

My main coding platform is VS Code. I just downloaded Anaconda because it comes pre-bundled with a lot of tools I thought I might want later as I learn more.

Any advice on how to gain consistency and control in this mess would be very much appreciated.

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.

LuosRestil
  • 169
  • 3
  • 12
  • For conda, could you please run 'conda env list'? – Roy2012 May 23 '20 at 16:11
  • Yes, no problem. The result is: `# conda environments: # base * /opt/anaconda3` – LuosRestil May 23 '20 at 16:12
  • 1
    "conda search python" just shows all the versions of python they (conda) have in their repo. It means nothing to your mac, as far as I understand. You can drop that from your question. (I think) – Roy2012 May 23 '20 at 16:13
  • Ah, I see. Will do, thank you. – LuosRestil May 23 '20 at 16:14
  • 1
    and one more thing - it seems that you ran which python (in the terminal) from within a conda environment. Could you please run conda deactivate, and then run 'which python' and 'which python3' again? – Roy2012 May 23 '20 at 16:17
  • It looks like this could be a big part of my problem all along. I had no idea I was in a conda environment. After running 'conda deactivate`, the main terminal now gives exactly the same information as the VS Code terminal for all commands. – LuosRestil May 23 '20 at 16:21
  • 1
    To prevent automatically activating conda env when you open a new terminal, see this question: https://stackoverflow.com/questions/54429210/how-do-i-prevent-conda-from-activating-the-base-environment-by-default – Roy2012 May 23 '20 at 16:24
  • Using Anaconda distribution may be easier to use. I'd look to delete many of you python versions and stick with the 2 distributions by anaconda. IMO. You should use virtual environments and they are a breeze in Anaconda, If you don't want to delete all these pythons then set up your virtaul environments and try running... – Natsfan May 23 '20 at 16:28
  • Also had no idea conda env got activated automatically. Thank you for that link, got that sorted out now. – LuosRestil May 23 '20 at 16:40
  • 1
    I have answered this in https://stackoverflow.com/questions/61811366/how-to-set-the-default-python3-to-python3-7 and https://stackoverflow.com/questions/61823218/how-to-add-anaconda-to-path in details. – Anya Samadi Jun 04 '20 at 01:07

0 Answers0