人工智能:pip、conda配置、使用命令,以及个人安装过的包汇总(pip/conda) ---- python3.7

人工智能:pip、conda配置、使用,以及个人安装过的包汇总(pip/conda) ---- python3.7

一、准备工作 —— conda和pip配置

工欲善其事必先利其器,先准备下载加速器:

1. conda加速:

如安装jieba包,打开cmd命令窗口:

法1:-c 镜像源 加速

运行以下命令:
清华源:$conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ jieba
或 阿里云 等:$conda install -c https://mirrors.aliyun.com/anaconda/pkgs/main/ jieba
注:国内知名的镜像源可参见我的另一篇博文:https://blog.csdn.net/Acegem/article/details/103153439

法2:永久设置

(1)清华源
使用清华提供的anaconda镜像
打开终端分别运行以下命令:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

(最后一行是设置显示下载通道地址的)
即可添加 Anaconda Python 免费仓库。
三行代码运行完,可以运行conda install jieba测试一下。
如果不想用,可以移除源,如:
$conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
(2)阿里源(推荐)
简单配置:

conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/free
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/main

正常上面简单配置即可!
详细配置:
打开终端,将下面命令一次性复制粘贴即可!

conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/free
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/main
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/msys2
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/r

conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/Paddle
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/auto
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/biobakery
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/bioconda
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/c4aarch64
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/caffe2
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/deepmodeling
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/dglteam
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/fastai
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/fermi
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/idaholab
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/intel
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/matsci
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/menpo
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/mordred-descriptor
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/msys2
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/numba
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/ohmeta
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/omnia
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/plotly
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/psi4
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/pytorch
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/pytorch-test
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/pytorch3d
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/pyviz
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/qiime2
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/rapidsai
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/rdkit
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/simpleitk
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/stackless
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/ursky

conda config --set show_channel_urls yes

配置文件在 ~/.condarc 中(没有则会自动创建)(类似 ~/.bashrc)。

2. pip加速:

法1:-i 镜像源 加速

清华源:$pip install jieba -i https://pypi.tuna.tsinghua.edu.cn/simple
或 阿里云等:$pip install jieba -i https://mirrors.aliyun.com/pypi/simple

法2:永久设置

同样可以将清华源设置成默认下载源
(1)清华源
方式一:命令导入

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn

方式二:修改配置文件
直接在user目录中创建一个pip目录,如:C:\Users\你的用户名\pip,新建文件pip.ini。内容:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]
trusted-host=pypi.tuna.tsinghua.edu.cn

(这里trusted-host=pypi.tuna.tsinghua.edu.cn 可写成 trusted-host=https://pypi.tuna.tsinghua.edu.cn
注:上面是针对windows。若Linux下,则修改 ~/.pip/pip.conf 或 ~/.config/pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
(2)阿里源(推荐)
方式一:命令导入

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com

配置文件在 ~/.config/pip/pip.conf 中(没有则会自动创建)。

方式二:修改配置文件
Windows下,直接在user目录中创建一个pip目录,如:C:\Users\你的用户名\pip,新建文件pip.ini。
Linux下,则修改 ~/.pip/pip.conf 或 ~/.config/pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)。
内容如下:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple

[install]
trusted-host=mirrors.aliyun.com

二、conda和pip使用命令

1. conda:

# 更新conda
conda update conda
conda update anaconda
conda update --all   # 自动检测并升级Anaconda管理器中所有可升级的库
conda update anaconda-navigator    //update最新版本的anaconda-navigator
conda update xxx   #更新xxx文件包

# 安装包
conda install xxx

# 虚拟环境
## 创建虚拟环境
conda create --name 自定义虚拟环境名 python=3.7
conda create --name 自定义虚拟环境名 python=3.7 numpy scipy
## 激活某个环境
conda activate 环境名
## 删除某个环境
conda remove --name 环境名 --all
## 复制某个环境
conda create --name 自定义新的虚拟环境名 --clone 旧的已存在的环境名
## 列出所有的环境
conda env list  # 或 conda info --envs

2. pip:

# 更新pip
python -m pip install -U pip
# 安装包
pip install xxx

# 检测包相互依赖问题
pip check
附:pip安装离线包

先到官方https://pypi.org/搜索下载包,如pdfplumber,如下图点击Download,
在这里插入图片描述若是 .whl或 .tar.gz类型的,即可直接 pip install xx.whlpip install xx.tar.gz

三、conda使用遇到的问题

1、Collecting package metadata (current_repodata.json): failed (此处省略数行…) An unexpected error has occurred. Conda has prepared the above report. Upload successful.

