用户:
郝俊杰2009查看:0 回复:2 评论:0 创建时间:2022-01-23T16:07:40
【作品展示】

【作品介绍】
如题所说,他是BCM的官方源码经我修改而成。这个版本取消了Turtle的界面显示以适配Linux系统,使他能真正被运用在生产环境中。优点:
1.增加了四种下载源可供选择
2.增加了截止到2022/1/23各库的最新版本,即代码中newest_version,有部分库可能会在更新版本后与BCM的教程不兼容,如需安装使用请自行啃文档!
3.设计了新的Logo(标题图片)
BCM的CEO看到了主动联系我打劳动费[doge]
【作品源代码】
import platform
import sys
import os
import traceback
import time
common_version = {
'pyecharts': ['pyecharts==0.5.11', 'pyecharts-snapshot==0.1.8'],
'pyecharts-snapshot': ['pyecharts==0.5.11', 'pyecharts-snapshot==0.1.8'],
'pillow': ['pillow==6.1.0'],
'matplotlib': ['matplotlib==3.1.2'],
'pyside2': ['PySide2==5.12.3'],
'arcade': ['arcade==2.0.9'],
'dataclasses': ['dataclasses==0.7'],
'snownlp': ['snownlp==0.12.3'],
'nltk': ['nltk==3.4.5'],
'echarts-countries-pypkg': ['echarts-countries-pypkg==0.1.6'],
'jieba': ['jieba==0.39'],
'reportlab': ['reportlab==3.5.23'],
'wordcloud': ['wordcloud==1.5.0'],
'imageio': ['imageio==2.5.0'],
'pygame': ['pygame==1.9.6'],
'sympy': ['sympy==1.4'],
'vpython': ['vpython==7.5.2'],
'requests': ['requests==2.18.1'],
'psutil': ['psutil==5.6.7'],
'opencv-python': ['opencv-python==4.1.2'],
'beautifulsoup4': ['beautifulsoup4==4.8.1'],
'numpy': ['numpy==1.17.2'],
'pandas': ['pandas==0.25.1'],
'seaborn': ['seaborn==0.9.0'],
'scikit-learn': ['scikit-learn==0.22'],
'usefultools':['usefultools=1.1.3']
}
newest_version = {
'pyecharts': ['pyecharts==1.9.1', 'pyecharts-snapshot==0.2.0'],
'pyecharts-snapshot': ['pyecharts==1.9.1', 'pyecharts-snapshot==0.2.0'],
'pillow': ['pillow==9.0.0'],
'matplotlib': ['matplotlib==3.5.1'],
'pyside2': ['PySide2==5.15.2.1'],
'arcade': ['arcade==2.6.9'],
'dataclasses': ['dataclasses==0.8'],
'snownlp': ['snownlp==0.12.3'],
'nltk': ['nltk==3.6.7'],
'echarts-countries-pypkg': ['echarts-countries-pypkg==0.1.6'],
'jieba': ['jieba==0.42.1'],
'reportlab': ['reportlab==3.6.5'],
'wordcloud': ['wordcloud==1.8.1'],
'imageio': ['imageio==2.14.0'],
'pygame': ['pygame==2.1.2'],
'sympy': ['sympy==1.9'],
'vpython': ['vpython==7.6.3'],
'requests': ['requests==2.27.1'],
'psutil': ['psutil==5.9.0'],
'opencv-python': ['opencv-python==4.5.5.62'],
'beautifulsoup4': ['beautifulsoup4==4.10.0'],
'numpy': ['numpy==1.22.1'],
'pandas': ['pandas==1.4.0'],
'seaborn': ['seaborn==0.11.2'],
'scikit-learn': ['scikit-learn==1.0.2'],
'usefultools': ['usefultools=1.1.3']
}
print("Preparing program :", "▋"*2, end="")
py_path, py_exe = sys.executable.rsplit(os.sep, 1) # 获取python可执行环境路径,以及可执行环境名称
print("▋"*5,end="")
os.chdir(py_path) # 切换到对应的路径下,方便执行命令
print("▋"*10," OK",end="")
print()
print(\
" ____ _ _ _ _ __ __ \n\
/ ___| | __ _ ___ ___| | (_) |__ | \/ | __ _ _ __ __ _ __ _ ___ _ __ \n\
| | | |/ _` / __/ __| | | | '_ \| |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|\n\
| |___| | (_| \__ \__ \ |___| | |_) | | | | (_| | | | | (_| | (_| | __/ | \n\
\____|_|\__,_|___/___/_____|_|_.__/|_| |_|\__,_|_| |_|\__,_|\__, |\___|_| \n\
|___/ OpenSource Version")
pis_lis喵pypi/simple/","http://pypi.mirrors.ustc.edu.cn/simple/","http://pypi.douban.com/simple/","https://pypi.tuna.tsinghua.edu.cn/simple/ "]# pypi源,可以根据自己的喜好进行更改
pypi_source = pis_list[int(input("Please enter the source to use:\n1.Alibaba cloud source/阿里云源\n2.China University of science and technology/中科大源\n3.Watercress source/豆瓣源\n4.Tsinghua source/清华源\n>>>"))-1]
def get_LD(string_a, string_b):
diff_start = -1
diff_end = -1
len_a = len(string_a)
len_b = len(string_b)
short = min(len_a, len_b)
# 寻找开头和结尾的共同字符串,并记录位置
for i in range(0, short):
if string_a[i] != string_b[i]:
diff_start = i
break
if diff_start == -1:
return abs(len_b - len_a)
for i in range(0, short):
if string_a[len_a - i - 1] != string_b[len_b - i - 1]:
diff_end = i
break
if diff_end == -1:
return abs(len_b - len_a)
# L(A+C, B+C) = LD(A, B)
# 除去开头以及结尾相同的字符串,构建新的字符串
long_str = str(string_a[diff_start: len_a - diff_end] if len_a >=
len_b else string_b[diff_start: len_b - diff_end])
short_str = str(string_a[diff_start: len_a - diff_end] if len_a <
len_b else string_b[diff_start: len_b - diff_end])
long_len = len(long_str)
short_len = len(short_str)
# store保存迭代过程中每次计算的结果
store = range(0, long_len + 1)
for i in range(short_len):
temp = [i + 1] * (long_len + 1)
for j in range(long_len):
if long_str[j] == short_str[i]:
temp[j + 1] = store[j]
else:
# 注意这时各个位置数据的对应关系
temp[j + 1] = min(store[j], store[j + 1], temp[j]) + 1
store = temp
# 最右下角即为编辑距离
return store[-1]
def get_osname():
"""获取操作系统名称"""
plt = platform.platform()
if "Darwin" in plt:
return "Mac"
elif "Windows" in plt:
return "Windows"
else:
pass
def get_package():
# 获取输入的库名及版本
package_ = input("Please write down lib name and version(Warning:You should insert a ' ' bettwen lib name and version.)")
try:
# 判断是否输入版本号
if len(package_.split()) > 1:
package_name, package_version = package_.split()
else:
package_name, package_version = package_, "None"
return package_name, package_version
except:
print( "Please pree the libary name:")
time.sleep(3)
def handle(package_name, version):
"""卸载并安装"""
py_env = ".{}{}".format(os.sep, py_exe)
os.system("{} -m pip uninstall {} -y".format(py_env, package_name))
if version == "None":
print("Started to install {} {} version".format(package_name))
result = os.system("{} -m pip install {} -i {}".format(py_env,
package_name, pypi_source))
else:
print("Started to install {} {} version!".format(package_name, version))
result = os.system("{} -m pip install {}=={} -i {}".format(py_env,
package_name, version, pypi_source))
if result == 0:
if version == "None":
print("-------> {} Version install successful!Exit in 3 seconds...\n\n".format(package_name))
print("\n\n{} Version install successful!Exit in 3 seconds...\n\n".format(
package_name))
time.sleep(3)
else:
print("------ -> {} {} Version install successful!Exit in 3 seconds...\n\n".format(package_name, version))
time.sleep(3)
def manual(package_name, package_version, common_version, osname):
"""手动安装"""
global show_text
# 增加判断,Mac不能用终端方式安装pyside2
if package_name == "pyside2" and osname == "Mac":
print("For MacOS,please manually uninstall pyside2 and then install pyside2 5.12.3")
return
print("Uninstalling {} version in your computer,please wait for a while...".format(package_name))
temp = []
# 计算所有的相似度
for i in common_version:
temp.append([i, get_LD(package_name, i)])
temp = sorted(temp, reverse=False, key=lambda x: x[1])
# 如果相似度完全一致,则使用预置版本
print(temp)
if temp[0][1] == 0:
print("Force specified version")
for i in common_version[temp[0][0]]:
package_name, package_version = i.split("==")
handle(package_name, package_version)
else:
handle(package_name, package_version)
def preset(package_name, common_version, osname):
"""预置指定版本"""
global show_text
# 增加判断,Mac不能用终端方式安装pyside2
if package_name == "pyside2" and osname == "Mac":
print("For MacOS,please manually uninstall pyside2 and then install pyside2 5.12.3")
return
print("Your input libname or version is wrong,started to look for similar version...")
temp = []
# 计算所有的相似度
for i in common_version:
temp.append([i, get_LD(package_name, i)])
temp = sorted(temp, reverse=False, key=lambda x: x[1])
if temp[0][1] < 2:
# 安装这个
print("------ -> There is a similar version,start to reinstall...\n\n")
print("\nThere is:".format_map(common_version[temp[0][0]]))
for i in common_version[temp[0][0]]:
package_name, package_version = i.split("==")
manual(package_name, package_version, common_version, osname)
else:
print("The libname is wrong,please run program again and press correct libname.")
time.sleep(3)
if __name__ == "__main__":
try:
osname = get_osname()
print("Your computer OS is:{}".format(osname))
package_name, package_version = get_package()
try:
manual(package_name, package_version, common_version, osname)
except:
preset(package_name, common_version, osname)
except Exception as e:
print("There are some excpyion during your installing:")
traceback.print_exc()
print("Install failed,program will exit arter 3 seconds...")
time.sleep(3)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn