How to Download Python Packages

How to Download Python Packages

You have a few options when it comes to obtaining Python packages for inclusion in your project, depending on whether you want to download a package to a repository, download source code from which to build the package, or just download and install the package in your project in a single step. 

  • Pre-built packages can be downloaded from locations like the Python Package Index (PyPI) without having to install them. This can be done by directly downloading the file, or else using pip or a similar package manager, such as conda. This is a typical step for organizations that maintain a local repository of approved Python packages for enterprise use.
  • Source code for packages can be downloaded or cloned from locations like Github, Gitlab, etc. This is a typical step for those organizations that prefer to build their Python packages from source for reasons of security; or that need specific build options; or just to be able to work with the very latest version.
  • Downloading and installing a pre-built package in a single step can be done using either pip install or Pipenv. For more information, refer to Python Package Installation on Windows.

Whichever method you choose to use, it’s always good practice to ensure that you have up to date resources, including your installation of Python, pip, conda, etc. before downloading

How to use Pip to Download Packages

Use the following command to download packages with pip without installing them:

pip download <packagename> <options>

The following example will download version 1.13.0 of the six package (six-1.13.0-py2.py3-none-any.whl), into the /pipdownload directory:

pip download six==1.13.0 -d /pipdownload 

For more download options, enter:

pip download --help

How to use Pip to Download Packages for Anaconda

If you’re working with Anaconda’s version of Python, you can download packages using pip at the Anaconda Prompt. Open an Anaconda Prompt or terminal (depending on the operating system) and enter:

pip download <packagename> <options>

Note: the conda command option <–download-only> for downloading packages, is not  functional.  Conda –download-only  does not produce an error message and appears to work, but does not actually download the package.

How to use Pip to Download Packages in Anaconda Navigator

If you’re using Anaconda Navigator, you can download packages using pip:

  1. Start the Anaconda Navigator application.
  2. Select Environments in the left-hand column of the GUI.
  3. Click on the triangle icon in the Root box, and select Open Terminal.
  4. Enter:  pip download <packagename> <options>

How to Manually Download Packages from PyPI

You can download packages directly from PyPI by doing the following:

  1. Point your browser at https://pypi.org/project/<packagename>
  2. Select either Download Files to download the current package version, or Release History to select the version of your choice.
  3. Click on the package to save it to a location on your computer or network.

How to Download Source Code from Github

Many Python packages maintain their source code in Github repositories. The repositories can be cloned to create local copies on your computer, and kept in sync with the original code on Github.  Repositories can also be downloaded in zip files to your computer. 

The cloning method is especially suited for those who have already created a repository on GitHub, or would like to contribute to a repository owned by someone else.

Clone a Github Repository in Linux

If git is not already installed on your system, then enter:

$ sudo apt update
$ sudo apt install git

2. On GitHub, navigate to the main page of a repository, such as https://github.com/IBM/plex.

3. Click the Clone or download button located under the repository name

4. The repository can be cloned with either HTTPS (default), or with SSH if you provide a public SSH key.

5. cd to the directory where you want to clone the repository and then enter:

$ git clone https://github.com/IBM/plex.git

Clone a Repository with Github Desktop in Windows

Github repositories can be cloned with the Github Desktop GUI in Windows, which is available for download from: 

https://desktop.github.com/

Once Github Desktop has been downloaded and installed, navigate to the main page of the repository that you would like to clone. 

1. Under the repository name, click the Clone or download button. A dropdown is displayed. 

2. Click on Open in Desktop

3. Click on the Open GithubDesk.exe button in the popup windows and follow the prompts. The GUI will assist you in navigating to a local path where you want the repository cloned to.

 

Download a Github Repository

  1. On GitHub, navigate to the main page of the repository.
  2. Click the Clone or download button located under the repository name. A dropdown is displayed.
  3. Click on Download ZIP and save the repository as a zip file to your system.

Try a faster way of installing Python packages for Windows, Linux and Mac. Get ActivePython or build your own Python runtime with the packages you need. Get started free on the ActiveState Platform.

Related Quick Reads:

How to Update All Python Packages

How to Uninstall Python Packages

Katie Chang