报错信息如下:
在这里插入图片描述在这里插入图片描述解决办法:
删除 .condarc 文件,其位置一般在 ~/.condarc ,不确定可通过命令 conda config --show-sources 来查看,如下:
在这里插入图片描述

四、pip使用遇到的问题

五、实例

个人安装过的一些包汇总(pip/conda)

  • 下面的一些实例是pip方式下载,装了Anaconda的最好用conda下载(将pip改成conda),可以判断包之间的兼容性。
  • 除了用命令安装,也可以打开Anaconda Navigator(以管理员打开),在Not installed里搜索安装。也很方便。比如:有的包安装时出现bug,可以试试此法!如:安装opencv即cv2 https://blog.csdn.net/Acegem/article/details/104096257
  • 镜像源可以加速下载,可依个人情况 将自己的pip默认下载方式永久改成 清华/豆瓣/阿里之类的镜像网站。
安装命令(安装方式)功能领域方向(类型)
mpl_financepip install https://github.com/matplotlib/mpl_finance/archive/master.zip获取财经网站的数据金融数据挖掘、数据分析
pandas_datareaderpip install pandas-datareader -i https://mirrors.aliyun.com/pypi/simple读取ss文件如股票数据金融股票K线数据分析安装该包的时候命令用的是pandas-datareader(横线),但代码中使用该包的时候import pandas_datareader as pdr用的是pandas_datareader(下划线)。参考我的博客:https://blog.csdn.net/Acegem/article/details/102973851
sleniumpip install selenium -i https://mirrors.aliyun.com/pypi/simple爬取js动态加载的网页数据时,调用浏览器driverPython爬虫需结合PhantomJS软件使用。
jiebapip install jieba -i https://mirrors.aliyun.com/pypi/simple分词,etcNLP自然语言处理
wordcloudpip install wordcloud -i https://mirrors.aliyun.com/pypi/simple生成词云图片NLP自然语言处理 + Python爬虫
fasttextpip install fasttext文本分类NLP自然语言处理开发者:Facebook
tensorflow需要create新的虚拟空间。不要直接pip install tensorflow 。具体安装过程下面讲解目前最流行的机器学习框架机器学习开发者:Google
keras最快方法pip install keras -i https://mirrors.aliyun.com/pypi/simple。官方命令是利用China包管理安装:conda install -c conda-forge keras 。然而有时会报错。若设置了默认清华镜像,则直接conda install keras即可!具体安装过程下面讲解调用TensorFlow的某些功能的API机器学习将TensorFlow的某些功能又封装了一下方便使用
sklearnpip install sklearn -i https://mirrors.aliyun.com/pypi/simple机器学习库机器学习新的tensorflow环境下,默认清华镜像conda命令安装不上时,可用此pip命令安装
cv2pip install --default-timeout=100 opencv-python视觉方向opencv库CV视觉opencv-python 即opencv,写代码import时被简记为cv2
capstonepip install capstone -i https://mirrors.aliyun.com/pypi/simple反汇编工具capstoneNLP等conda清华安装不上,在阿里找到了该包
MySQLdbconda install mysqlclientpython 连接mysql的驱动Pythonpython2或3都可以用。查询效率高,比纯python代码写的pymysql效率快
pymsqlpip install pymysqlpython 连接mysql的驱动Pythonpython语言写的包
py7zrpip install py7zr -i https://mirrors.aliyun.com/pypi/simple解压7z格式压缩包Python清华镜像安装不上
baidu-aippip install baidu-aip百度Aip人脸识别CV视觉使用方法,import aip 、from aip import AipFace等
gensimpip install gensim -i https://pypi.tuna.tsinghua.edu.cn/simpleNLP包NLP这个包,阿里云镜像安装慢。清华镜像还可以
fakerpip install Faker测试模拟数据包Python使用:from faker import Faker

例1. TensorFlow安装方法

前言

1)TensorFlow安装分为CPU和GPU,GPU功能强大处理快。CPU相当于一个大学教授能处理各种问题,而GPU相当于很多小学生能进行大量的基本算数运算,即能处理大量重复数据数据。GPU的概念是专为处理图像而提出的,它是集成在显卡上的芯片。对比,CPU是电脑的大脑进行计算的,而GPU是显卡的大脑。
2)好的电脑带GPU,如果自己的电脑带GPU,可以按照GPU版本的。如果不带GPU,那就用通用的CPU的。

CPU版本安装方法:

为了稳定,使用Anaconda Python3.6和TensorFlow1.8.0版本。

1. Python3.6版本的Anaconda:

