From f461ba718ad348248d1a4bce6d43e6842f98e606 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 28 Aug 2017 20:48:46 -0700 Subject: [PATCH 1/6] add a new tutorial on installing packages --- source/new-tutorials/index.rst | 5 + source/new-tutorials/installing/index.rst | 19 +++ .../installing-and-using-packages.rst | 141 ++++++++++++++++++ .../installing/installing-packaging-tools.rst | 104 +++++++++++++ 4 files changed, 269 insertions(+) create mode 100644 source/new-tutorials/installing/index.rst create mode 100644 source/new-tutorials/installing/installing-and-using-packages.rst create mode 100644 source/new-tutorials/installing/installing-packaging-tools.rst diff --git a/source/new-tutorials/index.rst b/source/new-tutorials/index.rst index 0caef49e41..fd0be15472 100644 --- a/source/new-tutorials/index.rst +++ b/source/new-tutorials/index.rst @@ -3,6 +3,11 @@ New Tutorials ============= +.. toctree:: + :maxdepth: 1 + + installing/index + .. warning:: This section is for work-in-progress tutorials! These will eventually be promoted to the :doc:`/tutorials/index` section. Do not link to these pages! diff --git a/source/new-tutorials/installing/index.rst b/source/new-tutorials/installing/index.rst new file mode 100644 index 0000000000..f4d4b0c800 --- /dev/null +++ b/source/new-tutorials/installing/index.rst @@ -0,0 +1,19 @@ +:orphan: + +Installing and using Python packages +==================================== + +.. toctree:: + :maxdepth: 2 + :hidden: + + installing-packaging-tools + 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 the Python packging +ecosystem is a varied one so this isn't the only way to install and use +Python packages, however, it does cover the most common use cases. + +Continue on to :doc:`installing-packaging-tools`. diff --git a/source/new-tutorials/installing/installing-and-using-packages.rst b/source/new-tutorials/installing/installing-and-using-packages.rst new file mode 100644 index 0000000000..6e6415173a --- /dev/null +++ b/source/new-tutorials/installing/installing-and-using-packages.rst @@ -0,0 +1,141 @@ +Installing and using packages +============================= + +This tutorial will show you how to install a Python package and use it. Before +you read this tutorial make sure you have all the packaging tools by reading +:doc:`installing-packaging-tools`. + +Creating a virtualenv +--------------------- + +As mentioned in the previous tutorial, :ref:`virtualenv` allows you to manage +separate package installations for different projects. It essentially allows +you to create a "virtual" isolated Python installation and install packages +into that virtual installation. When you switch projects, you can simply +create a new virtual environment and not have to worry about breaking the +packages installed in the other environments. It is always recommended to use +a virtualenv while developing Python applications. + +To create a virtual environment, go to your project's directory (you can +just create an empty directory somewhere for this tutorial) and run +virtualenv: + +.. code-block:: bash + + virtualenv env + +.. Note:: If you have Python 2 and 3 installed, you will probably need to + specify the Python version you want using + ``virtualenv --python python3 env``. + +The second argument is the location to create the virtualenv. Generally, you +can just create this in your project and call it ``env``. + +.. Note:: You should exclude your virtualenv directory from your version + control system using ``.gitignore`` or similar. + +virtualenv will create a virtual Python installation in the ``env`` folder. + + +Activating a virtualenv +----------------------- + +Before you can start installing or using packages in your virtualenv you'll +need to *activate* it. + +On macOS and Linux: + +.. code-block:: bash + + source env/bin/activate + +On Windows:: + + .\env\Scripts\activate + +You can confirm you're in the virtualenv by checking the location of your +Python interpreter, it should point to the ``env`` directory. + +On macOS and Linux: + +.. code-block:: bash + + which python + .../env/bin/python + +On Windows: + +.. code-block:: bash + + where python + .../env/bin/python.exe + + +Installing packages +------------------- + +Now that you're in your virtualenv you can install packages. Let's install +the excellent `Requests`_ library from the :term:`Python Package Index (PyPI)`: + +.. code-block:: bash + + pip install requests + +pip should download requests and all of its dependencies and install them: + +.. code-block:: text + + Collecting requests + Using cached requests-2.18.4-py2.py3-none-any.whl + Collecting chardet<3.1.0,>=3.0.2 (from requests) + Using cached chardet-3.0.4-py2.py3-none-any.whl + Collecting urllib3<1.23,>=1.21.1 (from requests) + Using cached urllib3-1.22-py2.py3-none-any.whl + Collecting certifi>=2017.4.17 (from requests) + Using cached certifi-2017.7.27.1-py2.py3-none-any.whl + Collecting idna<2.7,>=2.5 (from requests) + Using cached idna-2.6-py2.py3-none-any.whl + Installing collected packages: chardet, urllib3, certifi, idna, requests + Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 + +.. _Requests: http://docs.python-requests.org/ + + +Using installed packages +------------------------ + +Now that requests is installed you can create a simple ``main.py`` file to +use it: + +.. code-block:: python + + import requests + + response = requests.get('https://httpbin.org/ip') + + print('Your IP is {}'.format(response.text)) + +As long as you're in your virtualenv you'll be able to import and use your +installed packages. + + +Leaving the virtualenv +---------------------- + +If you want to switch projects or otherwise leave your virtualenv, simply run: + +.. code-block:: bash + + deactivate + +If you want to re-enter the virtualenv just follow the same instructions above +about activating a virtualenv. There's no need to re-create the virtualenv. + + +Next steps +---------- + +You now know how to install and use Python packages! :) However, there is +still some other useful things to learn that can be helpful. + +.. TODO:: Link to tutorials on using requirements.txt, guides on using different install sources and methods, etc. diff --git a/source/new-tutorials/installing/installing-packaging-tools.rst b/source/new-tutorials/installing/installing-packaging-tools.rst new file mode 100644 index 0000000000..2945e470d6 --- /dev/null +++ b/source/new-tutorials/installing/installing-packaging-tools.rst @@ -0,0 +1,104 @@ +Installing packaging tools +========================== + +This tutorial will show you how to install the Python package manager and +associated tools. + +Make sure you've got Python +--------------------------- + +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.1``. 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:: This guide is written for Python 3, however, these instructions + should work fine on Python 2. If there are any caveats for Python 2 this + guide will call it out with a note just like this one. + +.. _python.org: https://python.org +.. _Installing Python: http://docs.python-guide.org/en/latest/starting/installation/ + + +Installing pip +-------------- + +:ref:`pip` is the the Python package manager. It's used to install and update +packages. You'll need to make sure you have the latest version of pip +installed. + + +Windows ++++++++ + +The Python installers for Windows include pip. If you setup Python to be in +your ``PATH`` you should have access to pip already: + +.. code-block:: bash + + pip version + pip 9.0.1 from c:\python36\lib\site-packages (Python 3.6.1) + +.. Note:: If Python and pip aren't in your PATH, If you you'll need to add + Python's installation directory as well as the Scripts folder to your path, + for example: ``C:\Python36\;C:\Python36\Scripts\``. + +You should make sure that pip is up-to-date by running: + +.. code-block:: bash + + pip install --upgrade pip + + +Linux and macOS +++++++++++++++++ + +While Debian and most other distributions include a `python-pip`_ package, it's +recommended that you install pip yourself to get the latest version. This +also applies to Python on OS X (both system and Homebrew Python): + +.. code-block:: bash + + wget https://bootstrap.pypa.io/get-pip.py + sudo python get-pip.py + +.. _python-pip: https://packages.debian.org/stable/python-pip + +Afterwards, you should have pip: + +.. code-block:: bash + + pip --version + pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7) + + +Installing virtualenv +--------------------- + +:ref:`virtualenv` is used to manage Python packages for different projects. +Using virtualenv allows you to avoid installing Python packages globally +which could break system tools or other projects. + +Since you now have pip, you can install virtualenv by running: + +.. code-block:: bash + + pip install --upgrade virtualenv + +.. Note:: If you're on Linux or macOS, you may need to run this with ``sudo``. + In general, you should avoid invoking pip with ``sudo`` as this installs + packages globally. However, virtualenv and pip are core utilities that + make sense to be installed globally. + + +Next step +--------- + +Now that you've got the tools installed, continue on to +:doc:`installing-and-using-packages`. From e0f6ae643db17628258d170799afd1086b8e04b8 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Tue, 29 Aug 2017 19:46:15 -0700 Subject: [PATCH 2/6] Re-write tutorial to use pipenv --- source/key_projects.rst | 30 +++- source/new-tutorials/index.rst | 10 +- .../installing-and-using-packages.rst | 166 ++++++++++++++++++ source/new-tutorials/installing/index.rst | 19 -- .../installing-and-using-packages.rst | 141 --------------- .../installing/installing-packaging-tools.rst | 104 ----------- 6 files changed, 199 insertions(+), 271 deletions(-) create mode 100644 source/new-tutorials/installing-and-using-packages.rst delete mode 100644 source/new-tutorials/installing/index.rst delete mode 100644 source/new-tutorials/installing/installing-and-using-packages.rst delete mode 100644 source/new-tutorials/installing/installing-packaging-tools.rst diff --git a/source/key_projects.rst b/source/key_projects.rst index bb0dbf144a..6f5a46ff71 100644 --- a/source/key_projects.rst +++ b/source/key_projects.rst @@ -76,6 +76,16 @@ Dev irc:#pypa-dev A tool for installing Python packages. +.. _Pipfile: + +Pipfile +======= + +`Source `__ + +``Pipfile`` and its sister ``Pipfile.lock`` are a replacement for the existing +standard :ref:`pip`'s ``requirements.txt`` file. + Python Packaging User Guide =========================== @@ -158,8 +168,8 @@ Warehouse Dev irc:#pypa-dev -The current codebase powering :term:`PyPI`. It is hosted at -`pypi.org `_. +The current codebase powering the :term:`Python Package Index (PyPI)`. It is +hosted at `pypi.org `_. .. _wheel: @@ -310,6 +320,22 @@ files, standalone Python environments in the spirit of :ref:`virtualenv`. ``#!/usr/bin/env python`` and special ``__main__.py``, and are designed to make deployment of Python applications as simple as ``cp``. + +.. _Pipenv: + +Pipenv +====== + +`Docs `__ | +`Source `__ | +`Issues `__ | +`PyPI `__ + +Pipenv is a project that aims to bring the best of all packaging worlds to the +Python world. It harnesses :ref:`Pipfile`, :ref:`pip`, and :ref:`virtualenv` +into one single toolchain. It features very pretty terminal colors. + + .. _spack: Spack diff --git a/source/new-tutorials/index.rst b/source/new-tutorials/index.rst index fd0be15472..ced8d62fa4 100644 --- a/source/new-tutorials/index.rst +++ b/source/new-tutorials/index.rst @@ -3,11 +3,11 @@ New Tutorials ============= -.. toctree:: - :maxdepth: 1 - - installing/index - .. warning:: This section is for work-in-progress tutorials! These will eventually be promoted to the :doc:`/tutorials/index` section. Do not link to these pages! + +.. toctree:: + :maxdepth: 1 + + installing-and-using-packages diff --git a/source/new-tutorials/installing-and-using-packages.rst b/source/new-tutorials/installing-and-using-packages.rst new file mode 100644 index 0000000000..06e613c8b5 --- /dev/null +++ b/source/new-tutorials/installing-and-using-packages.rst @@ -0,0 +1,166 @@ +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 the Python packaging +ecosystem is a broad and varied one so this isn't the only way to install and +use Python packages, however, it does cover the most common tools and use +cases. + +.. Note:: This guide is written for Python 3, however, these instructions + should work fine on Python 2. + + +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.1``. 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. + +Additionally, you'll need to make sure you have :ref:`pip` available. You can +check this by running: + +.. 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`. + +.. _python.org: https://python.org +.. _Homebrew: https://brew.sh +.. _Installing Python: http://docs.python-guide.org/en/latest/starting/installation/ + + +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. + +Use ``pip`` to install Pipenv: + +.. code-block:: python + + pip install --user pipenv + + +.. Note:: This does a `user installation`_ to prevent breaking any system-wide + packages. If ``pipenv`` isn't available in your shell after installation, + you'll need to add the `user base`_'s ``bin`` directory to your ``PATH``. + You can find the user base by running ``import site; print(site.USER_BASE)`` + in Python. For example, on Linux this will return ``~/.local`` so you'll + need to add ``~/.local/bin`` to your ``PATH``. + +.. _npm: https://www.npmjs.com/ +.. _bundler: http://bundler.io/ +.. _user base: https://docs.python.org/3/library/site.html#site.USER_BASE +.. _user installation: https://pip.pypa.io/en/stable/user_guide/#user-installs + + +Installing packages for your project +------------------------------------ + +Pipenv manages dependencies on a per-project basis. To install packages, +change into your project's directory (or just an empty directory for this +tutorial) and run: + +.. code-block:: bash + + cd myproject + pipenv install requests + +Pipenv will install the excellent `Requests`_ library and create a ``Pipfile`` +for you in your project's directory. The :ref:`Pipfile` is used to track which +dependencies your project needs in case you need to re-install them, such as +when you share your project with others. You should get output similar to this: + +.. code-block:: text + + Creating a Pipfile for this project... + Creating a virtualenv for this project... + Using base prefix '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6' + New python executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python3.6 + Also creating executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python + Installing setuptools, pip, wheel...done. + + Virtualenv location: ~/.local/share/virtualenvs/tmp-agwWamBd + Installing requests... + Collecting requests + Using cached requests-2.18.4-py2.py3-none-any.whl + Collecting idna<2.7,>=2.5 (from requests) + Using cached idna-2.6-py2.py3-none-any.whl + Collecting urllib3<1.23,>=1.21.1 (from requests) + Using cached urllib3-1.22-py2.py3-none-any.whl + Collecting chardet<3.1.0,>=3.0.2 (from requests) + Using cached chardet-3.0.4-py2.py3-none-any.whl + Collecting certifi>=2017.4.17 (from requests) + Using cached certifi-2017.7.27.1-py2.py3-none-any.whl + Installing collected packages: idna, urllib3, chardet, certifi, requests + Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 + + Adding requests to Pipfile's [packages]... + P.S. You have excellent taste! ✨ 🍰 ✨ + +.. _Requests: https://python-requests.org + + +Using installed packages +------------------------ + +Now that Requests is installed you can create a simple ``main.py`` file to +use it: + +.. code-block:: python + + import requests + + response = requests.get('https://httpbin.org/ip') + + print('Your IP is {}'.format(response.json['origin'])) + +Then you can run this script using ``pipenv run``: + +.. code-block:: bash + + pipenv run python main.py + +You should get output similar to this: + +.. code-block:: text + + Your IP is 8.8.8.8 + +Using ``pipenv run`` ensures that your installed packages are available to +your script. It's also possible to spawn a new shell that ensures all commands +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're interesting in creating and distributing Python packages, see the +tutorial on packaging and distributing packages. + +.. TODO Link to packaging tutorial when it exists. diff --git a/source/new-tutorials/installing/index.rst b/source/new-tutorials/installing/index.rst deleted file mode 100644 index f4d4b0c800..0000000000 --- a/source/new-tutorials/installing/index.rst +++ /dev/null @@ -1,19 +0,0 @@ -:orphan: - -Installing and using Python packages -==================================== - -.. toctree:: - :maxdepth: 2 - :hidden: - - installing-packaging-tools - 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 the Python packging -ecosystem is a varied one so this isn't the only way to install and use -Python packages, however, it does cover the most common use cases. - -Continue on to :doc:`installing-packaging-tools`. diff --git a/source/new-tutorials/installing/installing-and-using-packages.rst b/source/new-tutorials/installing/installing-and-using-packages.rst deleted file mode 100644 index 6e6415173a..0000000000 --- a/source/new-tutorials/installing/installing-and-using-packages.rst +++ /dev/null @@ -1,141 +0,0 @@ -Installing and using packages -============================= - -This tutorial will show you how to install a Python package and use it. Before -you read this tutorial make sure you have all the packaging tools by reading -:doc:`installing-packaging-tools`. - -Creating a virtualenv ---------------------- - -As mentioned in the previous tutorial, :ref:`virtualenv` allows you to manage -separate package installations for different projects. It essentially allows -you to create a "virtual" isolated Python installation and install packages -into that virtual installation. When you switch projects, you can simply -create a new virtual environment and not have to worry about breaking the -packages installed in the other environments. It is always recommended to use -a virtualenv while developing Python applications. - -To create a virtual environment, go to your project's directory (you can -just create an empty directory somewhere for this tutorial) and run -virtualenv: - -.. code-block:: bash - - virtualenv env - -.. Note:: If you have Python 2 and 3 installed, you will probably need to - specify the Python version you want using - ``virtualenv --python python3 env``. - -The second argument is the location to create the virtualenv. Generally, you -can just create this in your project and call it ``env``. - -.. Note:: You should exclude your virtualenv directory from your version - control system using ``.gitignore`` or similar. - -virtualenv will create a virtual Python installation in the ``env`` folder. - - -Activating a virtualenv ------------------------ - -Before you can start installing or using packages in your virtualenv you'll -need to *activate* it. - -On macOS and Linux: - -.. code-block:: bash - - source env/bin/activate - -On Windows:: - - .\env\Scripts\activate - -You can confirm you're in the virtualenv by checking the location of your -Python interpreter, it should point to the ``env`` directory. - -On macOS and Linux: - -.. code-block:: bash - - which python - .../env/bin/python - -On Windows: - -.. code-block:: bash - - where python - .../env/bin/python.exe - - -Installing packages -------------------- - -Now that you're in your virtualenv you can install packages. Let's install -the excellent `Requests`_ library from the :term:`Python Package Index (PyPI)`: - -.. code-block:: bash - - pip install requests - -pip should download requests and all of its dependencies and install them: - -.. code-block:: text - - Collecting requests - Using cached requests-2.18.4-py2.py3-none-any.whl - Collecting chardet<3.1.0,>=3.0.2 (from requests) - Using cached chardet-3.0.4-py2.py3-none-any.whl - Collecting urllib3<1.23,>=1.21.1 (from requests) - Using cached urllib3-1.22-py2.py3-none-any.whl - Collecting certifi>=2017.4.17 (from requests) - Using cached certifi-2017.7.27.1-py2.py3-none-any.whl - Collecting idna<2.7,>=2.5 (from requests) - Using cached idna-2.6-py2.py3-none-any.whl - Installing collected packages: chardet, urllib3, certifi, idna, requests - Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 - -.. _Requests: http://docs.python-requests.org/ - - -Using installed packages ------------------------- - -Now that requests is installed you can create a simple ``main.py`` file to -use it: - -.. code-block:: python - - import requests - - response = requests.get('https://httpbin.org/ip') - - print('Your IP is {}'.format(response.text)) - -As long as you're in your virtualenv you'll be able to import and use your -installed packages. - - -Leaving the virtualenv ----------------------- - -If you want to switch projects or otherwise leave your virtualenv, simply run: - -.. code-block:: bash - - deactivate - -If you want to re-enter the virtualenv just follow the same instructions above -about activating a virtualenv. There's no need to re-create the virtualenv. - - -Next steps ----------- - -You now know how to install and use Python packages! :) However, there is -still some other useful things to learn that can be helpful. - -.. TODO:: Link to tutorials on using requirements.txt, guides on using different install sources and methods, etc. diff --git a/source/new-tutorials/installing/installing-packaging-tools.rst b/source/new-tutorials/installing/installing-packaging-tools.rst deleted file mode 100644 index 2945e470d6..0000000000 --- a/source/new-tutorials/installing/installing-packaging-tools.rst +++ /dev/null @@ -1,104 +0,0 @@ -Installing packaging tools -========================== - -This tutorial will show you how to install the Python package manager and -associated tools. - -Make sure you've got Python ---------------------------- - -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.1``. 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:: This guide is written for Python 3, however, these instructions - should work fine on Python 2. If there are any caveats for Python 2 this - guide will call it out with a note just like this one. - -.. _python.org: https://python.org -.. _Installing Python: http://docs.python-guide.org/en/latest/starting/installation/ - - -Installing pip --------------- - -:ref:`pip` is the the Python package manager. It's used to install and update -packages. You'll need to make sure you have the latest version of pip -installed. - - -Windows -+++++++ - -The Python installers for Windows include pip. If you setup Python to be in -your ``PATH`` you should have access to pip already: - -.. code-block:: bash - - pip version - pip 9.0.1 from c:\python36\lib\site-packages (Python 3.6.1) - -.. Note:: If Python and pip aren't in your PATH, If you you'll need to add - Python's installation directory as well as the Scripts folder to your path, - for example: ``C:\Python36\;C:\Python36\Scripts\``. - -You should make sure that pip is up-to-date by running: - -.. code-block:: bash - - pip install --upgrade pip - - -Linux and macOS -++++++++++++++++ - -While Debian and most other distributions include a `python-pip`_ package, it's -recommended that you install pip yourself to get the latest version. This -also applies to Python on OS X (both system and Homebrew Python): - -.. code-block:: bash - - wget https://bootstrap.pypa.io/get-pip.py - sudo python get-pip.py - -.. _python-pip: https://packages.debian.org/stable/python-pip - -Afterwards, you should have pip: - -.. code-block:: bash - - pip --version - pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7) - - -Installing virtualenv ---------------------- - -:ref:`virtualenv` is used to manage Python packages for different projects. -Using virtualenv allows you to avoid installing Python packages globally -which could break system tools or other projects. - -Since you now have pip, you can install virtualenv by running: - -.. code-block:: bash - - pip install --upgrade virtualenv - -.. Note:: If you're on Linux or macOS, you may need to run this with ``sudo``. - In general, you should avoid invoking pip with ``sudo`` as this installs - packages globally. However, virtualenv and pip are core utilities that - make sense to be installed globally. - - -Next step ---------- - -Now that you've got the tools installed, continue on to -:doc:`installing-and-using-packages`. From 9532e3232a87859485650be1b176f0ef5a6b8e12 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Tue, 29 Aug 2017 20:05:43 -0700 Subject: [PATCH 3/6] Use Python 2.6 compatible format string --- source/new-tutorials/installing-and-using-packages.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/new-tutorials/installing-and-using-packages.rst b/source/new-tutorials/installing-and-using-packages.rst index 06e613c8b5..84a4f730f4 100644 --- a/source/new-tutorials/installing-and-using-packages.rst +++ b/source/new-tutorials/installing-and-using-packages.rst @@ -131,7 +131,7 @@ use it: response = requests.get('https://httpbin.org/ip') - print('Your IP is {}'.format(response.json['origin'])) + print('Your IP is {0}'.format(response.json['origin'])) Then you can run this script using ``pipenv run``: From 31ce3d591ce426eea1e1a689d53d659150ca3bf4 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Tue, 29 Aug 2017 20:07:11 -0700 Subject: [PATCH 4/6] 3.6.2 --- source/new-tutorials/installing-and-using-packages.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/new-tutorials/installing-and-using-packages.rst b/source/new-tutorials/installing-and-using-packages.rst index 84a4f730f4..d81acafe9b 100644 --- a/source/new-tutorials/installing-and-using-packages.rst +++ b/source/new-tutorials/installing-and-using-packages.rst @@ -22,7 +22,7 @@ from your command line. You can check this by simply running: python --version -You should get some output like ``3.6.1``. If you do not have Python, please +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. @@ -93,7 +93,7 @@ when you share your project with others. You should get output similar to this: Creating a Pipfile for this project... Creating a virtualenv for this project... - Using base prefix '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6' + Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6' New python executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python3.6 Also creating executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python Installing setuptools, pip, wheel...done. From 8e4d638c8db9862cc11ccf7c1f2e92f498475fae Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 30 Aug 2017 10:32:12 -0700 Subject: [PATCH 5/6] Address review comments --- source/key_projects.rst | 5 +- .../installing-and-using-packages.rst | 51 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/source/key_projects.rst b/source/key_projects.rst index 6f5a46ff71..da9170fda8 100644 --- a/source/key_projects.rst +++ b/source/key_projects.rst @@ -83,8 +83,9 @@ Pipfile `Source `__ -``Pipfile`` and its sister ``Pipfile.lock`` are a replacement for the existing -standard :ref:`pip`'s ``requirements.txt`` file. +``Pipfile`` and its sister ``Pipfile.lock`` are a higher-level +application-centric alternative to :ref:`pip`'s lower-level +``requirements.txt`` file. Python Packaging User Guide diff --git a/source/new-tutorials/installing-and-using-packages.rst b/source/new-tutorials/installing-and-using-packages.rst index 06e613c8b5..4ee946ec59 100644 --- a/source/new-tutorials/installing-and-using-packages.rst +++ b/source/new-tutorials/installing-and-using-packages.rst @@ -3,13 +3,15 @@ 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 the Python packaging -ecosystem is a broad and varied one so this isn't the only way to install and -use Python packages, however, it does cover the most common tools and use -cases. +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. .. Note:: This guide is written for Python 3, however, these instructions - should work fine on Python 2. + should work fine on Python 2.7. Make sure you've got Python & pip @@ -22,10 +24,24 @@ from your command line. You can check this by simply running: python --version -You should get some output like ``3.6.1``. If you do not have Python, please +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. +.. Note:: If you're newcomer and you get an error like this: + + .. code-block:: python + + >>> python + Traceback (most recent call last): + File "", line 1, in + NameError: name 'python' is not defined + + It's because this command is 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. + Additionally, you'll need to make sure you have :ref:`pip` available. You can check this by running: @@ -38,6 +54,7 @@ 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/ @@ -62,15 +79,19 @@ Use ``pip`` to install Pipenv: .. Note:: This does a `user installation`_ to prevent breaking any system-wide packages. If ``pipenv`` isn't available in your shell after installation, you'll need to add the `user base`_'s ``bin`` directory to your ``PATH``. - You can find the user base by running ``import site; print(site.USER_BASE)`` - in Python. For example, on Linux this will return ``~/.local`` so you'll - need to add ``~/.local/bin`` to your ``PATH``. + You can find the user base by running ``python -m site`` which will print + site information including the user base. For example, on Linux this will + return ``USER_BASE: '~/.local'`` so you'll need to add ``~/.local/bin`` to + your ``PATH``. On Linux and macOS you can set your ``PATH`` permanently + by `modifying ~/.profile`_. On Windows you can set the user + ``PATH`` permanently in the `Control Panel`_. .. _npm: https://www.npmjs.com/ .. _bundler: http://bundler.io/ .. _user base: https://docs.python.org/3/library/site.html#site.USER_BASE .. _user installation: https://pip.pypa.io/en/stable/user_guide/#user-installs - +.. _modifying ~/.profile: https://stackoverflow.com/a/14638025 +.. _Control Panel: https://msdn.microsoft.com/en-us/library/windows/desktop/bb776899(v=vs.85).aspx Installing packages for your project ------------------------------------ @@ -87,13 +108,14 @@ tutorial) and run: Pipenv will install the excellent `Requests`_ library and create a ``Pipfile`` for you in your project's directory. The :ref:`Pipfile` is used to track which dependencies your project needs in case you need to re-install them, such as -when you share your project with others. You should get output similar to this: +when you share your project with others. You should get output similar to this +(although the exact paths shown will vary): .. code-block:: text Creating a Pipfile for this project... Creating a virtualenv for this project... - Using base prefix '/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6' + Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6' New python executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python3.6 Also creating executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python Installing setuptools, pip, wheel...done. @@ -160,6 +182,11 @@ 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: + +.. TODO Link to alternatives + If you're interesting in creating and distributing Python packages, see the tutorial on packaging and distributing packages. From 0bf38038a6c9d5b5e23fd0c2d00e0157dfbfad32 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 30 Aug 2017 18:44:09 -0700 Subject: [PATCH 6/6] Address review comments --- source/conf.py | 7 +++++++ .../installing-and-using-packages.rst | 17 +++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/conf.py b/source/conf.py index a0e8df7d93..f2cad0ed58 100644 --- a/source/conf.py +++ b/source/conf.py @@ -32,6 +32,7 @@ # ones. extensions = [ 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', ] # Add any paths that contain templates here, relative to this directory. @@ -355,3 +356,9 @@ 'pip': ('https://pip.pypa.io/en/latest/', None), 'pypa': ('https://pypa.io/en/latest/', None), } + + +# f this is True, todo and todolist produce output, else they produce nothing. +# The default is False. + +todo_include_todos = True diff --git a/source/new-tutorials/installing-and-using-packages.rst b/source/new-tutorials/installing-and-using-packages.rst index 3e32427835..712e8e6bf8 100644 --- a/source/new-tutorials/installing-and-using-packages.rst +++ b/source/new-tutorials/installing-and-using-packages.rst @@ -28,7 +28,7 @@ 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. -.. Note:: If you're newcomer and you get an error like this: +.. Note:: If you're a newcomer and you get an error like this: .. code-block:: python @@ -37,10 +37,11 @@ install the latest 3.x version from `python.org`_ or refer to the File "", line 1, in NameError: name 'python' is not defined - It's because this command is 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. + 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. Additionally, you'll need to make sure you have :ref:`pip` available. You can check this by running: @@ -180,14 +181,14 @@ 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. +.. 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: -.. TODO Link to alternatives +.. TODO:: Link to alternatives If you're interesting in creating and distributing Python packages, see the tutorial on packaging and distributing packages. -.. TODO Link to packaging tutorial when it exists. +.. TODO:: Link to packaging tutorial when it exists.