Skip to content

Commit 8da905e

Browse files
author
Adam Nelson
committed
First stab at Python3 OS X docs
1 parent 3047288 commit 8da905e

File tree

4 files changed

+146
-18
lines changed

4 files changed

+146
-18
lines changed

docs/dev/virtualenvs.rst

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ projects in separate places, by creating virtual Python environments for them.
88
It solves the "Project X depends on version 1.x but, Project Y needs 4.x"
99
dilemma, and keeps your global site-packages directory clean and manageable.
1010

11-
For example, you can work on a project which requires Django 1.3 while also
12-
maintaining a project which requires Django 1.0.
11+
For example, you can work on a project which requires Django 1.9 while also
12+
maintaining a project which requires Django 1.8.
13+
14+
If you are using Python 3, make sure you run something like the following (or
15+
have it in your env variables in `~/.bashrc`):
16+
17+
.. code-block:: console
18+
19+
$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
1320
1421
virtualenv
1522
----------
1623

1724
`virtualenv <http://pypi.python.org/pypi/virtualenv>`_ is a tool to create
18-
isolated Python environments. virtualenv creates a folder which contains all the
19-
necessary executables to use the packages that a Python project would need.
25+
isolated Python environments. virtualenv creates a folder which contains all the
26+
necessary executables to use the packages that a Python project would need.
2027

2128
Install virtualenv via pip:
2229

@@ -43,23 +50,23 @@ in the current directory instead.
4350
This creates a copy of Python in whichever directory you ran the command in,
4451
placing it in a folder named :file:`venv`.
4552

46-
You can also use a Python interpreter of your choice.
53+
You can also use the Python interpreter of your choice.
4754

4855
.. code-block:: console
4956
50-
$ virtualenv -p /usr/bin/python2.7 venv
57+
$ virtualenv -p /usr/local/bin/python3 venv
5158
52-
This will use the Python interpreter in :file:`/usr/bin/python2.7`
59+
This will use the Python interpreter in :file:`/usr/local/bin/python3`
5360

5461
2. To begin using the virtual environment, it needs to be activated:
5562

5663
.. code-block:: console
5764
5865
$ source venv/bin/activate
5966
60-
The name of the current virtual environment will now appear on the left of
61-
the prompt (e.g. ``(venv)Your-Computer:your_project UserName$)`` to let you know
62-
that it's active. From now on, any package that you install using pip will be
67+
The name of the current virtual environment will now appear on the left of
68+
the prompt (e.g. ``(venv)Your-Computer:your_project UserName$)`` to let you know
69+
that it's active. From now on, any package that you install using pip will be
6370
placed in the ``venv`` folder, isolated from the global Python installation.
6471

6572
Install packages as usual, for example:
@@ -78,7 +85,7 @@ Install packages as usual, for example:
7885
This puts you back to the system's default Python interpreter with all its
7986
installed libraries.
8087