到官网或清华镜像下载即可
如果目前的Anaconda是Python3.7,不必卸载重装,可以打开Anconada prompt或cmd直接用下面命令来降级到3.6
conda install python=3.6 等待提示(y/n?)输入y,大概10多分钟提示done降级完成。

注:
1.如下提示便是目前TensorFlow版本还不支持Python3.7版本,故要降级。
Could not find a version that satisfies the requirement tensorflow
2.Windows系统,如果电脑系统低于MicrosoftVC++ 2015,则安装一下vc_redist_x64.exe,官方下载地址:
https://www.microsoft.com/en-us/download/details.aspx?id=53587

2. TensorFlow1.8.0版本:

(1)在Anaconda prompt利用conda创建一个名为tensorflow(名字自定义)的Python3.6环境
conda create -n tensorflow python=3.6
(2)启动tensorflow环境:
conda activate tensorflowactivate tensorflow
注:当不使用tensorflow时,关闭tensorflow环境,命令为:conda deactivatedeactivate
(3)安装tensorflow:
因为前面设置过镜像加速,所以命令直接装即可。
cpu版本:conda install tensorflow==1.8.0pip install tensorflow==1.8.0
(4)测试TensorFlow,切换到Python下,输入以下代码:
在这里插入图片描述
注:如果显示没有导入TensorFlow module,则重启一下Anaconda Prompt窗口。后面安装Keras也是如此。
如此,则安装TensorFlow成功了。
(5)配置Pycharm:
新建工程-File-Settings–Project-Project Interpreter选择tensorflow下的Python解释器,例如我的位置是:
在这里插入图片描述再次运行代码测试下。

import tensorflow as tf
hello = tf.constant("Hello world!")
session = tf.Session()
print(session.run(hello))

小问题:

  • 代码运行 提示一:
    FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)])
    解决方法:
    numpy 1.17 版本过高,重新安装1.16版本
    pip install -U numpy==1.16.0
  • 代码运行 提示二:
    I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
    解决方法:
    这个是警告,不影响,意思是你的 CPU 支持AVX AVX2 (可以加速CPU计算)。忽略即可。如果不想显示,写代码时可以加上下面代码:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 只显示 warning 和 Error

注:

os.environ["TF_CPP_MIN_LOG_LEVEL"] = '1' # 默认,显示所有信息 
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2' # 只显示 warning 和 Error 
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '3' # 只显示 Error

例2. keras 安装方法

法1. (干货)默认清华conda加速安装:

如果你设置了默认清华conda加速,则直接在Anconada Prompt输入conda install keras即可!
测试:
Anaconda Prompt窗口输入python回车,进入python编辑器,再输入:import keras回车,搞定!
注:如果显示没有导入Kerasmodule,则重启一下Anaconda Prompt窗口即可!

法2.下面说一下常见的官方命令(注意此方式容易出现bug)

由于keras还没有被添加到conda库里,所以需要用China的conda-forge第三方包管理器来安装,即官方给出的安装命令是conda install -c conda-forge keras,这里-c是china的意思。但是,有时候安装会出现下面的错误:
conda install -c conda-forge keras Collecting package metadata (repodata.json): failed CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/conda-forge/noarch/repodata.json> Elapsed: -
这个因为安装下载国外软件,访问出现的类似https的ssl认证错误。网上给出的解决方法有:
C:/Users/你的电脑用户名/.condarc文件打开,原文件内容为:

ssl_verify: true
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true
  • 将里面- defaults一行删除,发现不行,(此法有时候管用!)
  • 再将 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/一行也删除,还是不行。
  • 将https改成http,也不行
  • 自己又尝试着,将ssl_verify: true改成ssl_verify: false或者将此行也删除,还是没解决!
    崩溃吧?
    所以国外软件,为了避免上面错误,最好用我上面说的法1:先设置成默认的清华conda加速,再下载。
对于https://aip.baidubce.com/rest/2.0/image-classify/v1/plant接口的传参,根据提供的引用内容,可以得出以下结论: 在使用该接口时,需要传入access_token作为必须参数。access_token是通过向授权服务地址https://aip.baidubce.com/oauth/2.0/token发送请求获取的。在请求URL中,需要带上以下参数:client_id和client_secret。此外,需要以POST方式发送请求。在POST请求的参数中,需要含一个名为image的参数,其值是要识别的图片文件。具体的实现代码可以参考提供的引用中的完整代码。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [php实现百度AI人脸分割,](https://blog.csdn.net/qq_33323469/article/details/108452491)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [百度al的人体检测接口调用](https://blog.csdn.net/qq_58744641/article/details/127463599)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值