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!
–
–
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 ...
–
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
–
–
–
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.