Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Background

The pip install command installs by default the newest stable version of a python package (stable versions as specified by PEP426 )

The flag --pre for the pip install command tells pip also consider release candidates and develompent versions of python packages. As far as I understand, though, pip install --pre packageA it will install a dev version of packageA , but also dev version of all its dependencies.

The question is:

Is it possible to use pip to install a development version of a package but stable versions of all its dependencies?

Attempted solutions

One thing I have tried is to install the stable version of the package (with stable dependencies), and then reinstall the dev version without dependencies: pip install packageA pip install --pre --no-deps --upgrade --force-reinstall packageA The problem, though, is that if the development version of packageA adds a new dependency, it will not be installed.

I am missing anything? Thanks!

Write a requirements.txt with pinned version numbers. But make sure the fit the conditions for the dependencies. Klaus D. May 16, 2018 at 8:23 But I do not want to pin versions of any package... I would like an automatizable way to install the newest version of packageA (stable or not, just as --pre would do) and the most recent stable versions of its dependencies. I'm not aware of how you can apply those constraints in requirements.txt without manually changing version numbers any time something is updated... mgab May 16, 2018 at 12:54

I write a script to do this( pip_install_dev_and_stable_of_dependencies.py ):

#!/usr/bin/env python
import os
import sys
def get_installed_packages():
    with os.popen('pip freeze') as f:
        ss = f.read().strip().split('\n')
    return set(i.split('=')[0].strip().lower() for i in ss)
def install_pre_with_its_dependencies_stable(package):
    already_installed_packages = get_installed_packages()
    os.system('pip install --pre ' + package)
    dependencies = ' '.join(
        p for p in get_installed_packages()
        if p not in already_installed_packages | set([package])
    os.system('pip uninstall -y ' + dependencies)
    os.system('pip install ' + dependencies)
def main():
    for p in sys.argv[1:]:
        install_pre_with_its_dependencies_stable(p)
if __name__ == '__main__':
    main()

Usage:

(venv)$ chmod +x pip_install_dev_and_stable_of_dependencies.py
(venv)$ ./pip_install_dev_and_stable_of_dependencies.py pandas

This script do the following things:

# Step 1. get the packages that already installed
pip freeze
# Step 2. install the dev version of packageA
pip install --pre packageA
# Step 3. pick out the dependencies (compare with Step 1)
pip freeze
# Step 4. uninstall all the dependencies of packageA
pip uninstall depend1 depend2 ...
# Step 5. install the stable version of dependencies
pip install depend1 depend2 ...
                But then if the dev version of packageA adds a new dependency, a development version of this dependency will be installed, am I right? For example, if packageA 0.1.1.dev1 adds numpy as a dependency, I want packageA 0.1.1.dev1 and the last stable version of numpy installed. I don't want a dev version of numpy, only of packageA...
– mgab
                May 16, 2018 at 12:42

This should do the trick.

  • First install your package without dependencies: pip install --pre --no-deps package
  • Then run again without --pre to install stable dependencies: pip install package
  • Does the second step install the dependencies of the development version of package (i.e. the one that first step installed)? Or does it only consider the dependencies of the last stable version? Unfortunately I cannot easily test it right now. – mgab Feb 2 at 10:25 But you need to specify the version of the package. Unless I'm missing something, you cannot use it to get the "most recent" development version of the package. – mgab Feb 2 at 10:21 @mgab, you can cat requirements.txt and pipe that using xargs into pip install --pre --no-deps {package_name} then pip install {package_name} – Anon957 Feb 2 at 23:34

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.