本文转载自:
Using TensorFlow through Jupyter (Python 3)
查找了许多解决方案均遇到问题,看到国外的一个解决方案,亲测完美解决。问题描述:
|
Apologies in advance, I think the issue is quite perplexing! I would like to use TensorFlow through Jupyter, with a Python3 kernel. However the command
As such, this question is really two-fold:
|
I had the same problem and solved it using the tutorial Using a virtualenv in an IPython notebook. I'll walk you through the steps I took.
I am using Anaconda, and I installed a new environment tensorflow using these instructions at tensorflow.org. After that, here is how I got tensorflow to work in a Jupyter notebook:
- Open Terminal
- Run
source activate tensorflow. You should now see(tensorflow)at the beginning of the prompt. -
Now that we are in the
tensorflowenvironment, we want to installipythonandjupyterin this environment: Runconda install ipythonand
conda install jupyter -
Now follow the instructions in the tutorial linked above. I'll repeat them here with a bit more information added. First run
ipython kernelspec install-self --userThe result for me was
Installed kernelspec python3 in /Users/charliebrummitt/Library/Jupyter/kernels/python3 -
Run the following:
mkdir -p ~/.ipython/kernelsThen run the following with
<kernel_name>replaced by a name of your choice (I chosetfkernel) and replace the first path (i.e.,~/.local/share/jupyter/kernels/pythonX) by the path generated in step 4:mv ~/.local/share/jupyter/kernels/pythonX ~/.ipython/kernels/<kernel_name> -
Now you'll see a new kernel if you open a Jupyter notebook and select
Kernel -> Change kernelfrom the menu. But the new kernel will have the same name as your previous kernel (for me it was calledPython 3). To give your new kernel a unique name, run in Terminalcd ~/.ipython/kernels/tfkernel/and then run
vim kernel.jsonto edit the filekernel.jsonso that you replace the value of"display_name"from the default (Python 3) to a new name (I chose to call it"tfkernel"). Save and exitvimby typing:wqwhile in command mode. - Open a new Jupyter notebook and type
import tensorflow as tf. If you didn't getImportErrorthen you are ready to go!
1547



被折叠的 条评论
为什么被折叠?



