首页 > 编程语言 >【基础知识】为python部署第三方库(设备可联网版)

【基础知识】为python部署第三方库(设备可联网版)

时间:2022-10-28 21:48:03浏览次数:72  
标签:cn mirrors python anaconda 基础知识 conda https edu 第三方

大家好哇!继上次我们说完怎么安装python之后,这一次给大家分享一下怎么根据自己的需求来部署所需要的库,如numpy库等。

01

安装第三方库

众所周知,在python下面有很多库,可以用来实现各种各样的功能。由于每个人的需求都不一样,所以你在刚装好python时,系统仅帮你内置了其中一些最基本的库,要想实现画图呀、机器学习呀等功能,就需要自己另外安装一些库了。我们首先来介绍当我们的电脑或者服务器可以联网时,如何来进行安装?

这种情况是最简单的了。我们可以通过以下两个代码完成所需库的安装。conda和pip两个命令具有同样的作用,都可以用来安装库,但我个人更加推荐优先使用conda命令进行安装,如果某个包conda没有,再尝试使用pip命令进行安装,具体原因后面有空会另开一篇进行对比。实际上,如果我们不是专门做计算机方面工作的、不依赖很多底层库的库的话,conda基本上能满足我们的需求。

conda install pkg_name   #如conda install xarray
pip install pkg_name   #如pip install xarray
conda install pkg_name=xx  #如conda install xarray=0.20.1,可以指定安装库的版本号

02

逐个添加国内源

由于Anaconda的服务器在国外,所以conda命令相比pip命令来说下载速度会稍慢些。但我们可以通过添加国内镜像源的方式,在下载时指定国内源来提高下载速度。除此以外,国内源也能在一定程度上解决我们上面提到的安装包找不到的现象。在文末会给大家提供一些国内源,这里以清华源为例,给大家介绍一下如何添加国内源并进行指定等基本操作(向左滑动屏幕可以查看全部代码)。

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/  #添加清华源
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ proplot  #指定清华源进行下载,其中-c可以换成--channels
conda config --set show_channel_urls yes #设置搜索时显示通道地址
conda config --show-sources  # 查看下载源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/#删除清华源

03

批量添加国内源

此外,当我们想批量添加国内源时,也可以直接通过修改.condarc文件批量进行国内源的添加。这里仍以清华源为例:

conda config --set show_channel_urls yes  #生成.condarc文件
vim .condarc  #编辑.condarc文件,将下面代码复制进去后,用wq!保存修改,即可完成修改。
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

END

推荐的国内源:

  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2

清华源参考文档:

https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

往期精彩

【写在前篇】How to study Python——新手必看

【科研利器】Screen命令让程序永不掉线

【基础知识】Anaconda的安装

标签:cn,mirrors,python,anaconda,基础知识,conda,https,edu,第三方
From: https://www.cnblogs.com/zxqxr/p/16837587.html

相关文章

  • 【python】装饰器参数
    装饰器是AOP编程思想,给主体函数增加功能,又不让代码入侵到主体函数中,实现高内聚,低耦合。参数有两种,一种是功能函数带参数、另外一种是装饰器函数带参数,如果装饰功能部分代......
  • 【基础知识】为python部署第三方库(设备不可联网版)
    “大家好哇!继上次我们说完怎么安装python之后,这一次给大家分享一下怎么根据自己的需求来部署所需要的库,如numpy库等。”01安装第三方库我们在前面已经说过了当设备可以......
  • Python time.strptime()方法
    time.strptime()函数根据指定的格式把一个时间字符串解析为时间元组。importtimefromdatetimeimportdatetimeresult=time.strptime("1.2022-12-1010:45:00","......
  • 10道Python面试题
    1、Python里面如何拷贝一个对象?(赋值,浅拷贝,深拷贝的区别)答:赋值(=),就是创建了对象的一个新的引用,修改其中任意一个变量都会影响到另一个。浅拷贝:创建一个新的对象,但它包......
  • python时间戳转换
    importtime,datetime#当前时间转时间戳maintenance_time=(datetime.datetime.now()+datetime.timedelta()).strftime("%Y-%m-%d%H:%M:%S")struct_time=time.......
  • 第三方模块,hashlib,subprocess,logging
    hashlib加密模块#1.加密就是把明文数据变为密文#2.加密的目的是为了保证数据的安全#3.加密后的数据是一串没有规律的字符串#4.加密后的密文越长说明使用的加密算......
  • python 爬虫 ----- xpath
    xpath是在XML文档中搜索内容的一门语言html是xml的一个子集 xml代码示例"""<book><id>1</id><name>野花遍地香</name><price>1.23</price><......
  • Python-一个傻瓜可视化的神库Streamlit
    1.如何安装?和安装其他包一样,安装streamlit非常简单,一条命令即可➜pipinstallstreamlit考虑到streamlit会附带安装比较多的工具依赖包,为了不污染当前的主要环境,......
  • Python RabbitMQ pika的安装及direct路由模式的使用
    RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件,RabbitMQ服务器是用Erlang语言编写的,而集群和故障转移是构建在开放电信平台框架上的。所有主要的编程语言均有......
  • PYTHON JSON EXCEL
    #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#pipinstallpandas#pipinstallopenpyxl#importjsonimporttimeimportpandasimpor......