Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,32 @@ happily accept any :doc:`contributions and feedback <contribute>`. 😊
.. _GitHub: https://github.com/pypa/python-packaging-user-guide
.. _Python Packaging Authority: https://pypa.io

.. note:: Looking for guidance on migrating from legacy PyPI to :term:`pypi.org`? Please see :doc:`guides/migrating-to-pypi-org`.
.. note:: Looking for guidance on migrating from legacy PyPI to :term:`pypi.org`?
Please see :doc:`guides/migrating-to-pypi-org`.

Get started
===========

Essential tools and concepts for working with the Python packaging ecosystem are covered in our :doc:`tutorials/index` section:
Essential tools and concepts for working with the Python packaging ecosystem are
covered in our :doc:`tutorials/index` section:

* to learn how to install packages, see the :doc:`tutorial on installing packages <tutorials/installing-packages>`.
* to learn how to package and distribute your projects, see the :doc:`tutorial on packaging and distributing <tutorials/distributing-packages>`
* to learn how to install packages, see the
:doc:`tutorial on installing packages <tutorials/installing-packages>`.
* to learn how to manage dependencies in a collaborative project, see the
:doc:`tutorial on managing application dependencies <tutorials/managing-dependencies>`.
* to learn how to package and distribute your projects, see the
:doc:`tutorial on packaging and distributing <tutorials/distributing-packages>`

Learn more
==========

Beyond our :doc:`tutorials/index`, this guide has several other resources:

* the :doc:`guides/index` section for walk throughs, such as :doc:`guides/installing-using-linux-tools` or :doc:`guides/packaging-binary-extensions`
* the :doc:`discussions/index` section for in-depth references on topics such as :doc:`discussions/deploying-python-applications` or :doc:`discussions/pip-vs-easy-install`
* the :doc:`guides/index` section for walk throughs, such as
:doc:`guides/installing-using-linux-tools` or :doc:`guides/packaging-binary-extensions`
* the :doc:`discussions/index` section for in-depth references on topics such as
:doc:`discussions/deploying-python-applications` or :doc:`discussions/pip-vs-easy-install`
* the :doc:`specifications/index` section for packaging interoperability specifications

Additionally, there is a list of :doc:`other projects <key_projects>` maintained by members of the Python Packaging Authority.
Additionally, there is a list of :doc:`other projects <key_projects>` maintained
by members of the Python Packaging Authority.
13 changes: 0 additions & 13 deletions source/new-tutorials/index.rst

This file was deleted.

2 changes: 2 additions & 0 deletions source/tutorials/distributing-packages.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _distributing-packages:

===================================
Packaging and Distributing Projects
===================================
Expand Down
1 change: 1 addition & 0 deletions source/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ topics, see :doc:`/guides/index`.
:maxdepth: 1

installing-packages
managing-dependencies
distributing-packages
127 changes: 93 additions & 34 deletions source/tutorials/installing-packages.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _installing-packages:

===================
Installing Packages
===================
Expand Down Expand Up @@ -27,32 +29,82 @@ Requirements for Installing Packages
This section describes the steps to follow before installing other Python
packages.

Install pip, setuptools, and wheel
----------------------------------

* If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from `python.org
<https://www.python.org>`_, you will already have :ref:`pip` and
:ref:`setuptools`, but will need to upgrade to the latest version:
Ensure you can run Python from the command line
-----------------------------------------------

Before you go any further, make sure you have Python and that the expected
version is available from your command line. You can check this by running:

.. code-block:: bash

python --version

You should get some output like ``Python 3.6.3``. If you do not have Python,
please install the latest 3.x version from `python.org`_ or refer to the
`Installing Python`_ section of the Hitchhiker's Guide to Python.

.. Note:: If you're a newcomer and you get an error like this:

.. code-block:: python

>>> python --version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined

It's because this command and other suggested commands in this tutorial
are intended to be run in a *shell* (also called a *terminal* or
*console*). See the Python for Beginners `getting started tutorial`_ for
an introduction to using your operating system's shell and interacting with
Python.

If you're using an enhanced shell like IPython or the Jupyter notebook, you
can run system commands like those in this tutorial by prefacing them with
a ``!`` character::

.. code-block:: python

In [1]: !python --version
Python 3.6.3

