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.
Is it possible to use pip to install a development version of a package but stable versions of all its dependencies?
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With