python pip之python模块自动化安装脚本
此脚本集成pip 所有功能,可在远程环境中执行,为你解决还在忧愁记住pip命令烦恼,此脚本预留了接口,可根据自己的实际环境自定义开发。
def pip_python_file(): win = (sys.platform == 'win32') linux = (sys.platform == 'linux2') if win: version = subprocess.Popen('pip -V', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() if len(version) > 0: print('********************安装环境信息********************') try: print('win_version:') print('\t' + u'版本:%s' % platform.platform()) except Exception: print() pip_version = subprocess.Popen('pip -V', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() python_version = subprocess.Popen('python -V', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() python_path = subprocess.Popen('where python', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() for python_version1 in python_version: print('python_version&path:') print('\t' + u'版本:%s' % str(python_version1, encoding="utf8").strip()) for python_path1 in python_path: print('\t' + u'路径:%s' % str(python_path1, encoding="utf8").strip()) for pip_version1 in pip_version: print('pip_version &path:') print('\t' + u'版本:%s' % str(pip_version1, encoding="utf8").strip()[:11]) print('\t' + u'路径:%s' % str(pip_version1, encoding="utf8").strip()[16:]) def menu(): print("****************Python pip安装工具 1.0****************") print('1.添加py模块') print('2.卸载py模块') print('3.查询更新py模块') print('4.查询单个py模块') print('5.查询所有py模块') print('6.pip使用方法') print('7.更新py模块') print('8.退出pip工具') print('9.查看本电脑环境变量') def input_card(): """ 1.添加py模块 :return: """ try: print('***************添加py模块***************') out = input('输入模块名称:') add_pip = "pip install" add_pip1 = subprocess.Popen(add_pip + '\t' + out, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() for i in add_pip1: print('\t' + str(i, encoding="utf8").strip()) except Exception as e: print("错误日志:" + str(e)) else: print() while True: niu = input("请继续您的选择是(y/q):").strip() if niu == 'y': return main() elif niu == 'q': exit('/n你已退出程序...') else: print("输入错误,请重新输入") return main() def del_name(): """ 2.卸载py模块 :param card_list: :return: """ try: print('*************** 卸载py模块***************') out = input('输入卸载模块名称:') add_pip = "pip uninstall" add_pip1 = subprocess.Popen(add_pip + '\t' + out, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() for i in add_pip1: print('\t' + str(i, encoding="utf8").strip()) except Exception as e: print("错误日志:" + str(e)) else: print() while True: niu = input("请继续您的选择是(y/q):").strip() if niu == 'y': return main() elif niu == 'q': exit('/n你已退出程序...') else: print("输入错误,请重新输入") return main() def del_card(): """ 7.更新py模块 :return: """ try: print('***************更新py模块***************') out = input('输入需要更新模块名:') add_pip = "pip install -U" add_pip1 = subprocess.Popen(add_pip + '\t' + out, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() for i in add_pip1: print('\t' + str(i, encoding="utf8").strip()) except Exception as e: print("错误日志:" + str(e)) else: print() while True: niu = input("请继续您的选择是(y/q):").strip() if niu == 'y': return main() elif niu == 'q': exit('/n你已退出程序...') else: print("输入错误,请重新输入") return main() def find_name(): """ 4.查询已安装模块 :param card_list: :return: """ t = input('输入查询模块名称:') import sys def dump(module): print("{0}模块安装路径".format(module)) if module in sys.builtin_module_names: # 查找内建模块是否存在 print("") else: module = __import__(module) # 非内建模块输出模块路径 print('(非内置模块已安装)安装路径:%s' % module.__file__) dump(t) while True: niu = input("请继续您的选择是(y/q):").strip() if niu == 'y': return main() elif niu == 'q': exit('/n你已退出程序...') else: print("输入错误,请重新输入") return main() def edit_name(): """ 3.需要升级模块 :param card_list: :return: """ update_pip = "pip list --outdated" update_pip1 = subprocess.Popen(update_pip, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() print(u'需要升级模块:') for i in update_pip1: print('\t' + str(i, encoding="utf8").strip()) while True: niu = input("请继续您的选择是(y/q):").strip() if niu == 'y': return main() elif niu == 'q': exit('/n你已退出程序...') else: print("输入错误,请重新输入") return main() def see_card(): """ 5.查看所有安装py模块 :param card_list: :return: """ cat_pip = "pip list" cat_pip1 = subprocess.Popen(cat_pip, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() print(u'你已安装的模块:') for i in cat_pip1: print('\t' + str(i, encoding="utf8").strip()) while True: niu = input("请继续您的选择是(y/q):").strip() if niu == 'y': return main() elif niu == 'q': exit('/n你已退出程序...') else: print("输入错误,请重新输入") return main() def pip_help(): """ 6.退出系统 :return: """ sys.exit('感谢使用本工具!!!') def sign_out(): """ 8.pip参数使用方法 :param card_list: :return: """ update_pip = "pip" update_pip1 = subprocess.Popen(update_pip, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.readlines() print(u'pip参数使用方法:') for i in update_pip1: print('\t' + str(i, encoding="utf8").strip()) while True: niu = input("请继续您的选择是(y/q):").strip() if niu == 'y': return main() elif niu == 'q': exit('/n你已退出程序...') else: print("输入错误,请重新输入") return main() def pip_path(): import os print(u'本地电脑环境变量:') print('\t' + 'PATH=' + os.environ['path']) def main(): menu() while True: mun = input('请输入功能序号:') if mun.isdigit(): mun = int(mun) else: print('请输入正确的功能序号!') if mun == 1: input_card() if mun == 2: del_name() if mun == 3: edit_name() if mun == 4: find_name() if mun == 5: see_card() if mun == 6: sign_out() break if mun == 7: del_card() if mun == 8: pip_help() if mun == 9: pip_path() if __name__ == '__main__': card_list = [] main() else: print('请先安装pip或配置环境变量') else: print('请先安装pip或配置环境变量') from bs4 import BeautifulSoup text = """ pip安装方法 """ soup = BeautifulSoup(text, 'html.parser') href = soup.find('a').get('href') print('pip安装方式:', href) if linux: pass else: print('请先安装pip或配置环境变量')
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Veeam实现MySQL的备份与还原(2)
此处说明Agent发起备份和还原的方法 从下面的地址下载对应Linux发行版的Agent 的yum源rpm文件 https://www.veeam.com/linux-backup-free-download.html 安装Veeam Agent [root@localhost~]#rpm-ivhveeam-release-el7-1.0.8-1.x86_64.rpm 准备中...#################################[100%] 正在升级/安装... 1:veeam-release-el7-1.0.8-1#################################[100%] [root@localhost~]#yumupdate 已加载插件:fastestmirror Loadingmirrorspeedsfromcachedhostfile *base:mirrors.aliyun.com *epel:mirrors.bfsu.edu.cn *extras:mirrors.aliyun.com *updates:mirrors.aliyun.co...
- 下一篇
从“PPT系统”走向现实:HarmonyOS,你真香了吗?
自2019年8月9日亮相伊始,华为HarmonyOS就受到了大量关注。在“被凝视”的发展历程中,质疑声始终不绝于耳。从最开始被戏谑为“PPT系统”到HarmonyOS 2发布会前夕甚嚣尘上的“安卓套壳”论,华为HarmonyOS终究还是来到了公众面前。 HarmonyOS之于我们这个时代究竟有什么意义?从“犹抱琵琶半遮面”到“千呼万唤始出来”,在不同观者的眼中对于HarmonyOS的印象又发生了哪些变化?如果说生态决定了一个操作系统能走多远,那我们又该如何参与HarmonyOS的未来? 是夜,远望智库合伙人谭茗洲、51CTO创始人熊平、华为官方授予的首批HarmonyOS系统课程开发讲师张荣超相聚在HarmonyOS社区直播间,就这些议题进行了探讨。在这些讨论中我们或可窥见HarmonyOS的昨天、今天与明天。 “新连接,新物种,新体验”:重构生活的可能 “当下我们所谓的‘智能生活’其实并不智能。”熊平首先提到了这样一个现象。 今天的我们似乎正在步入一个万物智能的时代。但在这个时代,对于“智能”的体感却并不怎么尽如人意:连接很复杂、控制很繁琐,体验很割裂。 “比如我买了一个冰箱,可能就...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- CentOS6,CentOS7官方镜像安装Oracle11G
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- 设置Eclipse缩进为4个空格,增强代码规范
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS8编译安装MySQL8.0.19