On Linux or macOS:
.. Note:: Due to the way most Linux distributions are handling the Python 3
migration, Linux users using the system Python without creating a virtual
environment first should replace the ``python`` command in this tutorial
with ``python3`` and the ``pip`` command with ``pip3 --user``. Do *not*
run any of the commands in this tutorial with ``sudo``: if you get a
permissions error, come back to the section on creating virtual environments,
set one up, and then continue with the tutorial as written.

::
.. _getting started tutorial: https://opentechschool.github.io/python-beginners/en/getting_started.html#what-is-python-exactly
.. _python.org: https://python.org

pip install -U pip setuptools
Ensure you can run pip from the command line
--------------------------------------------

Additionally, you'll need to make sure you have :ref:`pip` available. You can
check this by running:

On Windows:
.. code-block:: bash

::
pip --version

python -m pip install -U pip setuptools
If you installed Python from source, with an installer from `python.org`_, or
via `Homebrew`_ you should already have pip. If you're on Linux and installed
using your OS package manager, you may have to install pip separately, see
:doc:`/guides/installing-using-linux-tools`.

* If you're using a Python install on Linux that's managed by the system package
manager (e.g "yum", "apt-get" etc...), and you want to use the system package
manager to install or upgrade pip, then see :ref:`Installing
pip/setuptools/wheel with Linux Package Managers`
.. _Homebrew: https://brew.sh
.. _Installing Python: http://docs.python-guide.org/en/latest/starting/installation/

* Otherwise:
If ``pip`` isn't already installed, then first try to bootstrap it from the
standard library:

.. code-block:: bash

python -m ensurepip --default-pip

If that still doesn't allow you to run ``pip``:

* Securely Download `get-pip.py
<https://bootstrap.pypa.io/get-pip.py>`_ [1]_
Expand All @@ -71,26 +123,29 @@ Install pip, setuptools, and wheel
software.


Optionally, Create a virtual environment
----------------------------------------
Ensure pip, setuptools, and wheel are up to date
------------------------------------------------

See :ref:`section below <Creating and using Virtual Environments>` for details,
but here's the basic commands:
While ``pip`` alone is sufficient to install from pre-built binary archives,
up to date copies of the ``setuptools`` and ``wheel`` projects are useful
to ensure you can also install from source archives::

Using :ref:`virtualenv`:
python -m pip install --upgrade pip setuptools wheel

::

pip install virtualenv
virtualenv <DIR>
source <DIR>/bin/activate
Optionally, create a virtual environment
----------------------------------------

Using `venv`_: [3]_
See :ref:`section below <Creating and using Virtual Environments>` for details,
but here's the basic `venv`_ [3]_ command to use on a typical Linux system:

.. code-block:: bash

::
python3 -m venv tutorial_env
source tutorial_env/bin/activate

python3 -m venv <DIR>
source <DIR>/bin/activate
This will create a new virtual environment in the ``tutorial_env`` subdirectory,
and configure the current shell to use it as the default ``python`` environment.


.. _`Creating and using Virtual Environments`:
Expand Down Expand Up @@ -119,7 +174,7 @@ In all these cases, virtual environments can help you. They have their own
installation directories and they don’t share libraries with other virtual
environments.

Currently, there are two viable tools for creating Python virtual environments:
Currently, there are two common tools for creating Python virtual environments:

* `venv`_ is available by default in Python 3.3 and later, and installs
:ref:`pip` and :ref:`setuptools` into created virtual environments in
Expand Down Expand Up @@ -150,6 +205,11 @@ Using `venv`_:
For more information, see the `virtualenv <http://virtualenv.pypa.io>`_ docs or
the `venv`_ docs.

Managing multiple virtual environments directly can become tedious, so the
:ref:`dependency management tutorial <managing-dependencies>` introduces a
higher level tool, :ref:`Pipenv`, that automatically manages a separate
virtual environment for each project and application that you work on.


Use pip for Installing
======================
Expand All @@ -159,10 +219,6 @@ usage scenarios. For more detail, see the `pip docs <https://pip.pypa.io>`_,
which includes a complete `Reference Guide
<https://pip.pypa.io/en/latest/reference/index.html>`_.

There are a few cases where you might want to use `easy_install
<https://pip.pypa.io/en/latest/reference/index.html>`_ instead of pip. For
details, see :ref:`pip vs easy_install`.


Installing from PyPI
====================
Expand Down Expand Up @@ -250,6 +306,9 @@ For more information see the `User Installs
<https://pip.readthedocs.io/en/latest/user_guide.html#user-installs>`_ section
from the pip docs.

