Register to get access to free programming courses with interactive exercises

Alternative package sources Python: Setting up the environment

Earlier in the course, we installed the cowsay package. Unless otherwise specified, pip installs packages from the main index, PyPI.

In most cases, PyPI is the source we need. But there are cases where the package is in an alternative index, for example, an internal corporate one. Sometimes, developers upload packages to GitHub instead of publishing them in any index.

Pip knows how to work with alternative indexes and repositories containing the source code of packages. In this lesson, we'll look at both variations.

Alternative package indexes

If you call the pip install command with the --index-url <url> option, pip will look for the package and all its dependencies in the index at the specified URL address. Let's try to install a package from the training index Test PyPI:

asciicast

Note that the URL address of the index can be in the form of something-something'/'simple — it is how we should name indexes according to the convention.

Test PyPI contains most of the packages in the main PyPI, but usually, local index holders don't want to keep copies of all versions of all packages.

Usually, holders only store their packages and get all external dependencies from another index, usually an already regular PyPI.

The pip also has an option for this case: you can specify --index-url in addition to --extra-index-url <url>. In this configuration, pip looks for each package in the first index. If it doesn't find them, it looks for an additional index. The command as a whole may look like this:

python3 -m pip install --user --index-url https://test.pypi.org/simple --extra-index-url https://pypi.org/simple dogesay

Installing packages from repositories on GitHub

Sometimes you might not want to upload a package to PyPI. For example, when it isn't ready, you need to check and try to install it. In such cases, packages are installed directly from git repositories.

Let's install our tutorial package hexlet-boilerplates/python-package using pip:

asciicast

This package will only install if you have pip version 20 and above. If you see an error when installing the package, try updating the pip itself with this command:

python3 -m pip install --user --upgrade pip

Instead of the package name, we specify the URL address you would use when cloning the repository, but with the prefix git+ appended. This prefix tells pip that the URL is a Git repository — not necessarily hosted on GitHub.

During the package, pip will call git clone to clone the repository into a temporary directory. If we want to access a private repository, we enter a username and password. It also works with private GitHub repositories.

In general, pip supports other version control systems besides Git. Managing the installation of packages from these systems is very flexible. For example, you can specify the branches, tags, or commit hashes where the desired version of the located package is. You can read more about this in the documentation.

We haven't covered all possible package sources and briefly discussed the pip install command. If possible, we recommend you learn this and other pip commands in great detail, as pip is an essential tool for a Python developer.


Recommended materials

  1. The Python Package Installer (pip)
  2. Test PyPI
  3. Python package example (boilerplate)

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.bookmate">Bookmate</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.healthsamurai">Healthsamurai</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.dualboot">Dualboot</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.abbyy">Abbyy</span>
Suggested learning programs
profession
new
Developing web applications with Django
10 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.