百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

机器学习入门(3):Ubuntu16.04环境搭建玩TensorFlow | 100%实战

off999 2024-09-27 13:44 19 浏览 0 评论

上文讲到了成功安装anaconda和pycharm。没有找到合适的支持python3.7的tensorflow,故重新下载python3.6,方法和机器学习入门(1)类似。

主要内容:ubuntu16.04配置anaconda+tensorflow新手教程

前提:机器学习入门(2)已经安装好了anaconda

(1)直接在terminal中输入conda

rookie@ubuntu:~$ conda -V

conda 4.5.11

(2)输入指令conda info --envs

rookie@ubuntu:~$ conda info --envs

# conda environments:

#

base * /home/rookie/anaconda3

(3)创建虚拟环境

rookie@ubuntu:~$ conda create --name tf1 python=3.6

输入Y之后,创建成功输入如下:

Proceed ([y]/n)? y

Preparing transaction: done

Verifying transaction: done

Executing transaction: done

#

# To activate this environment, use

#

# $ conda activate tf1

#

# To deactivate an active environment, use

#

# $ conda deactivate

再次输入指令conda info --envs

rookie@ubuntu:~$ conda info --envs

# conda environments:

#

base * /home/rookie/anaconda3

tf1 /home/rookie/anaconda3/envs/tf1

(4)激活虚拟环境:(就是进入到这个虚拟环境里面)

rookie@ubuntu:~$ source activate tf1

(tf1) rookie@ubuntu:~$

PS:如果要退出:输入source deactivate tf

(5)在虚拟环境里安装tensorflow(cpu版本)

conda install tensorflow

参考https://blog.csdn.net/m0_37864814/article/details/82112029

The following packages will be downloaded:

package | build

---------------------------|-----------------

mkl-2017.0.3 | 0 129.5 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

The following NEW packages will be INSTALLED:

backports: 1.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

backports.weakref: 1.0rc1-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

blas: 1.0-mkl https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

bleach: 1.5.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

html5lib: 0.9999999-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

libprotobuf: 3.4.0-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

markdown: 2.6.9-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

mkl: 2017.0.3-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

numpy: 1.13.1-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

protobuf: 3.4.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

six: 1.10.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

tensorflow: 1.3.0-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

tensorflow-base: 1.3.0-py36h5293eaa_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

tensorflow-tensorboard: 0.1.5-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

werkzeug: 0.12.2-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

Proceed ([y]/n)? y

Downloading and Extracting Packages

mkl-2017.0.3 | 129.5 MB | ##################################### | 100%

Preparing transaction: done

Verifying transaction: done

Executing transaction: done

(6)测试tensorflow,安装成功

(tf1) rookie@ubuntu:~$ python

Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linuxType "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

>>>

(7)conda命令总结

参考https://blog.csdn.net/zongza/article/details/83039210

(8)执行命令conda install theano(theano是一个深度学习框架)

输出如下:

The following NEW packages will be INSTALLED:

libgfortran: 3.0.0-1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

libgpuarray: 0.6.9-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

mako: 1.0.6-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

markupsafe: 1.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

mkl-service: 1.1.2-py36_3 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

nose: 1.3.7-py36_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

pygpu: 0.6.9-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

scipy: 0.19.1-np113py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

theano: 0.9.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

Proceed ([y]/n)? y

Downloading and Extracting Packages

libgfortran-3.0.0 | 281 KB | ################################################################################################################################################################# | 100%

mako-1.0.6 | 115 KB | ################################################################################################################################################################# | 100%

nose-1.3.7 | 201 KB | ################################################################################################################################################################# | 100%

mkl-service-1.1.2 | 15 KB | ################################################################################################################################################################# | 100%

scipy-0.19.1 | 36.3 MB | ################################################################################################################################################################# | 100%

markupsafe-1.0 | 31 KB | ################################################################################################################################################################# | 100%

libgpuarray-0.6.9 | 211 KB | ################################################################################################################################################################# | 100%

pygpu-0.6.9 | 1.3 MB | ################################################################################################################################################################# | 100%

theano-0.9.0 | 4.0 MB | ################################################################################################################################################################# | 100%

