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.
- Tip! The ActiveState Platform automatically builds all Python packages including linked C libraries from source code, and packages them for Windows, Linux and macOS. Because it does it all server-side, there’s no need to maintain local build environments. Try it out by signing up for a free ActiveState Platform account.
- 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.
Try a faster way of installing Python packages for Windows. Build your own Python environment with the packages you need. Get started for free on the ActiveState Platform.
How to use Pip to Download Packages in Anaconda Navigator
If you’re using Anaconda Navigator, you can download packages using pip:
- Start the Anaconda Navigator application.
- Select Environments in the left-hand column of the GUI.
- Click on the triangle icon in the Root box, and select Open Terminal.
- Enter: pip download <packagename> <options>
How to Manually Download Packages from PyPI
You can download packages directly from PyPI by doing the following:
- Point your browser at https://pypi.org/project/<packagename>
- Select either Download Files to download the current package version, or Release History to select the version of your choice.
- 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:
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
- On GitHub, navigate to the main page of the repository.
- Click the Clone or download button located under the repository name. A dropdown is displayed.
- Click on Download ZIP and save the repository as a zip file to your system.
Download Python Dependencies With the ActiveState Platform
The ActiveState Platform GraphQL API can be used to download the source code for packages and their dependencies without installing them. This can be helpful if you need to patch the code, or otherwise work with the non-binary version.
To download dependencies:
- Navigate to the ActiveState Platform’s Build Graph API
- You can run an API query directly from the interactive documentation to return links to the source code for our ActivePython project, for example:
3. Or run a query for your own project to return the source code for your specific packages and dependencies
The ActiveState Platform automatically builds all Python packages including linked C libraries from source code, and packages them for Windows, Linux and macOS. Because it does it all server-side, there’s no need to maintain local build environments.
Try it out by signing up for a free ActiveState Platform account.