Mac OS X comes with Python 2.7 out of the box.
You do not need to install or configure anything else to use Python 2. Theseinstructions document the installation of Python 3.
The version of Python that ships with OS X is great for learning, but it’s notgood for development. The version shipped with OS X may be out of date from theofficial current Python release,which is considered the stable production version.
Doing it Right¶
Python and OS Compatibility¶ pip works with CPython versions 3.6, 3.7, 3.8 and also PyPy. This means pip works on the latest patch version of each of these minor versions. Previous patch versions are supported on a best effort approach. Pip works on Unix/Linux, macOS, and Windows. Pip accesses the Python Package Index, PyPI, which stores almost 200,000 projects and all previous releases of said projects. Because the repository keeps previous versions, you can pin to a version and not worry about updates causing conflicts. Pip can also install packages in local virtualenv, or virtual environment. To pip install OpenCV on your Raspberry Pi system, be sure to use sudo like this: $ sudo pip install opencv-contrib-python4.1.0.25 2019-11-21 Update: Readers have reported that some versions of OpenCV 4 as installed via pip do not work properly on the Raspberry Pi. Python and OS Compatibility¶ pip works with CPython versions 3.6, 3.7, 3.8 and also PyPy. This means pip works on the latest patch version of each of these minor versions. Previous patch versions are supported on a best effort approach. Pip works on Unix/Linux, macOS, and Windows.
Let’s install a real version of Python.
Before installing Python, you’ll need to install GCC. GCC can be obtainedby downloading Xcode, the smallerCommand Line Tools (must have anApple account) or the even smaller OSX-GCC-Installerpackage.
Note
If you already have Xcode installed, do not install OSX-GCC-Installer.In combination, the software can cause issues that are difficult todiagnose.
Note
If you perform a fresh install of Xcode, you will also need to add thecommandline tools by running xcode-select--install
on the terminal.
While OS X comes with a large number of Unix utilities, those familiar withLinux systems will notice one key component missing: a package manager.Homebrew fills this void.
To install Homebrew, open Terminal
oryour favorite OS X terminal emulator and run
Pip Install Os Python
The script will explain what changes it will make and prompt you before theinstallation begins.Once you’ve installed Homebrew, insert the Homebrew directory at the topof your PATH
environment variable. You can do this by adding the followingline at the bottom of your ~/.profile
file
If you have OS X 10.12 (Sierra) or older use this line instead
Now, we can install Python 3:
This will take a minute or two.
Pip¶
Homebrew installs pip
pointing to the Homebrew’d Python 3 for you.
Working with Python 3¶
At this point, you have the system Python 2.7 available, potentially theHomebrew version of Python 2 installed, and the Homebrewversion of Python 3 as well.
will launch the Homebrew-installed Python 3 interpreter.
will launch the Homebrew-installed Python 2 interpreter (if any).
will launch the Homebrew-installed Python 3 interpreter.
If the Homebrew version of Python 2 is installed then pip2
will point to Python 2.If the Homebrew version of Python 3 is installed then pip
will point to Python 3.
The rest of the guide will assume that python
references Python 3.
Pipenv & Virtual Environments¶
The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
A Virtual Environment is a tool to keep the dependencies required by different projectsin separate places, by creating virtual Python environments for them. It solves the“Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keepsyour global site-packages directory clean and manageable.
For example, you can work on a project which requires Django 1.10 while alsomaintaining a project which requires Django 1.8.
So, onward! To the Pipenv & Virtual Environments docs!
This page is a remixed version of another guide,which is available under the same license.
Original author(s) | Ian Bicking |
---|---|
Initial release | 4 April 2011 (9 years ago)[1] |
Stable release | 21.0 / 23 January 2021 (56 days ago)[2] |
Repository | |
Written in | Python |
Operating system | OS-independent |
Platform | Python |
Type | Package management system |
License | MIT[3] |
Website | pip.pypa.io |
pip is a package-management system written in Python used to install and manage software packages.[4] It connects to an online repository of public and paid-for private packages, called the Python Package Index.
Most distributions of Python come with pip preinstalled. Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip (pip3 for Python 3) by default.[5]
History[edit]
First introduced as pyinstall in 2008 by Ian Bicking (the creator of the virtualenv package) as an alternative to easy_install,[6][7] pip was chosen as the new name from one of several suggestions that the creator received on his blog post.[8] According to Bicking himself, the name is a recursive acronym for 'Pip Installs Packages'.[9] In 2011, the Python Packaging Authority (PyPA) was created to take over the maintenance of pip and virtualenv from Bicking, led by Carl Meyer, Brian Rosner, and Jannis Leidel.[7]
With the release of pip version 6.0 (2014-12-22), the version naming process was changed to have version in X.Y format and drop the preceding 1 from the version label.
Command-line interface[edit]
pip install virtualenv
One major advantage of pip is the ease of its command-line interface, which makes installing Python software packages as easy as issuing a command:
Users can also easily remove the package:
Most importantly, pip has a feature to manage full lists of packages and corresponding version numbers, possible through a 'requirements' file.[10] This permits the efficient re-creation of an entire group of packages in a separate environment (e.g. another computer) or virtual environment. This can be achieved with a properly formatted file and the following command,[11] where requirements.txt
is the name of the file:
Pip Install Os Error
To install some package for a specific python version, pip provides the following command, where ${version}
is replaced by 2, 3, 3.4, etc.:
Using setup.py[edit]
Pip provides a way to install user-defined projects locally with the use of setup.py file. This method requires the python project to have the following file structure:
Within this structure, user can add setup.py to the root of the project (i.e. example_project
for above structure) with the following content:
After this, pip can install this custom project by running the following command, from the project root directory:
See also[edit]
- Anaconda – uses Conda
- Python Package Index (PyPI)
- npm – Node.js Package Manager
References[edit]
- ^Release 1.0
- ^'Changelog - pip documentation v21.0'. pip.pypa.io. Retrieved 25 January 2021.
- ^'pip/LICENSE.txt'. Github. 17 April 2018. Archived from the original on 1 June 2018. Retrieved 1 June 2018.
- ^Kollár, László. 'Managing Python packages the right way'. Opensource.com. Red Hat. Retrieved 23 June 2019.
- ^'pip installation'. Retrieved 24 February 2015.
- ^Bicking, Ian (24 September 2008). 'pyinstall: A New Hope'. Archived from the original on 27 September 2008. Retrieved 4 March 2020.
- ^ ab'Packaging History'. Python Packaging Authority. Retrieved 4 March 2020.
- ^Bicking, Ian (1 October 2008). 'pyinstall pybundles'. Retrieved 4 March 2020.
- ^Bicking, Ian (28 October 2008). 'pyinstall is dead, long live pip!'. Retrieved 4 March 2020.
- ^'pip documentation'. The pip developers. Retrieved 5 January 2012.
- ^Gahlot, Gaurav (6 November 2018). 'Most Important pip Commands for a Python Developer - DZone Open Source'. dzone.com. Retrieved 23 June 2019.