pycharm 安装第三方库

导航:

1、解决在库的搜索区提示(nohing to show)的办法

2、使用pycharm自带的包管理的功能,直接搜寻需要的第三方库安装

先发效果图:

问题:

打开pycharm的包管理搜索界面File-Settings-Project-Project interpreter,点击右侧显示框,绿色的+号,弹出Available Packages对话框,显示的可用库是空的(nothing to show)。

解决方案

进入C:\Users\Administrator\pip,如果没有pip文件夹,创建该文件。

创建pip.ini文件(txt直接改后缀)

配置pip.ini文件

[global]
respect-virtualenv = true
download-cache = d:/Python/pip/cache
log-file = d:/Python/pip/pip.log


[install]
timeout = 30
find-links =https://pypi.python.org/pypi
find-links =http://pypi.douban.com/simple/
find-links =http://mirrors.aliyun.com/pypi/simple/

find-links =https://pypi.mirrors.ustc.edu.cn/simple/

保存,关闭pip.ini文件,重启pycharm即可。

注意1:download-cache = d:/Python/pip/cache,这里是选择下载的缓存区,如果没有D盘,可以改成其他盘符。

注意2:timeout = 30,这里是连接超时时间,网络不好,可以设置稍微长些。

注意3:find-links =https://pypi.python.org/pypi,这些地址是大家推荐的下载库文件的地址。默认只有第一个哦。使用的时候可以尝试那个比较好用,ini文件使用;将行注释。

另外:

如果上述方法仍不能解决问题,提示类似以下错误

configparser.DuplicateOptionError: While reading from 'C:\\Users\\Administrator\\pip\\pip.ini' [line 10]: option 'find-links' in section 'install' already exists。可以使用extra-index-url配置多个镜像源。不再使用find-links

完整配置文件信息:

[global]
respect-virtualenv = true
download-cache = d:/Python/pip/cache
log-file = d:/Python/pip/pip.log

index-url=https://mirrors.aliyun.com/pypi/simple/
extra-index-url=
	https://pypi.tuna.tsinghua.edu.cn/simple/
	https://pypi.mirrors.ustc.edu.cn/simple/
	https://pypi.douban.com/simple/
[install]
timeout = 30
trusted-host=mirrors.aliyun.com

最后:

安装第三库建议通过pip或者pip3(python3推荐)安装。

示例:pip版本查询,库查询,升级,第三方库安装

Microsoft Windows [版本 10.0.17134.556]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>pip --version
pip 10.0.1 from c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)

C:\Users\Administrator>pip list
Package    Version
---------- -------
Gooey      1.0.2
Pillow     5.4.1
pip        10.0.1
psutil     5.4.8
setuptools 39.0.1
six        1.12.0
wxPython   4.0.4
You are using pip version 10.0.1, however version 20.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\Administrator>python -m pip install --upgrade pip
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simple/, https://pypi.mirrors.ustc.edu.cn/simple/, https://pypi.douban.com/simple/
Collecting pip
  Downloading https://mirrors.aliyun.com/pypi/packages/54/2e/df11ea7e23e7e761d484ed3740285a34e38548cf2bad2bed3dd5768ec8b9/pip-20.1-py2.py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 156kB/s
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-20.1

C:\Users\Administrator>pip --version
pip 20.1 from c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)

C:\Users\Administrator>pip3 --version
pip 20.1 from c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)

C:\Users\Administrator>pip3 install numpy
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simple/, https://pypi.mirrors.ustc.edu.cn/simple/, https://pypi.douban.com/simple/
Collecting numpy
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fd/e0/ad1bf8bd24e210548e4a65926ae54a66cfa285a4e88aac1b09fb479c8769/numpy-1.18.4-cp37-cp37m-win_amd64.whl (12.8 MB)
     |████████████████████████████████| 12.8 MB 100 kB/s
Installing collected packages: numpy
Successfully installed numpy-1.18.4

最后的最后:

python的第三方库的安装要注意安装路径。即要注意你安装的是装的是PATH还是venv。

所谓PATH就是你安装python的时候添加环境变量后,打开cmd直接pip,上面的示例即是。

但是pycharm往往会为你的工程(project)单独开辟新的库环境venv,当然你也可以选用系统的(不推荐)。这时候你就要注意你的venv了。

右击工程名-Open in terminal,进入pycharm创建的venv,使用pip3安装第三方库。我的理解,pip的配置信息是全局共用的。不需要额外配置。

Microsoft Windows [版本 10.0.17134.556]
(c) 2018 Microsoft Corporation。保留所有权利。

(venv) C:\Users\Administrator\PycharmProjects\untitled>pip3 install numpy
Collecting numpy
  Cache entry deserialization failed, entry ignored
  Cache entry deserialization failed, entry ignored
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fd/e0/ad1bf8bd24e210548e4a65926ae54a66cfa285a4e88aac1b09fb479c8769/numpy-1.18.4-cp37-cp37m-win_am
d64.whl (12.8MB)
    100% |████████████████████████████████| 12.8MB 101kB/s
Installing collected packages: numpy
Successfully installed numpy-1.18.4

(venv) C:\Users\Administrator\PycharmProjects\untitled>

  • 6
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值