在虚拟环境tf中安装完tensorflow后,在虚拟环境tf打开的jupyter里发现只有一个kernel-python3,新建一个文件, import tensorflow as tf ,发现报错,没有tf这个模块。
    一开始还以为是tf的问题安装失败,后来才意识到是jupyter的问题。因为在虚拟环境tf中,虽然有jupyter(或者自己再安装pip install jupyter,他会提示说已存在),但这个jupyter还是原python环境中的jupyter。在虚拟环境tf中用命令 (tf) treamy ~ $ which jupyter 得/usr/local/bin/jupyter 再用 (tf) treamy ~ $ find ~/code/pydir/env -name "jupyter*" 发现虚拟环境中无jupyter故虚拟环境中的jupyter还是原python环境中的jupyter,kernel为python3,而我的原python3并没有安装tensorflow,所以报错了。
 
 
 

之前查网上按这个方法解决:(但无效)

(tf) treamy ~ $ 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 /Users/treamy/Library/Jupyter/kernels/python3
(tf) treamy ~ $ mkdir -p ~/.ipython/kernels
(tf) treamy ~ $ mv /Users/treamy/Library/Jupyter/kernels/python3 ~/.ipython/kernels/tfkernel
打开kernel.json文件,然后将display_name 后面的内容修改为tfkernel
(tf) treamy ~ $ vim ~/.ipython/kernels/tfkernel/kernel.json
但这样并无效果,因为创建的kernel相当于只是原kernel的复制品即python3,从上面那个json文件就可以看出来。
 
 

解决方案:

(tf) treamy ~ $ python3 -m ipykernel install --user --name tf --display-name "Python3(tf)"
# Installed kernelspec tf in /Users/treamy/Library/Jupyter/kernels/tf
cd 到 /Users/treamy/Library/Jupyter/kernels/tf
里面含 kernel.json  logo-32x32.png  logo-64x64.png 
查看这个json文件: cat kernel.json 
{
"argv": [
"/Users/treamy/code/pydir/env/tf/bin/python3",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python3(tf)",
"language": "python"
}
 
然后也不用移动它,就这样就OK了。刷新jupyter后就可以看到Python3(tf)这个选项。

详细官方文档:

在Jupyter notebook中使用特定虚拟环境中的python的kernel的更多相关文章

  1. Jupyter Notebook在多个虚拟环境配置与使用

    1 问题描述 使用Anaconda配置了包括Pytorch.Tensorflow等多个虚拟环境后,依然无法使用Jupyter Notebook选择不同的虚拟环境运行代码,问题如下图所示. 2 解决方法 ...

  2. jupyter notebook出现cannot import name 'create_prompt_application'问题(Died Kernel)

    应该是在安装其它python第三方库时更新了prompt-toolkit版本,降级到下面的版本即可: sudo pip install 'prompt-toolkit==1.0.15'

  3. 向jupyter notebook加入Anaconda3中已添加的虚拟环境kernel

    # jupyter notebook添加Anaconda虚拟环境的kernel #  开启虚拟环境 (base) C:\Users\jiangshan>activate tensorflow # ...

  4. linux中jupyter notebook中切换虚拟环境

    python -m ipykernel install --user --name 虚拟环境名称 --display-name "虚拟环境名称" 然后再打开jupyter note ...

  5. anaconda使用以及创建python3.7+pytorch1.0虚拟环境以及Jupyter notebook初级使用

    查看所有已安装的软件包$ conda list# packages in environment at S:\Users\jiangshan\Anaconda3:## Name Version Bui ...

  6. jupyter notebook添加Anaconda虚拟环境的python kernel

    之前在自己博客上写了一个如何通过自建配置文件,让jupyter notebook可以调用conda虚拟环境的python解释器. 今天介绍一种更加简单的方式,无需手动配置文件,利用ipykernel可 ...

  7. 【python】如何将ipdb的python解释器路径切换至虚拟环境中

    背景: 利用virtualenv构建一个python3.5的虚拟环境,在该虚拟环境中使用ipdb调试程序,结果报错找不到某一个模块. 程序的所有依赖模块都已经成功安装在虚拟环境中. 在虚拟环境中,te ...

  8. Jupyter Notebook 介绍 安装和使用技巧

    Jupyter Notebook介绍.安装及使用教程 原文链接:https://www.jianshu.com/p/91365f343585 目录一.什么是Jupyter Notebook? 1. 简 ...

  9. 基于Ubuntu+Python+Tensorflow+Jupyter notebook搭建深度学习环境

    基于Ubuntu+Python+Tensorflow+Jupyter notebook搭建深度学习环境 前言一.环境准备环境介绍软件下载VMware下安装UbuntuUbuntu下Anaconda的安 ...

随机推荐

  1. Android Studio 使用小技巧和快捷键

    Android Studio 使用小技巧和快捷键 Alt+回车 导入包,自己主动修正 Ctrl+N   查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L  格式化代码 Ctrl+Alt ...

  2. how to use greendao in android studio

    http://www.arjunsk.com/android/use-greendao-android-studio/ 1.新建一个java文件MainGenerator.java: import d ...

  3. HBase存储架构

    以下的介绍是基于Apache Hbase 0.94版本: 从HBase的架构图上可以看出,HBase中的存储包括HMaster.HRegionServer.HRegion.Store.MemStore ...

  4. C#生成电子印章源码

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  5. web.xml中配置spring配置(application.xml)文件

    application.xml 一般放到WEB-INF下,当然,你也可以将它放到任意问题,但需要web.xml指向到该文件 1.application.xml配置 <?xml version=& ...

  6. JMeter插件管理器

    JMeter插件管理器 来自官网:https://jmeter-plugins.org/wiki/PluginsManager/ JMeter插件管理器的想法很简单:不是手动安装各种插件,而是通过漂亮 ...

  7. 20145329 《Java程序设计》课程总结

    每周读书笔记链接汇总 •第一周读书笔记 http://www.cnblogs.com/jdy1453/p/5248592.html •第二周读书笔记 http://www.cnblogs.com/jd ...

  8. 20145231熊梓宏 《网络对抗》 实验9 Web安全基础实践

    20145231熊梓宏 <网络对抗> 实验9 Web安全基础实践 基础问题回答 1.SQL注入攻击原理,如何防御? •SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面 ...

  9. linux第四周

    一.知识点总结 (一)用户态.内核态和中断 1.内核态:在高的执行级别下,代码可以执行特权指令,访问任意的物理地址,这时的CPU就对应内核态 2.用户态:在低级别的指令状态下,代码 只能在级别允许的特 ...

  10. spring MVC Action里面怎么设置UTF-8编码集

    /* 编码转换,确保写数据库的时候不会出现乱码 */ public class CodingConvert{ public CodingConvert(){ // } public String to ...