zoukankan      html  css  js  c++  java
  • Jupiter 页面环境下使用pip无法安装(AttributeError: module 'pip' has no attribute 'main')

    • 异常:
    • AttributeError                            Traceback (most recent call last)
      <ipython-input-5-880e5dfa627c> in <module>
            1 def install(package):
            2     pip.main(["install", package])
      ----> 3 install("syslog_parse")
      
      <ipython-input-5-880e5dfa627c> in install(package)
            1 def install(package):
      ----> 2     pip.main(["install", package])
            3 install("syslog_parse")
      
      AttributeError: module 'pip' has no attribute 'main'
    • 代码:
    • def install(package):
          pip.main(["install", package])
      
      def uninstall(package):
          pip.main(["uninstall -y", package])
    • 解决:这是因为pip不同版本的情况:
    • def install(pkg):
          try:
              from pip._internal import main
          except Exception:
              from pip import main
          return main(["install", pkg])
      
      def uninstall(pkg):
          try:
              from pip._internal import main
          except Exception:
              from pip import main
          return main(["uninstall -y", pkg])
  • 相关阅读:
    服务器搭建Git
    BGP协议详解
    以太坊
    燃 * & *
    UML类图解析
    day8.文件操作
    python面试题汇总
    day5.字典
    day5.类型汇总
    day3,4总结程序
  • 原文地址:https://www.cnblogs.com/spaceapp/p/11528774.html
Copyright © 2011-2022 走看看