[PYTHON] Macports easy_install automatically resolves and runs the version

In an environment where you have installed multiple Python versions with different versions on Macports and are doing various things, when you inadvertently hit ʻeasy_install`, the easy_install corresponding to the Python version selected with port select is automatically selected. I wanted it to run, so I wrote a wrapper script. (Japanese is too long)

There are many ways to switch versions, which is chaos for Python beginners ...

#!/bin/bash
###
### Macports easy_install wrapper
###   Created by H.Ishiura 2016-12-17
###

SELECT=`port select --show python`
if [[ "$SELECT" =~ ^The\ currently\ selected\ version\ for\ \'python\'\ is\ \'python(.)(.)\'\.$ ]]; then
    MAJOR_VERSION=${BASH_REMATCH[1]}
    MINOR_VERSION=${BASH_REMATCH[2]}
    COMMAND="easy_install-${MAJOR_VERSION}.${MINOR_VERSION}"
else
    COMMAND="/usr/bin/easy_install"
fi
${COMMAND} $@

Place this script in a directory that will be searched in preference to / usr / bin and / opt / local / bin with execute permission. The following is an example of installation (operation has not been confirmed)

$ sudo port install python27
$ sudo port install py27-readline
$ sudo port install py27-setuptools
$ sudo port install py27-pip
$ sudo port install python35
$ sudo port install py35-readline
$ sudo port install py35-setuptools
$ sudo port install py35-pip
$ sudo port select --set python python35
$ sudo port select --set pip pip35
$ curl https://gist.githubusercontent.com/ura14h/6742ae07036dcf74b30de5d2ff8931a9/raw/f30e3887421e93a26df5553eb5c425cb7d7407e2/easy_install -o easy_install_wrapper
$ mkdir ~/bin/
$ mv easy_install_wrapper ~/bin/easy_install
$ chmod 755 ~/bin/easy_install
$ export PATH="${HOME}/bin:${PATH}"

After that, hit the command normally.

$ easy_install --version
setuptools 30.3.0 from /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (Python 3.5)

By the way, when you specify the version and execute it, it looks like this.

$ /usr/bin/easy_install --version
setuptools 18.5 from /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (Python 2.7)
$ 
$ easy_install-2.7 --version
setuptools 30.3.0 from /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (Python 2.7)
$ 
$ easy_install-3.5 --version
setuptools 30.3.0 from /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (Python 3.5)

The truth is, I wish I could do something like port select --set easy_install easy_install-3.5 ... No, should I quit Macports in the first place?

Recommended Posts

Macports easy_install automatically resolves and runs the version
Automatically fetch the installed version
Automatically update and confirm the school homepage
Automatically determine and process the encoding of the text file
[2020 version] Scraping and processing the text from Aozora Bunko
Automatically access the flow in enebular and pull the trigger
Check the type and version of your Linux distribution