MacLochlainns Weblog

Michael McLaughlin's Technical Blog

Site Admin

Archive for May, 2017

Installing PIP for Python

without comments

If you’re on a Mac running macOS Sierra, you can install PIP to add packages. PIP stands for either of the following:

  • PIP installs Packages
  • PIP installs Python

You use the following to install the PIP utility:

sudo easy_install pip

It should return the following:

Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 9.0.1
Downloading https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
Processing pip-9.0.1.tar.gz
Writing /tmp/easy_install-ryxjDg/pip-9.0.1/setup.cfg
Running pip-9.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ryxjDg/pip-9.0.1/egg-dist-tmp-l6_Jjt
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
creating /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Extracting pip-9.0.1-py2.7.egg to /Library/Python/2.7/site-packages
Adding pip 9.0.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
 
Installed /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

After you install PIP, you can use PIP to add custom packages to the Python environment. The

sudo pip install easygui

You get the following warning and installation:

The directory '/Users/michaelmclaughlin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/michaelmclaughlin/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting easygui
  Downloading easygui-0.98.1-py2.py3-none-any.whl (90kB)
    100% |████████████████████████████████| 92kB 1.0MB/s 
Installing collected packages: easygui
Successfully installed easygui-0.98.1

After installing the easygui Python library, you can change to the root directory to confirm the installation of the easygui Python library with the following command:

find . -name easygui* 2>/dev/null

It returns the following:

./Library/Python/2.7/site-packages/easygui
./Library/Python/2.7/site-packages/easygui/easygui.py
./Library/Python/2.7/site-packages/easygui/easygui.pyc
./Library/Python/2.7/site-packages/easygui-0.98.1.dist-info

You can connect to Python 2.7 in a Terminal session. Then, you use the easygui library to run a Hello World! message box with the following commands in the Python shell:

import easygui
easy gui.msgbox("Hello World!")

It will raise the following image:

Hopefully, this helps a few folks.

Written by maclochlainn

May 2nd, 2017 at 12:51 am