第三方模块的下载与使用


一、第三方模块的下载与使用

第三方开发者,开发了第三方模块,把模块打包传到了pypi上,这就是第三方模块的来源,上面有很多大佬的模块,这也是python目前这么流行的原因。通常来说如果我们想使用第三方模块需要先根据名称查找,然后把这个模块下载下来,之后再次使用的时候就相当于导入内置模块一样直接导入就可以使用了。

下载第三方模块的方式一:pip工具

1、使用win+R打开cmd窗口(命令提示符窗口)

2、输入pip install 模块名称 -i 仓库地址

下载第三方模块的句式
pip install 模块名
下载第三方模块临时切换仓库
pip install 模块名 -i 仓库地址
下载第三方模块指定版本(不指定默认是最新版)
pip install 模块名==版本号 -i 仓库地址

注:

1.pip的文件在python解释器的scrips文件夹中,我们需要注意不能直接用pip命名,要在后面接上版本号,如果没有对应的文件,就跟之前创建python解释器多版本共存一样,复制pip文件,重命名成对应的pip+python解释器版本名称。

2.当我们第一次使用pip的时候会出现很多奇奇怪怪的问题,这时候我们需要看返回给我们的错误信息或提示,当这些信息中有放在引号中的指令的时候我们可以根据提示判断指令的作用(基本都是帮我们解决问题的),如果没有看得明白的信息就复制到百度搜索对应的解决策略。

3.下载出现timeout(超时)
这类情况可能是自己当前的网络环境不好。

4.下载速度慢
pip的默认下载地址都是国外的,我们只需要切换下载地址即可
关于切换下载地址的方式在上面已经说明(仓库地址可以参考下面的常用仓库地址)

部分错误解决案例:

这里是我装的时候遇到的一些问题。

第一次使用国内仓库地址会出现不被信任的提示

错误提示中会出现带引号的命令提示,我们在原本的命令之后接空格然后ctrl+v直接粘贴上去就可以接着安装了。也可以根据提示把仓库地址中的http改成https。
image

下载第三方模块的方式二:pycharm中下载

image

步骤一:

在pycharm中创建一个项目后点击file,选择setttings,接着在弹出的窗口中选择左边列表中的project:+项目名称,然后选择python Interperter,第一次打开这个界面的时候内容很少,当我们导入了很多的模块之后会一一在下面显示出来。

步骤二:

在右边显示模块的地方双击,会弹出模块的安装界面,搜索需要安装的模块,然后点击左下方的Install Package就是安装模块。Install Package右边的ManageRepositories就是设置下载的仓库地址,可以有多个也可以只留一个国内的地址。

注:这里需要注意,如果我们遇到错误同上面说的仓库地址未信任的情况,需要使用更改仓库地址中的http变成https,不能使用上面的代码临时允许安装了。

pip仓库地址

由于默认的pip仓库地址在国外,因此导致下载速度很慢,所以这时候就可以使用国内的pip仓库地址来下载第三方模块

常用pip仓库地址

清华大学 :https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科学技术大学 :http://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学:http://pypi.hustunique.com/
豆瓣源:http://pypi.douban.com/simple/
腾讯源:http://mirrors.cloud.tencent.com/pypi/simple
华为镜像源:https://repo.huaweicloud.com/repository/pypi/simple/

二、pip永久换源

由于默认的pip仓库地址在国外,因此导致下载速度很慢,所以这时候就可以使用国内的pip仓库地址来下载第三方模块,但是每次都要在命令后面指定仓库地址同样很麻烦,因此我们讲解一下怎么给pip永久换源

特殊情况说明

以下在公司中出现的情况

  • 公司不能上外网

    • 下载模块的方式一:虽然不能上外网,但是公司内部的某个网址处(如xx.whl ),已经把文件提交下好,供我们安装----》pip install 路径/xx.whl
    • 下载模块的方式二:已经有项目,模块装完了,想把这个项目所有的模块导出---》导入到别的项目(回头研究)
  • 公司可以上外网

    • 下载会很慢,因为默认的pip仓库在国外
    • 但是国内有些镜像站供我们使用:建议用阿里云

永久配置安装源

Windows

  • 1、文件管理器文件路径地址栏敲:回车,快速进入 C:\Users\电脑用户\AppData\Roaming 文件夹中

  • 2、新建 pip 文件夹并在文件夹中新建 pip.ini 配置文件(有些人的电脑中可能已经有了)

image

  • 3、新增 pip.ini 配置文件内容(见下方配置文件内容)

image

MacOS、Linux

"""
1、在用户根目录下 ~ 下创建 .pip 隐藏文件夹,如果已经有了可以跳过
	-- mkdir ~/.pip
2、进入 .pip 隐藏文件夹并创建 pip.conf 配置文件
	-- cd ~/.pip && touch pip.conf
3、启动 Finder(访达) 按 cmd+shift+g 来的进入,输入 ~/.pip 回车进入
4、新增 pip.conf 配置文件内容
"""

配置文件内容

"""
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
"""


'''
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
use-mirrors =true
mirrors =https://mirrors.aliyun.com/pypi/simple
trusted-host =mirrors.aliyun.com
'''
'配置本地镜像站为阿里云,以后只要pip install 就是去阿里云下载'

提交模块

#  自己写个模块,就叫你的名字  ,注册pypi账号,打包好 setup.py  传到 pypi上,以后别人
	pip install 你的模块 就可以下载
    如果有兴趣,可以把自己写的模块,传上去
            


posted @   致丶幻  阅读(258)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
  1. 1 So Far Away (Acoustic) Adam Christopher
  2. 2 雪 Distance Capper&罗言RollFlash
  3. 3 CollapsingWorld
  4. 4 Call You Tonight Johnta Austin
So Far Away (Acoustic) - Adam Christopher
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作曲 : David Guetta/Giorgio H Tuinfort/Jamie Scott/Martijn G Garritsen

Light ‘em up, light ‘em up

Tell me where you are, tell me where you are

The summer nights, the bright lights

And the shooting stars, they break my heart

I‘m calling you now, but you‘re not picking up

Your shadows so close if you are still in love

Then light a match, light a match

Baby, in the dark, show me where you are

Oh, love

How I miss you every single day when I see you on those streets

Oh, love

Tell me there‘s a river I can swim that will bring you back to me

‘Cause I don‘t know how to love someone else

I don‘t know how to forget your face

Oh, love

God, I miss you every single day and now you‘re so far away

It‘s breaking me, I‘m losing you

We were far from perfect, but we were worth it

Too many fights, and we cried, but never said we‘re sorry

Stop saying you love me

You‘re calling me now, but I can‘t pick up

Your shadow‘s too close, and I‘m still in love

The summer‘s over now, but somehow, it still breaks my heart

We could have had the stars, oh

Oh, love

How I miss you every single day when I see you on those streets

Oh, love

Tell me there‘s a river I can swim that will bring you back to me

‘Cause I don‘t know how to love someone else

I don‘t know how to forget your face

Oh, love

God, I miss you every single day and now you‘re so far away

Oh, love

How I miss you every single day when I see you on those streets

Oh, love

Tell me there‘s a river I can swim that will bring you back to me

‘Cause I don‘t know how to love someone else

I don‘t know how to forget your face

Oh, love

God, I miss you every single day when you‘re so far away

点击右上角即可分享
微信分享提示