Homebrew Python 3.6



Does the test need tweaking here? As far as I can see in the bottles the new python@2 formula ships no vanilla python executable. It should work either way as the bindings shouldn't be tied to one specific python and the system's python isn't going anywhere anytime soon, but the intention here seems to be to test against the Python it was built against? Nov 29, 2020 This answer is for upgrading Python 2.7.10 to Python 2.7.11 on Mac OS X El Capitan. On Terminal type: brew unlink python After that type on Terminal. Brew install python Solution no. 9: The problem with me is that I have so many different versions of python, so it opens up a different python3.7 even after I did brew link. Python 3.6.8 was the last bugfix release for 3.6.x. Following the release of 3.6.8, we plan to provide security fixes for Python 3.6 as needed through 2021, five years following its initial release. Security fix releases are source-only releases; binary installers are not provided. In today’s blog post I demonstrated how to install OpenCV 3 with Python 2.7 and Python 3 bindings on your macOS system via Homebrew. As you can see, utilizing Homebrew is a great method to avoid the tedious process of manually configuring your CMake command to compile OpenCV via source (my full list of OpenCV install tutorials can be found on this page). Now could create a python 3.6.51 virtual environment to use it in a specific project, and then let brew update your python installation. To achieve that result with the module venv use the -copies option to make sure copies of the binaries (python, pip, etc.) were copied to the virtual environment folder.

Question or issue on macOS:

I’m running MacOS Sierra 10.12.4 and I’ve realized that homebrew python was upgraded to version 2.7.13. How can I switch back to 2.7.10?

How to solve this problem?

Solution no. 1:

First, it’s generally considered bad practice to rely on system python for user land code if you can avoid it. You need to assume that system utilities require a specific version of system python, and your user land code may then be locked to that python version forever, which is not wise (unless you’re writing system utilities, in which case just use /bin/python, but then you wouldn’t be asking this question…).

Secondly, I am unclear why you need 2.7.10 instead of 2.7.13. All pythons with the same minor revision number (2.7) should always be compatible. If you needed 2.6, that would be a different story since that’s a change in minor version. Code written for 2.7.x should all be compatible.

However, assuming your use case really does require using a specific Python version – getting to an actual solution now – be sure sure you really upgraded system python to begin with. If you enter the command: which python, do you get /usr/bin/python (system) or /usr/local/bin/python (brew installed user-land python). For example, /usr/bin/python -V gives me 2.7.10 even though python -V gives me 2.7.13 (via brew).

Homebrew python 3.6

Homebrew Python 3.6 Tutorial

It’s possible that you installed the latest python 2.7.x via brew which puts /usr/local/bin/python as a symlink in your $PATH, or you perhaps have a python alias pointing somewhere you don’t want. Verify your $PATH order.

Homebrew python 3.6 full

You can reset your homebrew python by removing it (brew uninstall python), or by changing the symlink (ln -s -f /usr/bin/python /usr/local/bin/python). However, using virtualenv removes the need for much of these sorts of gymnastics.

If you want to monkey with prior versions of Python installed via homebrew, this answer should help: How to install older formula using Brew?

One final option: if you absolutely must have a specific python version, pyenv can help.

Solution no. 2:

You can switch versions with brew switch. For instance I just downgraded Python 3.7.0 to 3.6.5 like this:

Unfortunately, the brew versions command has been deprecated, and it’s currently pretty complicated to locate the available versions. I’d love to hear a simple solution to this. Meanwhile, if you know the version you want to switch to, try the above command.

3.6

I agree with the answers here that virtualenvs are a good idea, but having the version of Python you need in homebrew is also a good idea. The way my virtualenvs were created, bin/python was a symlink to /usr/local/bin/python, so things broke when Python was updated via homebrew.

Solution no. 3:

Download python 3.6.0 from https://www.python.org/downloads/release/python-360/

Homebrew python 3.6 tutorial

Install it as a normal package.

Run cd /Library/Frameworks/Python.framework/Version

Run ls and all installed Python versions will be visible here.

Run sudo rm -rf 3.7

Check the version now by python3 -V and it will be 3.6 now.

Brew Install Python 3.6.8

Solution no. 4:

Homebrew Python 3.6 Tutorial

There is no need to downgrade python as you can use both on your system.

Homebrew

Places where you want your file to compile with python 2-x.

and where you need python 3

The default usage of python will lead to use the latest version, and downgrading to a particular version is a lot of headache as it is not direct as python is not made backward compatible from 3-x to 2-x.

Solution no. 5:

This is not a direct answer to the question, rather it explains a solution to avoid touching the system python.

The general idea is that you should always install the independent python for your projects. Each project needs its own python version (for compatibility reasons with libraries), and it’s not practical to keep one python version and trying to make it work with multiple projects.

I assume this issue in your system happened because another project required a higher python version and now for your other project you need a lower version python.

The best way to handle python versions is to use virtualenv.

Each project will have it’s own python, so you can have projects that work with python 2.7 and python 3 and they never touch each other’s dependency.

Install different python versions with homebrew and then for each project when you create virtualenv you decide which python to pick. Everytime you work with that project, the python version would be the one you picked yourself when created the virtualenv.

Hope this helps!

After running brew update; brew upgrade, brew updated python to version 3.7.x.x. When my code stopped working, I noticed that some of the 3rd party packages i use are not compatible Python 3.7.x.x yet. So i decided to revert to Python 3.6.5_1 the version that i am certain i will not have any troubles with.

I failed after trying to to revert to an older version using the usual method: brew install python@3.6.5_1 or: brew install python@3.6.5 or even: brew install python@3.6

After spending some time testing solutions i found the following posts that explained the situation to a great extent:

  • https://github.com/tensorflow/tensorflow/issues/25093

So, without further due, here is the solution:

First let’s ask brew to remove the links to the most recent python version, that brew installed automatically:

Then let’s install the version 3.6.5_1 by directing brew to the suitable commit of the python brew formula on the Homebrew formulae repository. The commit ID for Python 3.6.5_1 Formula is: f2a764ef944b1080be64bd88dca9a1d80130c558. To avoid the issue with circular dependencies the flag –ignore-dependencies must be used:

Then let’s ask brew to create the links to the freshly installed version of python:

Now could create a python 3.6.5_1 virtual environment to use it in a specific project, and then let brew update your python installation. To achieve that result with the module venv use the --copies option to make sure copies of the binaries (python, pip, etc.) were copied to the virtual environment folder. If --copies was not specified, venv will create symbolic links to the python binaries, and that means you will lose the correct version of python once brew upgrades the python binaries.

Alternatively, you could stop brew from automatically upgrading python when running brew upgrade. You simply have to tell brew that you don’t want to upgrade the python formula in the future:

You can allow brew to upgrade python by simply reverting the previous action:

I hope this post was useful!