`_.
The majority of new Python web applications today are built with Django.
@@ -221,19 +224,12 @@ how to set up your first application.
Heroku is the recommended PaaS for deploying Python web applications today.
-Gondor
-------
-
-`Gondor `_ is a PaaS specialized for deploying Django
-and Pinax applications. Gondor recommends Django version 1.6 and supports any
-WSGI application on Python version 2.7. Gondor can automatically configure your
-Django site if you use :file:`local_settings.py` for site-specific configuration
-information.
-
-Gondor has a guide on deploying `Django projects `_.
+Eldarion
+--------
-Gondor is run by a small company and focuses on helping businesses find success with
-Python and Django.
+`Eldarion `_ (formely known as Gondor) is a PaaS powered
+by Kubernetes, CoreOS, and Docker. They support any WSGI application and have a
+guide on deploying `Django projects `_.
Templating
::::::::::
@@ -372,7 +368,7 @@ into the corresponding block in the :file:`base.html` page.
.. code-block:: html
-
@@ -464,7 +460,7 @@ frameworks.
An example template in Mako looks like:
-.. code-block:: html
+.. code-block:: mako
<%inherit file="base.html"/>
<%
diff --git a/docs/scenarios/xml.rst b/docs/scenarios/xml.rst
index 0cc3cdc4c..8af9e416c 100644
--- a/docs/scenarios/xml.rst
+++ b/docs/scenarios/xml.rst
@@ -1,6 +1,8 @@
XML parsing
===========
+.. image:: https://farm3.staticflickr.com/2808/33888714601_a1f7d020a2_k_d.jpg
+
untangle
--------
diff --git a/docs/shipping/freezing.rst b/docs/shipping/freezing.rst
index d42f2d61b..f0b73b41d 100644
--- a/docs/shipping/freezing.rst
+++ b/docs/shipping/freezing.rst
@@ -4,11 +4,13 @@
Freezing Your Code
==================
+.. image:: https://farm5.staticflickr.com/4227/33907151034_e0a9e53402_k_d.jpg
+
"Freezing" your code is creating a single-file executable file to distribute
to end-users, that contains all of your application code as well as the
Python interpreter.
-Applications such as 'Dropbox', 'Eve Online', 'Civilisation IV', and
+Applications such as 'Dropbox', 'Eve Online', 'Civilization IV', and
BitTorrent clients do this.
The advantage of distributing this way is that your application will "just work",
@@ -60,7 +62,7 @@ py2app no no yes yes MIT no yes yes
.. note::
All solutions need MS Visual C++ dll to be installed on target machine, except py2app.
Only Pyinstaller makes self-executable exe that bundles the dll when
- passing :option:`--onefile` to :file:`Configure.py`.
+ passing ``--onefile`` to :file:`Configure.py`.
Windows
-------
@@ -70,7 +72,46 @@ bbFreeze
Prerequisite is to install :ref:`Python, Setuptools and pywin32 dependency on Windows `.
-.. todo:: Write steps for most basic .exe
+1. Install :code:`bbfreeze`:
+
+.. code-block:: console
+
+ $ pip install bbfreeze
+
+2. Write most basic :file:`bb_setup.py`
+
+.. code-block:: python
+
+ from bbfreeze import Freezer
+
+ freezer = Freezer(distdir='dist')
+ freezer.addScript('foobar.py', gui_only=True)
+ freezer()
+
+.. note::
+
+ This will work for the most basic one file scripts. For more advanced freezing you will have to provide
+ include and exclude paths like so
+
+ .. code-block:: python
+
+ freezer = Freezer(distdir='dist', includes=['my_code'], excludes=['docs'])
+
+3. (Optionally) include icon
+
+.. code-block:: python
+
+ freezer.setIcon('my_awesome_icon.ico')
+
+4. Provide the Microsoft Visual C runtime DLL for the freezer. It might be possible to append your :code:`sys.path`
+with Microsoft Visual Studio path but I find it easier to drop :file:`msvcp90.dll` in the same folder where your script
+resides.
+
+5. Freeze!
+
+.. code-block:: console
+
+ $ python bb_setup.py
py2exe
~~~~~~
@@ -108,7 +149,7 @@ PyInstaller
Prerequisite is to have installed :ref:`Python, Setuptools and pywin32 dependency on Windows `.
- `Most basic tutorial `_
-- `Manual `_
+- `Manual `_
OS X
@@ -163,7 +204,7 @@ To create a standalone windowed OS X application, use the :code:`--windowed` opt
This creates a :code:`script.app` in the :code:`dist` folder. Make sure to use GUI packages in your Python code, like `PyQt `_ or `PySide `_, to control the graphical parts of the app.
-There are several options in :code:`script.spec` related to Mac OS X app bundles `here `_. For example, to specify an icon for the app, use the :code:`icon=\path\to\icon.icns` option.
+There are several options in :code:`script.spec` related to Mac OS X app bundles `here `_. For example, to specify an icon for the app, use the :code:`icon=\path\to\icon.icns` option.
Linux
diff --git a/docs/shipping/packaging.rst b/docs/shipping/packaging.rst
index c67957529..7e55d4207 100644
--- a/docs/shipping/packaging.rst
+++ b/docs/shipping/packaging.rst
@@ -4,6 +4,8 @@
Packaging Your Code
===================
+.. image:: https://farm5.staticflickr.com/4325/36137234682_be6898bf57_k_d.jpg
+
Package your code to share it with other developers. For example
to share a library for other developers to use in their application,
or for development tools like 'py.test'.
@@ -101,7 +103,7 @@ pypiserver
`Pypiserver `_ is a minimal PyPI
compatible server. It can be used to serve a set of packages to easy_install
or pip. It includes helpful features like an administrative command
-(:option:`-U`) which will update all its packages to their latest versions
+(``-U``) which will update all its packages to their latest versions
found on PyPI.
@@ -152,7 +154,7 @@ Also, if a distribution releases a new security update for Python, then your
application will automatically start using that new version of Python.
The bdist_rpm command makes `producing an RPM file `_
-for use by distributions like Red Hat or SuSE is trivially easy.
+for use by distributions like Red Hat or SuSE trivially easy.
However, creating and maintaining the different configurations required for
each distribution's format (e.g. .deb for Debian/Ubuntu, .rpm for Red
diff --git a/docs/starting/install/linux.rst b/docs/starting/install/linux.rst
index aa56ec07d..de831b6e0 100644
--- a/docs/starting/install/linux.rst
+++ b/docs/starting/install/linux.rst
@@ -1,25 +1,29 @@
.. _install-linux:
-Installing Python on Linux
-==========================
+Installing Python 2 on Linux
+=============================
-The latest versions of CentOS, Fedora, Redhat Enterprise (RHEL) and Ubuntu
+.. image:: https://farm5.staticflickr.com/4268/34435688560_4cc2a7bcbb_k_d.jpg
+
+.. note::
+ Check out our :ref:`guide for installing Python 3 on Linux`.
+
+The latest versions of CentOS, Red Hat Enterprise Linux (RHEL) and Ubuntu
**come with Python 2.7 out of the box**.
To see which version of Python you have installed, open a command prompt and run
.. code-block:: console
- $ python --version
+ $ python2 --version
-Some older versions of RHEL and CentOS come with Python 2.4 which is
-unacceptable for modern Python development. Fortunately, there are
-`Extra Packages for Enterprise Linux`_ which include high
-quality additional packages based on their Fedora counterparts. This
-repository contains a Python 2.6 package specifically designed to install
-side-by-side with the system's Python 2.4 installation.
+However, with the growing popularity of Python 3, some distributions, such as
+Fedora, don't come with Python 2 pre-installed. You can install the ``python2``
+package with your distribution package manager:
+
+.. code-block:: console
-.. _Extra Packages for Enterprise Linux: http://fedoraproject.org/wiki/EPEL
+ $ sudo dnf install python2
You do not need to install or configure anything else to use Python. Having
said that, I would strongly recommend that you install the tools and libraries
@@ -32,11 +36,11 @@ Setuptools & Pip
The two most crucial third-party Python packages are `setuptools `_ and `pip `_.
-Once installed, you can download, install and uninstall any compliant Python software
-product with a single command. It also enables you to add this network installation
+Once installed, you can download, install and uninstall any compliant Python software
+product with a single command. It also enables you to add this network installation
capability to your own Python software with very little work.
-Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include
+Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include
pip by default.
To see if pip is installed, open a command prompt and run
@@ -50,15 +54,15 @@ To install pip, `follow the official pip installation guide ` docs.
+To start using this and see more information: :ref:`Virtual Environments ` docs.
You can also use :ref:`virtualenvwrapper ` to make it easier to
manage your virtual environments.
diff --git a/docs/starting/install/osx.rst b/docs/starting/install/osx.rst
index f459ef99e..f83bd4f07 100644
--- a/docs/starting/install/osx.rst
+++ b/docs/starting/install/osx.rst
@@ -1,17 +1,22 @@
.. _install-osx:
-Installing Python on Mac OS X
-=============================
+Installing Python 2 on Mac OS X
+===============================
-The latest version of Mac OS X, El Capitan, **comes with Python 2.7 out of the box**.
+.. image:: https://farm5.staticflickr.com/4268/34435688560_4cc2a7bcbb_k_d.jpg
-You do not need to install or configure anything else to use Python. Having
-said that, I would strongly recommend that you install the tools and libraries
-described in the next section before you start building Python applications
-for real-world use. In particular, you should always install Setuptools, as it
-makes it much easier for you to use other third-party Python libraries.
+.. note::
+ Check out our :ref:`guide for installing Python 3 on OS X`.
+
+The latest version of Mac OS X, High Sierra, **comes with Python 2.7 out of the box**.
-The version of Python that ships with OS X is great for learning but it's not
+You do not need to install or configure anything else to use Python. Having said
+that, I would strongly recommend that you install the tools and libraries
+described in the next section before you start building Python applications for
+real-world use. In particular, you should always install Setuptools, as it makes
+it much easier for you to install and manage other third-party Python libraries.
+
+The version of Python that ships with OS X is great for learning, but it's not
good for development. The version shipped with OS X may be out of date from the
`official current Python release `_,
which is considered the stable production version.
@@ -30,9 +35,14 @@ minimal but unofficial
package.
.. note::
- If you already have Xcode installed or plan to use Homebrew, do not install
- OSX-GCC-Installer. In combination, the software can cause issues that are
- difficult to diagnose.
+ If you already have XCode installed, do not install OSX-GCC-Installer.
+ In combination, the software can cause issues that are difficult to
+ diagnose.
+
+.. note::
+ If you perform a fresh install of XCode, you will also need to add the
+ commandline tools by running ``xcode-select --install`` on the terminal.
+
While OS X comes with a large number of UNIX utilities, those familiar with
Linux systems will notice one key component missing: a decent package manager.
@@ -67,7 +77,16 @@ or Python 3:
$ brew install python3
-This will take a minute or two.
+This will take a minute or two.
+
+Homebrew names the executable ``python2`` so that you can still run the system Python via the executable ``python``.
+
+
+.. code-block:: console
+
+ $ python -V # system Python interpreter
+ $ python2 -V # Homebrew installed Python 2 interpreter
+ $ python3 -V # Homebrew installed Python 3 interpreter (if installed)
Setuptools & Pip
@@ -81,23 +100,29 @@ software over a network (usually the Internet) with a single command
capability to your own Python software with very little work.
``pip`` is a tool for easily installing and managing Python packages,
-that is recommended over ``easy_install``. It is superior to ``easy_install`` in `several ways `_,
+that is recommended over ``easy_install``. It is superior to ``easy_install``
+in `several ways `_,
and is actively maintained.
+.. code-block:: console
+
+ $ pip2 -V # pip pointing to the Homebrew installed Python 2 interpreter
+ $ pip3 -V # pip pointing to the Homebrew installed Python 3 interpreter (if installed)
+
+
Virtual Environments
--------------------
-A Virtual Environment is a tool to keep the dependencies required by different projects
-in 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 keeps
+A Virtual Environment (commonly referred to as a 'virtualenv') is a tool to keep the dependencies required by different projects
+in 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 keeps
your global site-packages directory clean and manageable.
For example, you can work on a project which requires Django 1.10 while also
maintaining a project which requires Django 1.8.
-To start using this and see more information: :ref:`Virtual Environments ` docs.
-
+To start using this and see more information: :ref:`Virtual Environments ` docs.
--------------------------------
diff --git a/docs/starting/install/win.rst b/docs/starting/install/win.rst
index 131ace663..e930b4683 100644
--- a/docs/starting/install/win.rst
+++ b/docs/starting/install/win.rst
@@ -1,10 +1,15 @@
.. _install-windows:
-Installing Python on Windows
-============================
+Installing Python 2 on Windows
+==============================
-First, download the `latest version `_
-of Python 2.7 from the official Website. If you want to be sure you are installing a fully
+.. image:: https://farm5.staticflickr.com/4268/34435688560_4cc2a7bcbb_k_d.jpg
+
+.. note::
+ Check out our :ref:`guide for installing Python 3 on Windows`.
+
+First, download the `latest version `_
+of Python 2.7 from the official website. If you want to be sure you are installing a fully
up-to-date version, click the Downloads > Windows link from the home page of the
`Python.org web site `_ .
@@ -35,6 +40,8 @@ You can do this easily by running the following in ``powershell``:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")
+This is also an option during the installation process.
+
The second (:file:`Scripts`) directory receives command files when certain
packages are installed, so it is a very useful addition.
You do not need to install or configure anything else to use Python. Having
@@ -46,38 +53,36 @@ makes it much easier for you to use other third-party Python libraries.
Setuptools + Pip
----------------
-The most crucial third-party Python software of all is Setuptools, which
-extends the packaging and installation facilities provided by the distutils in
-the standard library. Once you add Setuptools to your Python system you can
-download and install any compliant Python software product with a single
-command. It also enables you to add this network installation capability to
-your own Python software with very little work.
+The two most crucial third-party Python packages are `setuptools `_ and `pip `_.
-To obtain the latest version of Setuptools for Windows, run the Python script
-available here: `ez_setup.py `_
+Once installed, you can download, install and uninstall any compliant Python software
+product with a single command. It also enables you to add this network installation
+capability to your own Python software with very little work.
+Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include
+pip by default.
+
+To see if pip is installed, open a command prompt and run
+
+.. code-block:: console
-You'll now have a new command available to you: **easy_install**. It is
-considered by many to be deprecated, so we will install its replacement:
-**pip**. Pip allows for uninstallation of packages, and is actively maintained,
-unlike easy_install.
+ $ command -v pip
-To install pip, run the Python script available here:
-`get-pip.py `_
+To install pip, `follow the official pip installation guide `_ - this will automatically install the latest version of setuptools.
Virtual Environments
--------------------
-A Virtual Environment is a tool to keep the dependencies required by different projects
-in 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 keeps
+A Virtual Environment is a tool to keep the dependencies required by different projects
+in 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 keeps
your global site-packages directory clean and manageable.
For example, you can work on a project which requires Django 1.10 while also
maintaining a project which requires Django 1.8.
-To start using this and see more information: :ref:`Virtual Environments ` docs.
+To start using this and see more information: :ref:`Virtual Environments ` docs.
--------------------------------
diff --git a/docs/starting/install3/linux.rst b/docs/starting/install3/linux.rst
new file mode 100644
index 000000000..1c6d67d35
--- /dev/null
+++ b/docs/starting/install3/linux.rst
@@ -0,0 +1,112 @@
+.. _install3-linux:
+
+Installing Python 3 on Linux
+============================
+
+.. image:: https://farm5.staticflickr.com/4276/34435689480_2e6f358510_k_d.jpg
+
+This document describes how to install Python 3.6 on Ubuntu Linux machines.
+
+To see which version of Python 3 you have installed, open a command prompt and run
+
+.. code-block:: console
+
+ $ python3 --version
+
+If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the following commands::
+
+ $ sudo apt-get update
+ $ sudo apt-get install python3.6
+
+If you're using another version of Ubuntu (e.g. the latest LTS release), we recommend using the `deadsnakes PPA `_ to install Python 3.6::
+
+ $ sudo apt-get install software-properties-common
+ $ sudo add-apt-repository ppa:deadsnakes/ppa
+ $ sudo apt-get update
+ $ sudo apt-get install python3.6
+
+If you are using other Linux distribution, chances are you already have Python 3
+pre-installed as well. If not, use your distribution's package manager.
+For example on Fedora, you would use `dnf`:
+
+.. code-block:: console
+
+ $ sudo dnf install python3
+
+Note that if the version of the ``python3`` package is not recent enough
+for you, there may be ways of installing more recent versions as well,
+depending on you distribution. For example installing the ``python36`` package
+on Fedora 25 to get Python 3.6. If you are a Fedora user, you might want
+to read about `multiple Python versions available in Fedora`_.
+
+.. _multiple Python versions available in Fedora: https://developer.fedoraproject.org/tech/languages/python/multiple-pythons.html
+
+
+Working with Python 3
+---------------------
+
+At this point, you may have system Python 2.7 available as well.
+
+.. code-block:: console
+
+ $ python
+
+This will launch the Python 2 interpreter.
+
+.. code-block:: console
+
+ $ python3
+
+This will launch the Python 3 interpreter.
+
+Setuptools & Pip
+----------------
+
+The two most crucial third-party Python packages are `setuptools `_ and `pip `_.
+
+Once installed, you can download, install and uninstall any compliant Python software
+product with a single command. It also enables you to add this network installation
+capability to your own Python software with very little work.
+
+Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include
+pip by default.
+
+To see if pip is installed, open a command prompt and run
+
+.. code-block:: console
+
+ $ command -v pip
+
+To install pip, `follow the official pip installation guide `_ - this will automatically install the latest version of setuptools.
+
+Note that on some Linux distributions including Ubuntu and Fedora the ``pip``
+command is meant for Python 2, while the ``pip3`` command is meant for Python 3.
+
+.. code-block:: console
+
+ $ command -v pip3
+
+However, when using virtual environments (described below), you don't need to
+care about that.
+
+
+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 projects
+in 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 keeps
+your global site-packages directory clean and manageable.
+
+For example, you can work on a project which requires Django 1.10 while also
+maintaining a project which requires Django 1.8.
+
+So, onward! To the :ref:`Pipenv & Virtual Environments ` docs!
+
+--------------------------------
+
+This page is a remixed version of `another guide `_,
+which is available under the same license.
+
diff --git a/docs/starting/install3/osx.rst b/docs/starting/install3/osx.rst
new file mode 100644
index 000000000..bd7ad7168
--- /dev/null
+++ b/docs/starting/install3/osx.rst
@@ -0,0 +1,124 @@
+:orphan: This article should not be added to a toctree for now
+
+.. _install3-osx:
+
+Installing Python 3 on Mac OS X
+===============================
+
+.. image:: https://farm5.staticflickr.com/4276/34435689480_2e6f358510_k_d.jpg
+
+The latest version of Mac OS X, High Sierra, **comes with Python 2.7 out of the box**.
+
+You do not need to install or configure anything else to use Python 2. These
+instructions document the installation of Python 3.
+
+The version of Python that ships with OS X is great for learning, but it's not
+good for development. The version shipped with OS X may be out of date from the
+`official current Python release `_,
+which is considered the stable production version.
+
+Doing it Right
+--------------
+
+Let's install a real version of Python.
+
+Before installing Python, you'll need to install GCC. GCC can be obtained
+by downloading `XCode `_, the smaller
+`Command Line Tools `_ (must have an
+Apple account) or the even smaller `OSX-GCC-Installer `_
+package.
+
+.. note::
+ If you already have XCode installed, do not install OSX-GCC-Installer.
+ In combination, the software can cause issues that are difficult to
+ diagnose.
+
+.. note::
+ If you perform a fresh install of XCode, you will also need to add the
+ commandline tools by running ``xcode-select --install`` on the terminal.
+
+While OS X comes with a large number of UNIX utilities, those familiar with
+Linux systems will notice one key component missing: a package manager.
+`Homebrew `_ fills this void.
+
+To `install Homebrew `_, open :file:`Terminal` or
+your favorite OSX terminal emulator and run
+
+.. code-block:: console
+
+ $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
+
+The script will explain what changes it will make and prompt you before the
+installation begins.
+Once you've installed Homebrew, insert the Homebrew directory at the top
+of your :envvar:`PATH` environment variable. You can do this by adding the following
+line at the bottom of your :file:`~/.profile` file
+
+.. code-block:: console
+
+ export PATH=/usr/local/bin:/usr/local/sbin:$PATH
+
+Now, we can install Python 3:
+
+.. code-block:: console
+
+ $ brew install python3
+
+This will take a minute or two.
+
+
+Pip
+---
+
+Homebrew installs ``pip3`` for you.
+
+``pip3`` is the alias to ``pip`` pointing to the Homebrew'd Python 3.
+
+Working with Python 3
+---------------------
+
+At this point, you have the system Python 2.7 available, potentially the
+:ref:`Homebrew version of Python 2 ` installed, and the Homebrew
+version of Python 3 as well.
+
+.. code-block:: console
+
+ $ python
+
+will launch the system Python interpreter.
+
+.. code-block:: console
+
+ $ python2
+
+will launch the homebrew-installed Python 2 interpreter (if any).
+
+.. code-block:: console
+
+ $ python3
+
+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 ``pip3`` will point to 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 projects
+in 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 keeps
+your global site-packages directory clean and manageable.
+
+For example, you can work on a project which requires Django 1.10 while also
+maintaining a project which requires Django 1.8.
+
+So, onward! To the :ref:`Pipenv & Virtual Environments ` docs!
+
+--------------------------------
+
+This page is a remixed version of `another guide `_,
+which is available under the same license.
diff --git a/docs/starting/install3/win.rst b/docs/starting/install3/win.rst
new file mode 100644
index 000000000..74fe7d0a4
--- /dev/null
+++ b/docs/starting/install3/win.rst
@@ -0,0 +1,95 @@
+.. _install3-windows:
+
+Installing Python 3 on Windows
+==============================
+
+.. image:: https://farm5.staticflickr.com/4276/34435689480_2e6f358510_k_d.jpg
+
+First, download the `latest version `_
+of Python 3.6 from the official website. If you want to be sure you are installing a fully
+up-to-date version, click the Downloads > Windows link from the home page of the
+`Python.org web site `_ .
+
+By design, Python installs to a directory with the version number embedded,
+e.g. Python version 3.6 will install at :file:`C:\\Python36\\`, so that you can
+have multiple versions of Python on the
+same system without conflicts. Of course, only one interpreter can be the
+default application for Python file types. It also does not automatically
+modify the :envvar:`PATH` environment variable, so that you always have control over
+which copy of Python is run.
+
+Typing the full path name for a Python interpreter each time quickly gets
+tedious, so add the directories for your default Python version to the :envvar:`PATH`.
+Assuming that your Python installation is in :file:`C:\\Python36\\`, add this to your
+:envvar:`PATH`:
+
+.. code-block:: console
+
+ C:\Python36\;C:\Python36\Scripts\
+
+You can do this easily by running the following in ``powershell``:
+
+.. code-block:: console
+
+ [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python36\;C:\Python36\Scripts\", "User")
+
+This is also an option during the installation process.
+
+The second (:file:`Scripts`) directory receives command files when certain
+packages are installed, so it is a very useful addition.
+You do not need to install or configure anything else to use Python. Having
+said that, I would strongly recommend that you install the tools and libraries
+described in the next section before you start building Python applications for
+real-world use. In particular, you should always install Setuptools, as it
+makes it much easier for you to use other third-party Python libraries.
+
+Working with Python 3
+---------------------
+
+At this point, you may also have Python 2.7 installed.
+
+.. code-block:: console
+
+ $ python
+
+This will launch the Python 2 interpreter.
+
+.. code-block:: console
+
+ $ python3
+
+This will launch the Python 3 interpreter.
+
+
+Setuptools + Pip
+----------------
+
+The two most crucial third-party Python packages are `setuptools `_ and `pip `_,
+which let you download, install and uninstall any compliant Python software
+product with a single command. It also enables you to add this network installation
+capability to your own Python software with very little work.
+
+All supported versions of Python 3 include pip, so just make sure it's up to date::
+
+ python -m pip install -U pip
+
+
+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 projects
+in 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 keeps
+your global site-packages directory clean and manageable.
+
+For example, you can work on a project which requires Django 1.10 while also
+maintaining a project which requires Django 1.8.
+
+So, onward! To the :ref:`Pipenv & Virtual Environments ` docs!
+
+--------------------------------
+
+This page is a remixed version of `another guide `_,
+which is available under the same license.
diff --git a/docs/starting/installation.rst b/docs/starting/installation.rst
index 5df0035f3..bb84c2715 100644
--- a/docs/starting/installation.rst
+++ b/docs/starting/installation.rst
@@ -1,6 +1,10 @@
+.. _installation:
+
Properly Installing Python
==========================
+.. image:: https://farm5.staticflickr.com/4303/36137232412_fdcb0f84eb_k_d.jpg
+
There's a good chance that you already have Python on your operating system.
If so, you do not need to install or configure anything else to use Python.
@@ -10,12 +14,26 @@ applications for real-world use. In particular, you should always install
Setuptools, Pip, and Virtualenv — they make it much easier for you to use
other third-party Python libraries.
+.. note:: The use of **Python 3** is *highly* preferred over Python 2. Consider upgrading your applications and infrastructure if you find yourself *still* using Python 2 in production today. If you are using Python 3, congratulations — you are indeed a person of excellent taste.
+ —*Kenneth Reitz*
+
+
Installation Guides
-------------------
-These guides go over the proper installation of :ref:`Python 2.7 `
-for development purposes, as well as setuptools, pip, and virtualenv setup.
+These guides go over the proper installation of :ref:`Python `
+for development purposes, as well as setuptools, pip and virtualenv.
+
+Python 3 Installation Guides
+////////////////////////////
+
+- :ref:`Python 3 on MacOS `.
+- :ref:`Python 3 on Windows `.
+- :ref:`Python 3 on Linux `.
+
+Legacy Python 2 Installation Guides
+///////////////////////////////////
-- :ref:`Mac OS X `.
-- :ref:`Microsoft Windows `.
-- :ref:`Linux `.
+- :ref:`Python 2 on MacOS `.
+- :ref:`Python 2 on Microsoft Windows `.
+- :ref:`Python 2 on Linux `.
diff --git a/docs/starting/which-python.rst b/docs/starting/which-python.rst
index 26732e34e..155eadb0c 100644
--- a/docs/starting/which-python.rst
+++ b/docs/starting/which-python.rst
@@ -1,57 +1,53 @@
-Picking an Interpreter
-======================
+Picking an Python Interpreter (3 vs. 2)
+=======================================
+
+.. image:: https://farm5.staticflickr.com/4265/34484834733_5b80f65ab1_k_d.jpg
.. _which-python:
-The State of Python (2 vs 3)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The State of Python (3 & 2)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
When choosing a Python interpreter, one looming question is always present:
-"Should I choose Python 2 or Python 3"? The answer is not as obvious as
+"Should I choose Python 2 or Python 3"? The answer is a bit more subtle than
one might think.
The basic gist of the state of things is as follows:
-1. Python 2.7 has been the standard for a *long* time.
-2. Python 3 introduced major changes to the language, which many developers are unhappy with.
-3. Python 2.7 will receive necessary security updates until 2020 [#pep373_eol]_.
-4. Python 3 is continually evolving, like Python 2 did in years past.
-
-So, you can now see why this is not such an easy decision.
-
+1. Most production applications today use Python 2.7.
+2. Python 3 is ready for the production deployment of applications today.
+3. Python 2.7 will only receive necessary security updates until 2020 [#pep373_eol]_.
+4. The brand name "Python" encapsulates both Python 3 and Python 2.
Recommendations
~~~~~~~~~~~~~~~
-I'll be blunt:
-
-
-**Use Python 3 if...**
-- You don't care.
-- You love Python 3.
-- You are indifferent towards 2 vs 3.
-- You don't know which one to use.
-- You embrace change.
+.. note:: The use of **Python 3** is *highly* preferred over Python 2. Consider upgrading your applications and infrastructure if you find yourself *still* using Python 2 in production today. If you are using Python 3, congratulations — you are indeed a person of excellent taste.
+ —*Kenneth Reitz*
-**Use Python 2 if...**
-
-- You love Python 2 and are saddened by the future being Python 3.
-- The stability requirements of your software would be improved by a language and runtime that never changes.
-- Software that you depend on requires it.
+I'll be blunt:
+- Use Python 3 for new Python applications.
+- If you're learning Python for the first time, familiarizing yourself with Python 2.7 will be very
+ useful, but not more useful than learning Python 3.
+- Learn both. They are both "Python".
+- Software that is already built often depends on Python 2.7.
+- If you are writing a new open source Python library, it's best to write it for both Python 2 and 3
+ simultaneously. Only supporting Python 3 for a new library you want to be widely adopted is a
+ political statement and will alienate many of your users. This is not a problem — slowly, over the next three years, this will become less the case.
So.... 3?
~~~~~~~~~
-If you're choosing a Python interpreter to use, and aren't opinionated, then I
+If you're choosing a Python interpreter to use, I
recommend you use the newest Python 3.x, since every version brings new and
-improved standard library modules, security and bug fixes. Progress is progress.
+improved standard library modules, security and bug fixes.
-Given such, only use Python 2 if you have a strong reason to, such as a Python 2
-exclusive library which has no adequate Python 3 ready alternative, or you
-(like me) absolutely love and are inspired by Python 2.
+Given such, only use Python 2 if you have a strong reason to, such as a
+pre-existing code-base, a Python 2 exclusive library, simplicity/familiarity,
+or, of course, you absolutely love and are inspired by Python 2. No harm in that.
Check out `Can I Use Python 3? `_ to see if any
software you're depending on will block your adoption of Python 3.
@@ -62,7 +58,9 @@ It is possible to `write code that works on Python 2.6, 2.7, and Python 3
`_. This
ranges from trivial to hard depending upon the kind of software
you are writing; if you're a beginner there are far more important things to
-worry about.
+worry about. Note that Python 2.6 is end-of-life upstream, so you shouldn't
+try to write 2.6-compatible code unless you're being paid specifically to
+do that.
Implementations
~~~~~~~~~~~~~~~
diff --git a/docs/writing/documentation.rst b/docs/writing/documentation.rst
index bdd39e13e..d251a0b99 100644
--- a/docs/writing/documentation.rst
+++ b/docs/writing/documentation.rst
@@ -1,6 +1,8 @@
Documentation
=============
+.. image:: https://farm5.staticflickr.com/4279/35620636012_f66aa88f93_k_d.jpg
+
Readability is a primary focus for Python developers, in both project
and code documentation. Following some simple best practices can save
both you and others a lot of time.
@@ -205,8 +207,8 @@ more information about a function, what it does, any exceptions it may raise,
what it returns, or relevant details about the parameters.
For more detailed documentation of code a popular style is the one used for the
-Numpy project, often called `Numpy style`_ docstrings. While it can take up a
-few more lines the previous example, it allows the developer to include a lot
+Numpy project, often called `Numpy style`_ docstrings. While it can take up more
+lines than the previous example, it allows the developer to include a lot
more information about a method, function, or class. ::
def random_number_generator(arg1, arg2):
diff --git a/docs/writing/gotchas.rst b/docs/writing/gotchas.rst
index f8e2e2377..cfbb08a12 100644
--- a/docs/writing/gotchas.rst
+++ b/docs/writing/gotchas.rst
@@ -1,6 +1,8 @@
Common Gotchas
==============
+.. image:: https://farm5.staticflickr.com/4163/34435688380_b5a740762b_k_d.jpg
+
For the most part, Python aims to be a clean and consistent language that
avoids surprises. However, there are a few cases that can be confusing to
newcomers.
@@ -76,6 +78,7 @@ signal that no argument was provided (:py:data:`None` is often a good choice).
to.append(element)
return to
+Do not forget, you are passing a *list* object as the second argument.
When the Gotcha Isn't a Gotcha
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -229,13 +232,29 @@ Here's nice trick for removing all of these files, if they already exist::
Run that from the root directory of your project, and all ``.pyc`` files
will suddenly vanish. Much better.
+.. _version_control_ignores:
+Version Control Ignores
+~~~~~~~~~~~~~~~~~~~~~~~
+If you still need the ``.pyc`` files for performance reasons, you can always add them
+to the ignore files of your version control repositories. Popular version control
+systems have the ability to use wildcards defined in a file to apply special
+rules.
+An ignore file will make sure the matching files don't get checked into the repository.
+Git_ uses ``.gitignore`` while Mercurial_ uses ``.hgignore``.
+.. _Git: https://git-scm.com/
+.. _Mercurial: https://www.mercurial-scm.org/
+At the minimum your ignore files should look like this.
+::
+ syntax:glob # This line is not needed for .gitignore files.
+ *.py[cod] # Will match .pyc, .pyo and .pyd files.
+ __pycache__/ # Exclude the whole folder
-
-
+You may wish to include more files and directories depending on your needs.
+The next time you commit to the repository, these files will not be included.
diff --git a/docs/writing/license.rst b/docs/writing/license.rst
index 6c42df767..dd5fe3bb8 100644
--- a/docs/writing/license.rst
+++ b/docs/writing/license.rst
@@ -1,6 +1,8 @@
Choosing a License
==================
+.. image:: https://farm5.staticflickr.com/4228/33907149294_82d7535a6c_k_d.jpg
+
Your source publication *needs* a license. In the US, if no license is
specified, users have no legal right to download, modify, or distribute.
Furthermore, people can't contribute to your code unless you tell them what
diff --git a/docs/writing/logging.rst b/docs/writing/logging.rst
index 9b41abadf..184e9e8b6 100644
--- a/docs/writing/logging.rst
+++ b/docs/writing/logging.rst
@@ -1,6 +1,8 @@
Logging
=======
+.. image:: https://farm5.staticflickr.com/4246/35254379756_c9fe23f843_k_d.jpg
+
The :mod:`logging` module has been a part of Python's Standard Library since
version 2.3. It is succinctly described in :pep:`282`. The documentation
is notoriously hard to read, except for the `basic logging tutorial`_.
@@ -55,17 +57,8 @@ this in your ``__init__.py``
.. code-block:: python
- # Set default logging handler to avoid "No handler found" warnings.
import logging
- try: # Python 2.7+
- from logging import NullHandler
- except ImportError:
- class NullHandler(logging.Handler):
- def emit(self, record):
- pass
-
- logging.getLogger(__name__).addHandler(NullHandler())
-
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
Logging in an Application
diff --git a/docs/writing/reading.rst b/docs/writing/reading.rst
index 97342250a..0b6486d51 100644
--- a/docs/writing/reading.rst
+++ b/docs/writing/reading.rst
@@ -1,6 +1,8 @@
Reading Great Code
==================
+.. image:: https://farm5.staticflickr.com/4221/34689452831_93d7fd0571_k_d.jpg
+
One of the core tenets behind the design of Python is creating
readable code. The motivation behind this design is simple: The number
one thing that Python programmers do is read code.
diff --git a/docs/writing/structure.rst b/docs/writing/structure.rst
index a156fba7f..b0dc9cadf 100644
--- a/docs/writing/structure.rst
+++ b/docs/writing/structure.rst
@@ -1,6 +1,8 @@
Structuring Your Project
========================
+.. image:: https://farm5.staticflickr.com/4203/33907151224_0574e7dfc2_k_d.jpg
+
By "structure" we mean the decisions you make concerning
how your project best meets its objective. We need to consider how to
best leverage Python's features to create clean, effective code.
@@ -172,6 +174,8 @@ Test Suite
::::::::::
+*For advice on writing your tests, see :doc:`writing/tests`.*
+
.. csv-table::
:widths: 20, 40
@@ -200,7 +204,7 @@ it. You can do this a few ways:
package properly.
I highly recommend the latter. Requiring a developer to run
-`setup.py `__ develop to test an actively changing
+``setup.py develop`` to test an actively changing
codebase also requires them to have an isolated environment setup for
each instance of the codebase.
@@ -211,7 +215,7 @@ file:
import os
import sys
- sys.path.insert(0, os.path.abspath('..'))
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import sample
@@ -391,7 +395,17 @@ folder named :file:`my` which is not the case. There is an
dot notation should be used in the Python docs.
If you'd like you could name your module :file:`my_spam.py`, but even our
-friend the underscore should not be seen often in module names.
+friend the underscore should not be seen often in module names. However, using other
+characters (spaces or hyphens) in module names will prevent importing
+(- is the subtract operator), so try to keep module names short so there is
+no need to separate words. And, most of all, don't namespace with underscores, use submodules instead.
+
+.. code-block:: python
+
+ # OK
+ import library.plugin.foo
+ # not OK
+ import library.foo_plugin
Aside from some naming restrictions, nothing special is required for a Python
file to be a module, but you need to understand the import mechanism in order
@@ -633,7 +647,7 @@ with the class approach:
class CustomOpen(object):
def __init__(self, filename):
- self.file = open(filename)
+ self.file = open(filename)
def __enter__(self):
return self.file
@@ -762,7 +776,7 @@ compute x + 1, you have to create another integer and give it a name.
my_list = [1, 2, 3]
my_list[0] = 4
- print my_list # [4, 2, 3] <- The same list as changed
+ print my_list # [4, 2, 3] <- The same list has changed
x = 6
x = x + 1 # The new x is another object
@@ -785,7 +799,12 @@ its parts, it is much more efficient to accumulate the parts in a list,
which is mutable, and then glue ('join') the parts together when the
full string is needed. One thing to notice, however, is that list
comprehensions are better and faster than constructing a list in a loop
-with calls to ``append()``.
+with calls to ``append()``.
+
+One other option is using the map function, which can 'map' a function
+('str') to an iterable ('range(20)'). This results in a map object,
+which you can then ('join') together just like the other examples.
+The map function can be even faster than a list comprehension in some cases.
**Bad**
@@ -794,7 +813,7 @@ with calls to ``append()``.
# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = ""
for n in range(20):
- nums += str(n) # slow and inefficient
+ nums += str(n) # slow and inefficient
print nums
**Good**
@@ -804,16 +823,24 @@ with calls to ``append()``.
# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = []
for n in range(20):
- nums.append(str(n))
+ nums.append(str(n))
print "".join(nums) # much more efficient
-**Best**
+**Better**
.. code-block:: python
# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = [str(n) for n in range(20)]
print "".join(nums)
+
+**Best**
+
+.. code-block:: python
+
+ # create a concatenated string from 0 to 19 (e.g. "012..1819")
+ nums = map(str, range(20))
+ print "".join(nums)
One final thing to mention about strings is that using ``join()`` is not always
best. In the instances where you are creating a new string from a pre-determined
diff --git a/docs/writing/style.rst b/docs/writing/style.rst
index 7454e9465..abd0af49f 100644
--- a/docs/writing/style.rst
+++ b/docs/writing/style.rst
@@ -3,6 +3,8 @@
Code Style
==========
+.. image:: https://farm5.staticflickr.com/4223/33907150054_5ee79e8940_k_d.jpg
+
If you ask Python programmers what they like most about Python, they will
often cite its high readability. Indeed, a high level of readability
is at the heart of the design of the Python language, following the
@@ -459,23 +461,23 @@ best to adhere to the guidelines laid out within this document. Some project
may sway from it from time to time, while others may
`amend its recommendations `_.
-That being said, conforming your Python code to PEP 8 is generally a good
-idea and helps make code more consistent when working on projects with other
-developers. There is a command-line program, `pep8 `_,
-that can check your code for conformance. Install it by running the following
-command in your terminal:
+That being said, conforming your Python code to PEP 8 is generally a good idea
+and helps make code more consistent when working on projects with other
+developers. There is a command-line program, `pycodestyle `_
+(previously known as ``pep8``), that can check your code for conformance.
+Install it by running the following command in your terminal:
.. code-block:: console
- $ pip install pep8
+ $ pip install pycodestyle
Then run it on a file or series of files to get a report of any violations.
.. code-block:: console
- $ pep8 optparse.py
+ $ pycodestyle optparse.py
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
optparse.py:88:5: E301 expected 1 blank line, found 0
diff --git a/docs/writing/tests.rst b/docs/writing/tests.rst
index b8b7ca022..32c6e552e 100644
--- a/docs/writing/tests.rst
+++ b/docs/writing/tests.rst
@@ -1,6 +1,8 @@
Testing Your Code
=================
+.. image:: https://farm5.staticflickr.com/4166/34435687940_8f73fc1fa6_k_d.jpg
+
Testing your code is very important.
Getting used to writing testing code and running this code in parallel is now
@@ -185,24 +187,41 @@ and then running the `py.test` command
is far less work than would be required for the equivalent functionality with
the unittest module!
- `py.test `_
-
+ `py.test `_
-Nose
-----
-nose extends unittest to make testing easier.
+Hypothesis
+----------
+Hypothesis is a library which lets you write tests that are parametrized by
+a source of examples. It then generates simple and comprehensible examples
+that make your tests fail, letting you find more bugs with less work.
.. code-block:: console
- $ pip install nose
+ $ pip install hypothesis
+
+For example, testing lists of floats will try many examples, but report the
+minimal example of each bug (distinguished exception type and location):
+
+.. code-block:: python
+
+ @given(lists(floats(allow_nan=False, allow_infinity=False), min_size=1))
+ def test_mean(xs):
+ mean = sum(xs) / len(xs)
+ assert min(xs) <= mean(xs) <= max(xs)
+
+.. code-block:: none
-nose provides automatic test discovery to save you the hassle of manually
-creating test suites. It also provides numerous plugins for features such as
-xUnit-compatible test output, coverage reporting, and test selection.
+ Falsifying example: test_mean(
+ xs=[1.7976321109618856e+308, 6.102390043022755e+303]
+ )
- `nose `_
+Hypothesis is practical as well as very powerful, and will often find bugs
+that escaped all other forms of testing. It integrates well with py.test,
+and has a strong focus on usability in both simple and advanced scenarios.
+
+ `hypothesis `_
tox
@@ -218,7 +237,8 @@ multiple interpreter configurations
tox allows you to configure complicated multi-parameter test matrices via a
simple ini-style configuration file.
- `tox `_
+ `tox `_
+
Unittest2
---------