81-
To delete a virtual environment, just delete its folder. (In this case,
88+
To delete a virtual environment, just delete its folder. (In this case,
8289
it would be ``rm -rf venv``.)
8390

8491
After a while, though, you might end up with a lot of virtual environments
@@ -102,8 +109,8 @@ the current state of the environment packages. To do this, run
102109
103110
This will create a :file:`requirements.txt` file, which contains a simple
104111
list of all the packages in the current environment, and their respective
105-
versions. You can see the list of installed packages without the requirements
106-
format using "pip list". Later it will be easier for a different developer
112+
versions. You can see the list of installed packages without the requirements
113+
format using "pip list". Later it will be easier for a different developer
107114
(or you, if you need to re-create the environment) to install the same packages
108115
using the same versions:
109116

@@ -143,7 +150,7 @@ To install (make sure **virtualenv** is already installed):
143150
.. code-block:: console
144151
145152
$ pip install virtualenvwrapper-win
146-
153+
147154
In Windows, the default path for WORKON_HOME is %USERPROFILE%\Envs
148155

149156
Basic Usage

docs/starting/install/osx.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Installing Python on Mac OS X
44
=============================
55

6+
.. note::
7+
Check out our :ref:`guide for installing Python 3 on OS X<install3-osx>`.
8+
69
The latest version of Mac OS X, El Capitan, **comes with Python 2.7 out of the box**.
710

811
You do not need to install or configure anything else to use Python. Having said

docs/starting/install3/osx.rst

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.. _install3-osx:
2+
3+
Installing Python 3 on Mac OS X
4+
================================
5+
6+
The latest version of Mac OS X, El Capitan, **comes with Python 2.7 out of the box**.
7+
8+
You do not need to install or configure anything else to use Python 2. These
9+
instructions document the installation of Python 3.
10+
11+
The version of Python that ships with OS X is great for learning but it's not
12+
good for development. The version shipped with OS X may be out of date from the
13+
`official current Python release <https://www.python.org/downloads/mac-osx/>`_,
14+
which is considered the stable production version.
15+
16+
Doing it Right
17+
--------------
18+
19+
Let's install a real version of Python.
20+
21+
Before installing Python, you'll need to install GCC. GCC can be obtained
22+
by downloading `XCode <http://developer.apple.com/xcode/>`_, the smaller
23+
`Command Line Tools <https://developer.apple.com/downloads/>`_ (must have an
24+
Apple account) or the even smaller `OSX-GCC-Installer <https://github.com/kennethreitz/osx-gcc-installer#readme>`_
25+
package.
26+
27+
.. note::
28+
If you already have XCode installed, do not install OSX-GCC-Installer.
29+
In combination, the software can cause issues that are difficult to
30+
diagnose.
31+
32+
.. note::
33+
If you perform a fresh install of XCode, you will also need to add the
34+
commandline tools by running ``xcode-select --install`` on the terminal.
35+
36+
While OS X comes with a large number of UNIX utilities, those familiar with
37+
Linux systems will notice one key component missing: a package manager.
38+
`Homebrew <http://brew.sh>`_ fills this void.
39+
40+
To `install Homebrew <http://brew.sh/#install>`_, open :file:`Terminal` or
41+
your favorite OSX terminal emulator and run
42+
43+
.. code-block:: console
44+
45+
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
46+
47+
The script will explain what changes it will make and prompt you before the
48+
installation begins.
49+
Once you've installed Homebrew, insert the Homebrew directory at the top
50+
of your :envvar:`PATH` environment variable. You can do this by adding the following
51+
line at the bottom of your :file:`~/.profile` file
52+
53+
.. code-block:: console
54+
55+
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
56+
57+
Now, we can install Python 3:
58+
59+
.. code-block:: console
60+
61+
$ brew install python3
62+
63+
This will take a minute or two.
64+
65+
66+
Pip
67+
----------------
68+
69+
Homebrew installs ``pip3`` for you.
70+
71+
``pip3`` is the alias for the Python 3 version of ``pip`` on systems with both
72+
the Homebrew'd Python 2 and 3 installed.
73+
74+
Working with Python3
75+
--------------------
76+
77+
At this point, you have the system Python 2.7 available, potentially the
78+
:ref:`Homebrew version of Python 2 <install-osx>` installed, and the Homebrew
79+
version of Python 3 as well.
80+
81+
.. code-block:: console
82+
83+
$ python
84+
85+
will launch the Python 2 interpreter.
86+
87+
.. code-block:: console
88+
89+
$ python3
90+
91+
will launch the Python 3 interpreter
92+
93+
``pip3`` and ``pip`` will both be available. If the Homebrew version of Python
94+
2 is not installed, they will be the same. If the Homebrew version of Python 2
95+
is installed then ``pip`` will point to Python 2 and ``pip3`` will point to
96+
Python 3.
97+
98+
99+
Virtual Environments
100+
--------------------
101+
102+
A Virtual Environment (commonly referred to as a 'virtualenv') is a tool to keep
103+
the dependencies required by different projects in separate places, by creating
104+
virtual Python environments for them. It solves the "Project X depends on
105+
version 1.x but, Project Y needs 4.x" dilemma, and keeps your global
106+
site-packages directory clean and manageable.
107+
108+
For example, you can work on a project which requires Django 1.10 while also
109+
maintaining a project which requires Django 1.8.
110+
111+
To start using this and see more information: :ref:`Virtual Environments <virtualenvironments-ref>` docs.
112+
113+
--------------------------------
114+
115+
This page is a remixed version of `another guide <http://www.stuartellis.eu/articles/python-development-windows/>`_,
116+
which is available under the same license.

docs/starting/installation.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ other third-party Python libraries.
1313
Installation Guides
1414
-------------------
1515

16-
These guides go over the proper installation of :ref:`Python 2.7 <which-python>`
16+
These guides go over the proper installation of :ref:`Python <which-python>`
1717
for development purposes, as well as pip and virtualenv.
1818

19-
- :ref:`Mac OS X <install-osx>`.
20-
- :ref:`Microsoft Windows <install-windows>`.
21-
- :ref:`Ubuntu Linux <install-linux>`.
19+
- :ref:`Python 3 on Mac OS X <install3-osx>`.
20+
21+
- :ref:`Python 2 on Mac OS X <install-osx>`.
22+
- :ref:`Python 2 on Microsoft Windows <install-windows>`.
23+
- :ref:`Python 2 on Ubuntu Linux <install-linux>`.

0 commit comments

Comments
 (0)