Preparing transaction: done

Verifying transaction: done

Executing transaction: done

(9)安装keras

参考https://blog.csdn.net/qq_31802027/article/details/73655965

先输入git clone https://github.com/fchollet/keras.git

再cd keras/

其次python setup.py install

git clone https://github.com/fchollet/keras.git输出如下:

Downloading and Extracting Packages

libgfortran-3.0.0 | 281 KB | ################################################################################################################################################################# | 100%

mako-1.0.6 | 115 KB | ################################################################################################################################################################# | 100%

nose-1.3.7 | 201 KB | ################################################################################################################################################################# | 100%

mkl-service-1.1.2 | 15 KB | ################################################################################################################################################################# | 100%

scipy-0.19.1 | 36.3 MB | ################################################################################################################################################################# | 100%

markupsafe-1.0 | 31 KB | ################################################################################################################################################################# | 100%

libgpuarray-0.6.9 | 211 KB | ################################################################################################################################################################# | 100%

pygpu-0.6.9 | 1.3 MB | ################################################################################################################################################################# | 100%

theano-0.9.0 | 4.0 MB | ################################################################################################################################################################# | 100%

Preparing transaction: done

Verifying transaction: done

Executing transaction: done

(tf1) rookie@ubuntu:~$ keras

Traceback (most recent call last):

File "/usr/lib/command-not-found", line 27, in <module>

from CommandNotFound.util import crash_guard

ModuleNotFoundError: No module named 'CommandNotFound'

(tf1) rookie@ubuntu:~$ keras -V

Traceback (most recent call last):

File "/usr/lib/command-not-found", line 27, in <module>

from CommandNotFound.util import crash_guard

ModuleNotFoundError: No module named 'CommandNotFound'

(tf1) rookie@ubuntu:~$ git clone https://github.com/fchollet/keras.git

Cloning into 'keras'...

remote: Enumerating objects: 32203, done.

remote: Total 32203 (delta 0), reused 0 (delta 0), pack-reused 32203

Receiving objects: 100% (32203/32203), 12.66 MiB | 8.00 KiB/s, done.

Resolving deltas: 100% (23492/23492), done.

Checking connectivity... done.

python setup.py install

报错:

In file included from /tmp/easy_install-2giks2je/h5py-2.9.0/h5py/defs.c:642:0:

/tmp/easy_install-2giks2je/h5py-2.9.0/h5py/api_compat.h:27:18: fatal error: hdf5.h: No such file or directory

compilation terminated.

error: Setup script exited with error: command 'gcc' failed with exit status 1

明天再来看吧,晚安!


这期间遇到了很多问题,我还有两个问题没有解决,如果有朋友有类似的问题,可以交流;希望有前辈指教。

第一个就是我先安装了python3.7.4,然后再安装python3.6.4的时候,安装失败,报错。说空间不够,然后我百度看怎么解决,有个命令如下,发现有个/dev/sda1把磁盘占满了,然后一直没有解决。现在删掉了一些东西,占比只有80%,然后python3.6.4得以安装成功,但是这个问题花费了不少时间,还没有解决!!!

root@ubuntu:/dev# df -h

Filesystem Size Used Avail Use% Mounted on

udev 1.5G 0 1.5G 0% /dev

tmpfs 298M 4.9M 294M 2% /run

/dev/sda1 19G 18G 1.8M 100% /

tmpfs 1.5G 212K 1.5G 1% /dev/shm

tmpfs 5.0M 4.0K 5.0M 1% /run/lock

tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup

tmpfs 298M 44K 298M 1% /run/user/1000

第二个是我在终端输入python,python3时,它出现的版本为什么总是python3.7.0。

使用的命令如下

rm -rf /usr/bin/python3

sudo ln -s /home/rookie/Desktop/local/python3.6.4/bin/python3.6 /usr/bin/python3

原来我先下载的python3.7.4,链接的是python3.7.0。之后下载了python3.6.4,我想把python和python3改成链接python3.6.4。命令是如上 ,但是在root模式下,是python3.6.4,但是在普通用户模式下,仍然还是python3.7.0。所以这个是为什么,我也是没有解决!!!

