码迷,mamicode.com
首页 > 编程语言 > 详细

学python在pycharm中安装包时所遇到的问题

时间:2018-09-02 02:07:21      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:from   cmd   tee   nbsp   exception   方便   gif   setting   spl   

Problem:  Module ‘pip‘ have no attribute the ‘main‘

之前在学习python爬虫的视频偶然看到一次讲师直接在pycharm中安装程序包,对于小白并且只知道在cmd下进行pip install  命令进行安装的我来说很是新奇。

并且,直接在pycharm中安装包好处有二:

01、在pycharm下编写python程序时,同时能在pycharm下安装所需要的包很是方便。

02、避免了电脑中安装多个python环境,使得在cmd下安装的包肯恶搞安装的不是现在说使用的环境。

 

刚开始我的操作:file>>setting>>python interpreter>>点击右上角的“+”进行安装新的包

技术分享图片

 

然后出现下述界面

技术分享图片

 

在不勾选Istall......的选项后在收索框里收索需要的包,然后进行Install Package。

然后问题来了,系统进行了如下报错:

技术分享图片
 1 Executed command:
 2     pip install --index-url http://mirrors.aliyun.com/pypi/simple/ pydot
 3 
 4 Error occurred:
 5     AttributeError: module pip has no attribute main
 6 
 7 Traceback (most recent call last):
 8     File ""
 9     File ""
10         return pip.main([install+pkgs])
11 AttributeError: module pip has no attribute main
View Code

 

在网上经历了各种的收索让我找到了解决的方法和错误的额原因,原来是因为我更新了pip这个python包(pip8.0-->pip18.0)

解决的方法

在安装pycharm的文件夹下找的helpers,然后在里面找到以恶叫packing_tools.py的文件,然后打开

找到如下代码:

技术分享图片
 1 def do_install(pkgs):
 2     try:
 3         import pip
 4     except ImortError:
 5         error_no_pip()
 6     return pip.main([install]+pkgs)
 7 
 8 def do_uninstall(pkgs):
 9     try:
10         import pip
11     except ImortError:
12         error_no_pip()
13     return pip.main([uninstall]+pkgs)
View Code

将其修改为如下的代码,然后进行保存即可:

技术分享图片
 1 def do_install(pkgs):
 2     try:   
 3         try:
 4             from pip._internal import main
 5         except Exception:
 6                 from pip import main
 7     except ImportError:
 8         error_no_pip()
 9     return main([install]+pkgs)
10 
11 def do_install(pkgs):
12     try:   
13         try:
14             from pip._internal import main
15         except Exception:
16                 from pip import main
17     except ImportError:
18         error_no_pip()
19     return main([uninstall]+pkgs)
View Code

学python在pycharm中安装包时所遇到的问题

标签:from   cmd   tee   nbsp   exception   方便   gif   setting   spl   

原文地址:https://www.cnblogs.com/Quasimodo2018-0815/p/Shawshank_pycharm2017_installpackage.html

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