Skip to main content

Install many versions of the same Python package with pip3 support.

Project description

Install many versions of the same Python package with pip3 support.

Getting started

Technical stack

  1. Python3 as an interpreter (programming language) to execute the code.
    • The following list of versions has been tested: 3.4, 3.5, 3.6, 3.7.


  1. Git as a version control system to work with current repository.
  2. pip as a package manager for Python.


Install using pip3:

$ pip3 install pip3-multiple-versions



Install multiple version of the same package with the following commands:

$ pip3-multiple-versions package install --name=requests --version=1.0.0
$ pip3-multiple-versions package install --name=requests --version=2.0.0

Use any of them:

import multiple_versions
multiple_versions.use(name='requests', version='1.0.0')

import requests

Or another one:

import multiple_versions
multiple_versions.use(name='requests', version='2.0.0')

import requests


To specify particular version, use the function named use from multiple_versions. You should define use function strictly before importing a target library:

import multiple_versions
multiple_versions.use(name='requests', version='2.0.0')

import requests


Distribution functionality (pkg_resources) is supported by default:

import multiple_versions
multiple_versions.use(name='requests', version='2.0.0')
import requests

import pkg_resources

Command line interface


Get the version of the package — pip3-multiple-versions --version:

$ pip3-multiple-versions --version
pip3-multiple-versions, version 0.0.1


Get the detailed description of all supported commands by the package — pip3-multiple-versions --help:

$ pip3-multiple-versions --help
Usage: pip3-multiple-versions [OPTIONS] COMMAND [ARGS]...

  Provide command-line interface for pip3 package's multiple versions.

  --version  Show the version and exit.
  --help     Show this message and exit.


Install a package — pip3-multiple-versions package install.

You can install as many version as you wish.

Arguments Type Required Restrictions Description
name String Yes - Name of a package.
version String Yes - Version of a package.
extra-index-url String No May contain authentication token. URL to extra Python Package Index. May be private one.
$ pip3-multiple-versions package install \
      --name=requests \
      --version=2.0.0 \

How it works


Any cache system from Python is not used and the library does not decrease speed of imports call.

Performance without multiple versions calling:

$ python3 -mtimeit -s "import requests"
50000000 loops, best of 5: 6.62 nsec per loop

Performance with multiple versions calling:

$ python3 -mtimeit -s "import multiple_versions; multiple_versions.use(name='requests', version='2.0.0'); import requests"
50000000 loops, best of 5: 6.56 nsec per loop


Unknown module folder

You may get the unknown module folder error illustrated below.

Traceback (most recent call last):
  File "", line 45, in <module>
    multiple_versions.use(name='requests', version='2.0.0')
  File "/Users/dmytro/projects/pip3-multiple-versions/multiple_versions/", line 140, in use
    imported_package_folder = _get_imported_package_folder(package_name=name, package_version=version)
  File "/Users/dmytro/projects/pip3-multiple-versions/multiple_versions/", line 112, in _get_imported_package_folder
    raise ModuleNotFoundError('Unknown module folder, package name is different from package folder name.')
ModuleNotFoundError: Unknown module folder, package name is different from package folder name.

It means, that the project name is different from package folder name. After installation this kind of projects, you have:

  1. Package folder you do imports from.

    import rest_framework
  2. Folder with meta data from such as version, description, etc.

    $ ls /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages

And the point is that multiple_versions.use under the hood requires data for both of them and the problem is these different names — djangorestframework (package name while installing) and rest_framework (package folder name).

The library easily parse package name, but not package folder name. The solution is to use import_name variable to be passed to multiple_versions.use.

import multiple_versions
multiple_versions.use(name='djangorestframework', version='3.11.0', import_name='rest_framework')

import rest_framework

You don't need import_name variable in case package name and package folder name is the same:

$ ls /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages


Clone the project

To start working with the project, clone it with the following commands.

$ git clone
$ cd dmytrostriletskyi/pip3-multiple-versions

Install requirements:

$ pip3 install -r requirements/project.txt -r requirements/tests.txt

Run tests

$ pytest tests


Build the project with the following command:

$ python3 sdist

Install it locally:

$ pip3 install dist/*.tar.gz

After the command above, you can execute the command line interface as if you installed it through pip3:

$ pip3-multiple-versions --version
pip3-multiple-versions, version 0.0.1

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pip3-multiple-versions, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size pip3-multiple-versions-0.2.1.tar.gz (9.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page