当前位置: 首页 > news >正文

天津公司网站怎样制作网站后台模板

天津公司网站怎样制作,网站后台模板,河南自助建站seo公司,锦州做网站公司转载请注明出处#xff1a;小锋学长生活大爆炸[xfxuezhang.cn] 背景说明 对于新python环境#xff0c;要运行某个脚本#xff0c;可能需要安装很多库#xff0c;一般可以通过提供的requirements.txt来自动安装。但如果没有这个txt#xff0c;那就得手动一个一个安装#… 转载请注明出处小锋学长生活大爆炸[xfxuezhang.cn] 背景说明 对于新python环境要运行某个脚本可能需要安装很多库一般可以通过提供的requirements.txt来自动安装。但如果没有这个txt那就得手动一个一个安装非常的麻烦。 通过捕捉ImportError错误实际上可以从错误消息中提取缺失的模块名称而一旦确定了缺失的模块名称就可以使用 pip 自动安装它们了。 参考脚本 autoDependencyInstaller.py import argparse import subprocess import sys import redef install_module(module_name, python_executable):try:subprocess.check_call([python_executable, -m, pip, install, module_name])return Trueexcept subprocess.CalledProcessError:return Falsedef extract_imports(file_name):with open(file_name, r) as file:file_content file.read()imports re.findall(r^(?:from\s(\S)|import\s(\S))(?:\s|$), file_content, re.MULTILINE)top_level_modules {imp[0].split(.)[0] if imp[0] else imp[1].split(.)[0] for imp in imports}return list(top_level_modules)def check_module(module, python_executable):try:subprocess.check_call([python_executable, -c, fimport {module}])return Trueexcept subprocess.CalledProcessError:return Falsedef check_and_install_modules(modules, python_executable):for module in modules:if check_module(module, python_executable):print(f模块 {module} 已存在.)else:print(f尝试安装模块: {module})if not install_module(module, python_executable):correct_name input(f安装 {module} 失败。请输入正确的包名或按 Enter 跳过: ).strip()if correct_name:install_module(correct_name, python_executable)def main():parser argparse.ArgumentParser(description自动检测和安装 Python 脚本依赖.)parser.add_argument(script, help要检查依赖的 Python 脚本文件名)parser.add_argument(-p, --python-path, helpPython 解释器的路径可选, defaultsys.executable)args parser.parse_args()modules_to_check extract_imports(args.script)check_and_install_modules(modules_to_check, args.python_path)if __name__ __main__:main()参数第一项表示目标py文件。第二项表示要用道德python路径如果没有给则默认使用当前环境下的python 这个脚本只提取 Python 脚本中的 import 和 from ... import 语句然后在当前脚本中尝试导入它们。这样做的好处是不会执行原始脚本的其他部分只会检查依赖项是否存在。如果遇到任何 ImportError则可以安装相应的缺失模块。这种方法更加安全和高效因为它避免了不必要的脚本执行。 使用示例 python autoDependencyInstaller.py 目标py文件 目标python路径 比如 python autoDependencyInstaller.py young_http.py python autoDependencyInstaller.py young_http.py -p /home/sxf/miniconda3/envs/py39/bin/python 进阶使用 把这个脚本打包 pip install pyinstaller pyinstaller -F -w autoDependencyInstaller.py 生成的二进制文件在dist目录下所以就可以非常方便的使用了 ./dist/autoDependencyInstaller young_http.py -p /home/sxf/miniconda3/envs/py39/bin/python 注意对于打包的文件必须提供-p不然用的是二进制文件自己的环境会出问题。 或者可以直接这样用$(which python) ./dist/autoDependencyInstaller young_http.py -p $(which python) 更进阶使用 把这个文件放到系统目录下就不用每次都找了 sudo mv dist/autoDependencyInstaller /usr/sbin/ 以后就可以直接用了 autoDependencyInstaller young_http.py -p /home/sxf/miniconda3/envs/py39/bin/python
http://www.eeditor.cn/news/121887/

相关文章:

  • 合同下载网站中国建筑网信息查询
  • 建站工具的优点鞍山58同城
  • 特价网站建设官网苏州微信网站
  • 织梦体育网站模板国际知名设计公司
  • 江阴早晨网站建设什么是seo推广
  • 专门做棋牌广告广告的网站漳州市网站建设公司
  • 中交建设集团 网站下载京东网上购物
  • 电子商务网站建设报价表企业为什么校招
  • 快速提高网站权重提升网站栏目设计优化方案
  • 北京品牌建设网站公司dw做网站的导航栏怎么做
  • 百度移动网站检测大连网站建设要多少钱
  • 个人网站模板源码下载化妆品推广策划方案
  • 网站建设有限公司自己接单的平台
  • 怎么打造自己的网站网站建设行情
  • 网站建设服务亿企网络软件开发从入门到精通
  • 做推广网站那里好河池市住房与城市建设部网站
  • 网站建设摊销搭建网站架构是什么意思
  • 网站建设403网站制作手机模板
  • 湛江网站建设详细策划国家建设厅网站
  • 做酒店需要怎么上网站广州市旅游商务职业学校
  • 开放大学门户网站建设wordpress建站模版
  • 营销型 网站 品牌电脑 手机网站二合一源码
  • 儿童早教网站模板深圳公共资源交易平台
  • 上海做网站比较好的公司最好的免费信息发布平台
  • 哪家做企业网站职业生涯规划大赛的意义
  • WordPress中文改英文版seo计费系统
  • 怎么自建设部网站查询公司资质网站运行与维护
  • 网站推广工作总结网站建设及发布的流程
  • 类似电影天堂的网站 怎么做佛山市网站建设分站多少钱
  • 网站icp网站备案信息更改