Note that the ``--user`` flag has no effect when inside a virtual environment
- all installation commands will affect the virtual environment.


Requirements files
==================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,38 @@
Installing and using packages
=============================

This tutorial walks you through installing and using Python packages. It will
show you how to install and use the necessary tools and make strong
recommendations on best practices. Keep in mind that Python is used for a great
many different purposes, and precisely how you want to manage your dependencies
may change based on how you decide to publish your software. The guidance
presented here is most directly applicable to the development and deployment of
network services (including web applications), but is also very well suited to
managing development and testing environments for any kind of project.
.. _managing-dependencies:

.. Note:: This guide is written for Python 3, however, these instructions
should work fine on Python 2.7.


Make sure you've got Python & pip
---------------------------------

Before you go any further, make sure you have Python and that it's avalable
from your command line. You can check this by simply running:

.. code-block:: bash

python --version

You should get some output like ``3.6.2``. If you do not have Python, please
install the latest 3.x version from `python.org`_ or refer to the
`Installing Python`_ section of the Hitchhiker's Guide to Python.
Managing Application Dependencies
=================================

.. Note:: If you're a newcomer and you get an error like this:

.. code-block:: python
The :ref:`package installation tutorial <installing-packages>`
covered the basics of getting set up to install and update Python packages.

>>> python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
However, running these commands interactively can get tedious even for your
own personal projects, and things get even more difficult when trying to set up
development environments automatically for projects with multiple contributors.

It's because this command and other suggested commands in this tutorial
are intended to be run in a *shell* (also called a *terminal* or
*console*). See the Python for Beginners `getting started tutorial`_ for
an introduction to using your operating system's shell and interacting with
Python.
This tutorial walks you through the use of :ref:`Pipenv` to manage dependencies
for an application. It will show you how to install and use the necessary tools
and make strong recommendations on best practices.

Additionally, you'll need to make sure you have :ref:`pip` available. You can
check this by running:
Keep in mind that Python is used for a great many different purposes, and
precisely how you want to manage your dependencies may change based on how you
decide to publish your software. The guidance presented here is most directly
applicable to the development and deployment of network services (including
web applications), but is also very well suited to managing development and
testing environments for any kind of project.

.. code-block:: bash

pip --version

If you installed Python from source, with an installer from `python.org`_, or
via `Homebrew`_ you should already have pip. If you're on Linux and installed
using your OS package manager, you may have to install pip separately, see
:doc:`/guides/installing-using-linux-tools`.

.. _getting started tutorial: https://opentechschool.github.io/python-beginners/en/getting_started.html#what-is-python-exactly
.. _python.org: https://python.org
.. _Homebrew: https://brew.sh
.. _Installing Python: http://docs.python-guide.org/en/latest/starting/installation/
.. Note:: This guide is written for Python 3, however, these instructions
should also work on Python 2.7.


Installing Pipenv
-----------------

:ref:`Pipenv` is a dependency manager for Python projects. If you're familiar
with Node.js' `npm`_ or Ruby's `bundler`_, it is similar in spirit to those
tools. While :ref:`pip` can install Python packages, Pipenv is recommended as
it's a higher-level tool that simplifies dependency management for common use
cases.
tools. While :ref:`pip` alone is often sufficient for personal use, Pipenv is
recommended for collaborative projects as it's a higher-level tool that
simplifies dependency management for common use cases.

Use ``pip`` to install Pipenv:

Expand Down Expand Up @@ -187,19 +151,14 @@ have access to your installed packages with ``pipenv shell``.
Next steps
----------

Congratulations, you now know how to install and use Python packages! ✨ 🍰 ✨

There's more resources you can look at to learn about installing and using
Python packages:

.. TODO:: Link to additional guides and resources.

If you find this approach isn't working well for you or your use case, you may
want to explore these other approaches:
Congratulations, you now know how to effectively manage dependencies and
development environments on a collaborative Python project! ✨ 🍰 ✨

.. TODO:: Link to alternatives
If you find this particular approach isn't working well for you or your use
case, you may want to explore these other approaches:

If you're interesting in creating and distributing Python packages, see the
tutorial on packaging and distributing packages.
* `pip-tools <https://github.com/jazzband/pip-tools>`_
* `hatch <https://github.com/ofek/hatch>`_

.. TODO:: Link to packaging tutorial when it exists.
If you're interesting in creating and distributing your own Python packages, see
the :ref:`tutorial on packaging and distributing packages <distributing-packages>`.