该pip install命令默认安装 python 包的最新稳定版本(由PEP426指定的稳定版本)
--pre该命令的标志pip install告诉 pip 还考虑发布候选版本和 python 包的开发版本。但据我了解,pip install --pre packageA它将安装 的开发版本packageA,以及所有依赖项的开发版本。
是否可以使用 pip 安装包的开发版本,但安装其所有依赖项的稳定版本?
我尝试过的一件事是安装软件包的稳定版本(具有稳定的依赖项),然后重新安装不带依赖项的开发版本:
pip install packageA
pip install --pre --no-deps --upgrade --force-reinstall packageA
但问题是,如果开发版本packageA添加了新的依赖项,则不会安装。
我缺少什么吗?谢谢!
我编写了一个脚本来执行此操作(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()
Run Code Online (Sandbox Code Playgroud)
用法:
(venv)$ chmod +x pip_install_dev_and_stable_of_dependencies.py
(venv)$ ./pip_install_dev_and_stable_of_dependencies.py pandas
Run Code Online (Sandbox Code Playgroud)
该脚本执行以下操作:
#!/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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18480 次 |
| 最近记录: |