前言:
而今姐妹们对“ubuntu14装tensorflow”可能比较注重,大家都需要分析一些“ubuntu14装tensorflow”的相关文章。那么小编也在网摘上搜集了一些关于“ubuntu14装tensorflow””的相关资讯,希望大家能喜欢,我们快快来学习一下吧!我们先进入到tf1这个虚拟环境
(1)激活环境
source activate tf1
(2)查看有哪些库
conda list
source deactivate tf1
遇到问题:
ubuntu 遇到鼠标变为十字 无法点击的问题
原因:我在终端输入python,然后输入import tensorflow as tf,然后打开jupyter notebook。鼠标根本就动不了!
参考
遇到之后请Ctrl + Alt + F1切到命令行界面下,然后输入命令
ps -e | grep import
kill -9 21526(import的进程)
在ctrl + alt + F7切回gnome下,然后重新登录即可
之后问题解决。
(3)依次执行以下命令
1.(tf1) rookie@ubuntu:~$ conda install ipython
结果:
Downloading and Extracting Packages
。。。(省略)
ipython-6.1.0 | 1013 KB | ################################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
2.(tf1) rookie@ubuntu:~$ conda install jupyter
结果如下:
_libgcc_mutex-0.1 | 3 KB | ################################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
3.(tf1) rookie@ubuntu:~$ ipython kernelspec install-self --user
(tf1) rookie@ubuntu:~$ ipython kernelspec install-self --user
[TerminalIPythonApp] WARNING | Subcommand `ipython kernelspec` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter kernelspec` in the future
[InstallNativeKernelSpec] WARNING | `jupyter kernelspec install-self` is DEPRECATED as of 4.0. You probably want `ipython kernel install` to install the IPython kernelspec.
[InstallNativeKernelSpec] Installed kernelspec python3 in /home/rookie/.local/share/jupyter/kernels/python3
4.(tf1) rookie@ubuntu:~$ mv ~/.local/share/jupyter/kernels/python3 ~/.ipython/kernels/tfkernel
(tf1) rookie@ubuntu:~$ ipython kernelspec install-self --user
[TerminalIPythonApp] WARNING | Subcommand `ipython kernelspec` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter kernelspec` in the future
[InstallNativeKernelSpec] WARNING | `jupyter kernelspec install-self` is DEPRECATED as of 4.0. You probably want `ipython kernel install` to install the IPython kernelspec.
[InstallNativeKernelSpec] Installed kernelspec python3 in /home/rookie/.local/share/jupyter/kernels/python3
我这里得到的结果(1)是Installed kernelspec python3 in /home/rookie/.local/share/jupyter/kernels/python3
5.(tf1) rookie@ubuntu:~$ mkdir -p ~/.ipython/kernels
然后运行下边的命令,使用你选择的名字来代替<kernel_name>(我使用的tfkernel),并且刚才得到的结果(1)路径(例如,~/.local/share/jupyter/kernels/python3)来替换下方命令中的第一个路径。
mv ~/.local/share/jupyter/kernels/pythonX ~/.ipython/kernels/<kernel_name>
6.(tf1) rookie@ubuntu:~$ mv ~/.local/share/jupyter/kernels/python3 ~/.ipython/kernels/tfkernel
7.现在,打开Jupyter Notebook,选择Kernel -> Change kernel,你将看到一个新的kernel。但是,新的kernel与你之前的kernel拥有相同点名字,运行下边的命令,给你的新kernel起一个不同的名字。cd ~/.ipython/kernels/tfkernel/。接着,运行vim kernel.json来编辑kernel.json文件,将"display_name"中的默认值Python 3替换为你的新名字,然后保存,并退出。
(tf1) rookie@ubuntu:~$ cd ~/.ipython/kernels/tfkernel/
(tf1) rookie@ubuntu:~/.ipython/kernels/tfkernel$ vim kernel.json
(tf1) rookie@ubuntu:~/.ipython/kernels/tfkernel$ jupyter noteboo
8.打开一个新的Jupyter Notebook,输入一行import tensorflow as tf并运行,如果没有出现任何错误,那么就搞定了。
参考:
9.最后试验一下tensorflow是不是可以用
import tensorflow as tf
sess = tf.Session()
a = tf.constant(2)
b = tf.constant(3)
print(sess.run(a+b))
然后输出如下:
输出5,这样就成功啦!