发布一个Python的程序,用来快速使用pip指令而不用敲代码
源代码
#coding = "utf-8"
import random,os
from time import sleep
mirrors = []
mirrors.append(u"https://pypi.tuna.tsinghua.edu.cn/simple/")
mirrors.append(u"https://mirrors.aliyun.com/pypi/simple/")
mirrors.append(u"https://pypi.mirrors.ustc.edu.cn/simple/")
mirrors.append(u"https://pypi.douban.com/simple/")
def ChoiceUrl():
return random.choice(mirrors)
def SystemStart(usrInput):
if usrInput == "0":
GetHelp()
elif usrInput == "1":
GetNowList()
elif usrInput == "2":
InstallMode()
elif usrInput == "3":
UpgradeMode()
elif usrInput == "4":
GetInfo()
elif usrInput == "5":
GetUpInfo()
elif usrInput == "6":
GetShow()
elif usrInput == "7":
GetSearch()
elif usrInput == "8":
DelMode()
elif usrInput == "9":
PipUpgrade()
else:
Pings()
def GetNowList():
os.system("python -m pip list>PackageList.txt")
print("\n创建成功")
def GetHelp():
os.system("python -m pip>Help.txt")
print("\n创建成功")
def GetInfo():
os.system("python -m pip freeze>Requirements.txt")
print("\n创建成功")
def GetUpInfo():
os.system("python -m pip list -o>UpdataList.txt")
print("\n创建成功")
def GetShow():
tmps = input("\n请输入模块名称:")
print()
os.system("python -m pip show " + tmps)
os.system("python -m pip show " + tmps +">WhlOutput.txt")
print("\n创建成功")
def GetSearch():
tmps = input("\n请输入关键词:")
print()
os.system("python -m pip search " + tmps)
os.system("python -m pip search " + tmps +">SearchOut.txt")
print("\n创建成功")
def DelMode():
tmps = input("\n请输入模块名称:")
os.system("python -m pip uninstall " + tmps)
print("\n删除成功")
def PipUpgrade():
usrflag = input("\n是(0)否(1)从镜像下载?")
if usrflag == "1":
flag = True
else:
flag = False
if flag == True:
os.system("python -m pip install --upgrade pip")
else:
usr_url = input("\n请输入镜像源(输入x使用程序内置镜像源):")
if "http" not in usr_url:
tmpUrl = ChoiceUrl()
print("\n当前镜像源" + tmpUrl)
print()
os.system("python -m pip install --upgrade -i "+ tmpUrl + " pip")
else:
print("\n当前镜像源" + usr_url)
print()
os.system("python -m pip install --upgrade -i "+ usr_url + " pip")
def InstallMode():
usrInput = input("\n模块名称:")
usrflag = input("\n是(0)否(1)从镜像下载?")
if usrflag == "1":
flag = True
else:
flag = False
if flag == True:
os.system("python -m pip install " + usrInput)
else:
usr_url = input("\n请输入镜像源(输入x使用程序内置镜像源):")
if "http" not in usr_url:
tmpUrl = ChoiceUrl()
print("\n当前镜像源" + tmpUrl)
print()
os.system("python -m pip install -i "+ tmpUrl + " " + usrInput)
else:
print("\n当前镜像源" + usr_url)
print()
os.system("python -m pip install -i "+ usr_url + " " + usrInput)
def UpgradeMode():
usrInput = input("\n模块名称:")
usrflag = input("\n是(0)否(1)从镜像下载?")
if usrflag == "1":
flag = True
else:
flag = False
if flag == True:
os.system("python -m pip install --upgrade " + usrInput)
else:
usr_url = input("\n请输入镜像源(输入x使用程序内置镜像源):")
if "http" not in usr_url:
tmpUrl = ChoiceUrl()
print("\n当前镜像源" + tmpUrl)
print()
os.system("python -m pip install --upgrade -i "+ tmpUrl + " " + usrInput)
else:
print("\n当前镜像源" + usr_url)
print()
os.system("python -m pip install --upgrade -i "+ usr_url + " " + usrInput)
def Pings():
usr_input = input("\n请输入域名:")
print()
usr_input = usr_input.replace("https://", "")
usr_input = usr_input.replace("http://", "")
os.system("ping " + usr_input)
def main():
os.system("@echo off")
os.system("title User_PipSoftwave")
os.system("color 0a")
os.system("cls")
print()
print("_____程序开始_____")
print()
print("__0 - 获取帮助,详见Help.txt")
print("__1 - 获取当前模块列表,详见PackageList.txt")
print("__2 - 直接安装模块")
print("__3 - 升级安装模块")
print("__4 - 查看已经安装的模块及版本信息,详见Requirements.txt")
print("__5 - 查询可升级的模块,详见UpdataList.txt")
print("__6 - 显示模块所在目录及信息,详见WhlOutput.txt")
print("__7 - 搜索模块,详见SearchOut.txt")
print("__8 - 删除模块")
print("__9 - 升级pip版本")
print("__x - 测试域名连通性")
print()
usr_choice = input("__选择支:")
SystemStart(usr_choice)
print()
print("_____程序结束_____")
print()
print("程序将在3秒后退出")
sleep(3)
main()
发布地址:lanzous.com/iau5phc
又及
运行界面:
就酱。。。