码迷,mamicode.com
首页 > 其他好文 > 详细

Jupiter 页面环境下使用pip无法安装(AttributeError: module 'pip' has no attribute 'main')

时间:2019-09-16 20:00:55      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:dfa   col   mod   put   cep   code   NPU   parse   pkg   

  • 异常:
  • 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])

     

Jupiter 页面环境下使用pip无法安装(AttributeError: module 'pip' has no attribute 'main')

标签:dfa   col   mod   put   cep   code   NPU   parse   pkg   

原文地址:https://www.cnblogs.com/spaceapp/p/11528774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!