Skip to content

青岛市青少年科技创新工厂

为明天点燃创新的火种

Menu
  • 首页
  • 人工智能
  • 信息科技
  • 社团活动
  • 学生竞赛
  • 选修课程
  • 他山之石
  • 随笔感悟
  • 关于
Menu

国内安装tensorflow, opencv库,避免安装不成功或下载太

Posted on 2020-09-27 by ganthur

1. 安装tensorflow官方方法与使用国内源方法

1.1 官方安装方法-适用翻墙

tensorflow安装方法比较常见,参考谷歌的官方教程,安装方法如下:

  • python2版本的安装

pip install --upgrade tensorflow      # for Python 2.*pip install --upgrade tensorflow-gpu  # for Python 2.* and GPU12
  • python3版本的安装

pip3 install --upgrade tensorflow     # for Python 3.*pip3 install --upgrade tensorflow-gpu # for Python 3.* and GPU12

1.2 国内源方法-无需翻墙

但是国内网络问题,网速非常慢,如果没有翻墙,可以按照下面方法快速安装

  • python2版本的快速安装

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow      # for Python 2.*pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow-gpu  # for Python 2.* and GPU12
  • python3版本的快速安装

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow     # for Python 3.*pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow-gpu # for Python 3.* and GPU12

以上是使用清华的镜像源地址,也可使用下面的镜像地址替换清华源地址:

阿里云 
http://mirrors.aliyun.com/pypi/simple/
中国科技大学 
https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) 
http://pypi.douban.com/simple/
清华大学 
https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 
http://pypi.mirrors.ustc.edu.cn/simple/123456789101112131415

2. opencv的pip/pip3安装方法

图像处理领域必不可少的当属opencv,但是使用opencv源码编译的方法比较麻烦,现在非官方的pip安装非常方便,下面给出针对python2和python3的环境,分别给出安装方法,并且针对国内下载速度过慢的问题,参照tensorflow的快速安装方法也可实现opencv的快速安装

2.1 opencv的pip/pip3普通安装-适用翻墙

需要说明的是opencv官方也曾给出pip的安装方法,但是也明确这种方法并非官方安装方法,仅供参考。不过,现在opencv的高阶函数API使用较少,一般是使用读图或视频,以及简单的预处理方法,所以pip安装基本足够我使用,并且pip安装方法也给出了额外的包安装方法,命令行安装方法如下:

# python2版本的基本包安装pip install opencv-python# python2版本的额外包安装pip install opencv-contrib-python# python3版本的基本包安装pip3 install opencv-python# python3版本的额外包安装pip3 install opencv-contrib-python12345678

2.2 opencv的pip/pip3快速安装-国内源

与tensorflow安装一样,如果没有翻墙的话,安装过程非常漫长,而且中间安装还有很大可能中断,因此可以套用tensorflow的国内源安装方法来安装opencv

# python2版本的基本包安装pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python# python2版本的额外包安装pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python# python3版本的基本包安装pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python# python3版本的额外包安装pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python123456789
  • 上面使用的是清华源,如果速度不行,可以参考1.2节的说明,使用其他国内镜像源地址。

3. 总结

其实只要使用pip/pip3安装的方法,都可以加上国内源地址进行安装,当然我没有测试过所有的安装包,大部分都可以的。如果你能翻墙,就跳过我这篇文章吧。
一般的pip/pip3安装可以参考如下格式

# for python2.xpip install -i https://pypi.tuna.tsinghua.edu.cn/simple XXXXXXX 
# for python3.xpip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple XXXXXXX 1234

发表回复 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Recent Posts

  • 第八届全国青少年无人机大赛山东省青岛市赛开始报名了!
  • 2023年崂山区第二实验小学科技节“喊你来报名”啦!
  • 青岛市第八届中小学创客系列活动创客比赛决赛通知
  • 第六届全国青少年人工智能创新挑战赛通知
  • 青岛市第八届创客大赛系列活动开始报名啦!

Recent Comments

您尚未收到任何评论。

Archives

  • 2024 年 4 月
  • 2023 年 5 月
  • 2023 年 4 月
  • 2022 年 11 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2022 年 6 月
  • 2022 年 5 月
  • 2022 年 4 月
  • 2021 年 10 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 5 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 1 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 7 月
  • 2020 年 3 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 4 月
  • 2019 年 3 月
  • 2019 年 2 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 9 月
  • 2018 年 8 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2017 年 9 月
  • 2017 年 6 月
  • 2017 年 5 月
  • 2017 年 4 月

Categories

  • 人工智能
  • 他山之石
  • 信息科技
  • 学生竞赛
  • 社团活动
  • 选修课程
  • 随笔感悟
©2025 青岛市青少年科技创新工厂 | Design: Newspaperly WordPress Theme