Manage each Python version with Homebrew

Python has a great tool for creating closed environments called virtualenv, tox. There is an elegant tool called latest /) that automates multiple versions of testing. (Personal subjectivity) In order to handle these tools effectively, there is a demand for coexistence of multiple versions of Python. (Well, coexistence of multiple versions isn't limited to Python, it seems to be a requirement that can be either Ruby or Perl, and I think you can find a library for it with a little research.) As software to easily fulfill this request, pythonbrew, pythonz, [pyenv](https:: //github.com/yyuu/pyenv) and so on.

But I dare to use Homebrew

Somehow the reason is (laughs). If I force you to say, I don't want to increase the number of management tools too much. As the number of tools of this type increases, it becomes difficult to understand what is managed, what, and how, and the configuration files (mainly .bashrc / .zshrc) also expand.

Since Homebrew is a general-purpose package manager, it naturally provides software other than Python, and (as I recently learned) Homebrew-Cask , GUI apps can also be managed. If you put it together as much as possible, it will be easier to manage.

There is a minor version of Formula. That is a lie.

The current Homebrew repository HEAD only supports the latest versions of Python 2 and 3 (2.7, 3.4), and other versions cannot be installed.

python


% brew search python
gst-python010  python         python3        wxpython       zpython
homebrew/apache/mod_python

% brew info python
python: stable 2.7.6 (bottled), HEAD
http://www.python.org

…

% brew info python3
python3: stable 3.4.1 (bottled), HEAD
https://www.python.org/

#But I have an old version of Formula ... when and where did I get it ...

% brew list | grep python
python
python26
python3
python31
python32

There are repositories that provide Formulas for different software versions, but not Python. Why is it so… https://github.com/Homebrew/homebrew-versions

Create your own Homebrew repository

So I decided to create a custom Homebrew repository with each version of Formula.

https://github.com/FGtatsuro/homebrew-custom

Creating / using a repository is very easy

  1. Create a repository named homebrew- (ex. Homebrew-custom) on github.
  2. Register the created repository with brew tap (Github user name) / (repository name). (FGtatsuro / custom in this repository)
  3. Use brew update to get the Formula in the registered repository.

Each Formula is based on the original Formula (python.rb, python3.rb) with the following changes.

  1. When installing, use make alt install instead ofmake install. This will prevent symbolic links such as python, python3 from being created under Homebrew's bin (default:/ usr / local / bin /). (A link will be created that includes even minor versions like python3.3.)
  2. pip and easy_install will be installed together, but likewise, these symbolic links will not be created (ex. Pip, pip2) that do not include minor versions.

Both 1 and 2 are to avoid executing an unintended version due to symbolic link overwriting when multiple versions are installed. I think there are pros and cons to deleting the python link, but I also use the environment created with virtualenv for my usual environment, especially because those symbolic links are created in this environment. It doesn't matter. If not, it's a good idea to decide which version you want to use in the main and then create a new symbolic link.

python


% ln -s /usr/local/bin/python34 /usr/local/bin/python

The usual reaction of the person next to me is ...

"Wow, just write a ww MakeFile, isn't it? Www? Does it mean to manage it with Homebrew?" (I feel like I said that)

Postscript (2014/05/26)

It seems that python, python3 may be requested due to the dependency of another Formula, and at that time, it conflicts with python27, python34 put in the custom repository. So, it's safer to use the latest one from the original repository.

Recommended Posts

Manage each Python version with Homebrew
Check version with python
Manage Python multiple version environment with Pythonz, virtualenv
Manage cron jobs with python
Manage python environment with virtualenv
Specify python version with virtualenv
[Python Windows] pip install with Python version
Publish your own Python library with Homebrew
Manage multiple Python versions with update-alternatives (Ubuntu)
Statistics with python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
[Python] Each hash
Bingo with python
Zundokokiyoshi with python
PYTHON2.7 64bit version
Excel with Python
Microcomputer with Python
Cast with python
Let's write FizzBuzz with an error: Python Version
I wanted to install Python 3.4.3 with Homebrew + pyenv
[Rust / Python] Handle numpy with PyO3 (August 2020 version)
[Improved version] Script to monitor CPU with Python
Manage AWS nicely with the Python library Boto
Install Python 3 on MacOS Catalina (with Homebrew only)
Manage multiple context managers together with Python contextlib.ExitStack
Kernel / Python version summary for each Debian release
Homebrew Vim doesn't start with Python 3.8 error Note
Solve "AtCoder version! Ant book (beginner)" with Python!
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Scraping with Python (preparation)
Text mining with Python ① Morphological analysis (re: Linux version)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Serial communication with python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Introduced Boost.python with homebrew
homebrew python environment construction
Scraping with Python + PhantomJS
Create Python version Lambda function (+ Lambda Layer) with Serverless Framework