pythoncharm安装时出错误_python01:pycharm中安装包时所遇到的问题
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/pydot3
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 defdo_install(pkgs):2 try:3 importpip4 exceptImortError:5 error_no_pip()6 return pip.main(['install']+pkgs)7
8 defdo_uninstall(pkgs):9 try:10 importpip11 exceptImortError:12 error_no_pip()13 return pip.main(['uninstall']+pkgs)
View Code
將其修改為如下的代碼,然后進行保存即可:
1 defdo_install(pkgs):2 try:3 try:4 from pip._internal importmain5 exceptException:6 from pip importmain7 exceptImportError:8 error_no_pip()9 return main(['install']+pkgs)10
11 defdo_install(pkgs):12 try:13 try:14 from pip._internal importmain15 exceptException:16 from pip importmain17 exceptImportError:18 error_no_pip()19 return main(['uninstall']+pkgs)
View Code
總結
以上是生活随笔為你收集整理的pythoncharm安装时出错误_python01:pycharm中安装包时所遇到的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代码内容变成图片_网站只剩25行代码,真
- 下一篇: 代码雨代码源复制_小程序基于Parser