相关推荐

python入门到脱坑经典案例—清空列表

在Python中,清空列表是一个基础但重要的操作。clear()方法是最直接的方式,但还有其他方法也可以实现相同效果。以下是详细说明:1.使用clear()方法(Python3.3+推荐)...

python中元组,列表,字典,集合删除项目方式的归纳

九三,君子终日乾乾,夕惕若,厉无咎。在使用python过程中会经常遇到这四种集合数据类型,今天就对这四种集合数据类型中删除项目的操作做个总结性的归纳。列表(List)是一种有序和可更改的集合。允许重复...

Linux 下海量文件删除方法效率对比,最慢的竟然是 rm

Linux下海量文件删除方法效率对比,本次参赛选手一共6位,分别是:rm、find、findwithdelete、rsync、Python、Perl.首先建立50万个文件$testfor...

数据结构与算法——链式存储(链表)的插入及删除,

持续分享嵌入式技术,操作系统,算法,c语言/python等,欢迎小友关注支持上篇文章我们讲述了链表的基本概念及一些查找遍历的方法,本篇我们主要将一下链表的插入删除操作,以及采用堆栈方式如何创建链表。链...

Python自动化:openpyxl写入数据,插入删除行列等基础操作

importopenpyxlwb=openpyxl.load_workbook("example1.xlsx")sh=wb['Sheet1']写入数据#...

在Linux下软件的安装与卸载(linux里的程序的安装与卸载命令)

通过apt安装/协助软件apt是AdvancedPackagingTool,是Linux下的一款安装包管理工具可以在终端中方便的安装/卸载/更新软件包命令使用格式:安装软件:sudoapt...

Python 批量卸载关联包 pip-autoremove

pip工具在安装扩展包的时候会自动安装依赖的关联包,但是卸载时只删除单个包,无法卸载关联的包。pip-autoremove就是为了解决卸载关联包的问题。安装方法通过下面的命令安装:pipinsta...

用Python在Word文档中插入和删除文本框

在当今自动化办公需求日益增长的背景下,通过编程手段动态管理Word文档中的文本框元素已成为提升工作效率的关键技术路径。文本框作为文档排版中灵活的内容容器,既能承载多模态信息(如文字、图像),又可实现独...

Python 从列表中删除值的多种实用方法详解

#Python从列表中删除值的多种实用方法详解在Python编程中,列表(List)是一种常用的数据结构,具有动态可变的特性。当我们需要从列表中删除元素时,根据不同的场景(如按值删除、按索引删除、...

Python 中的前缀删除操作全指南(python删除前导0)

1.字符串前缀删除1.1使用内置方法Python提供了几种内置方法来处理字符串前缀的删除:#1.使用removeprefix()方法(Python3.9+)text="...

每天学点Python知识:如何删除空白

在Python中,删除空白可以分为几种不同的情况,常见的是针对字符串或列表中空白字符的处理。一、删除字符串中的空白1.删除字符串两端的空白(空格、\t、\n等)使用.strip()方法:s...

Linux系统自带Python2&amp;yum的卸载及重装

写在前面事情的起因是我昨天在测试Linux安装Python3的shell脚本时,需要卸载Python3重新安装一遍。但是通过如下命令卸载python3时,少写了个3,不小心将系统自带的python2也...

如何使用Python将多个excel文件数据快速汇总?

在数据分析和处理的过程中,Excel文件是我们经常会遇到的数据格式之一。本文将通过一个具体的示例,展示如何使用Python和Pandas库来读取、合并和处理多个Excel文件的数据,并最终生成一个包含...

【第三弹】用Python实现Excel的vlookup功能

今天继续用pandas实现Excel的vlookup功能,假设我们的2个表长成这样:我们希望把Sheet2的部门匹在Sheet1的最后一列。话不多说,先上代码:importpandasaspd...

python中pandas读取excel单列及连续多列数据

案例:想获取test.xls中C列、H列以后(当H列后列数未知时)的所有数据。importpandasaspdfile_name=r'D:\test.xls'#表格绝对...

取消回复欢迎 发表评论: