在虚拟环境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. Jmeter(九)压力测试

    一般我们在做压力测试的时候,分单场景和混合场景,单场景也就是咱们压测单个接口的时候,多场景也就是有业务流程的情况下,比如说一个购物流程,那么这样的场景就是混合场景,就是有多个接口一起来做操作.1.单场 ...

  2. Spark2.0机器学习系列之4:Logistic回归及Binary分类(二分问题)结果评估

    参数设置 α: 梯度上升算法迭代时候权重更新公式中包含 α :  http://blog.csdn.net/lu597203933/article/details/38468303 为了更好理解 α和 ...

  3. linux使用nohup命令后台运行程序

    在linux服务器上搭建web服务器,用ssh客户端登陆后使用./startservice.sh脚本启动服务,但是当ssh断开连接后起的服务也会停掉. 这时可以用nohup ./startservic ...

  4. SQL Server 2008 添加登录账户并配置权限

    首先打开数据库,并以windows身份验证模式进入数据库. 然后在左侧的[对象资源管理器中]展开[安全性]节点,鼠标右键点击节点中的[登录名],在弹出的菜单中单击[新建登录名],弹出一个对话框. 1. ...

  5. Creating an generated Earth AVI with C++

    Creating an generated Earth AVI with C++        EarthGenerator.cpp /*    EarthGenerator.cpp An examp ...

  6. 360急速浏览器JS的调试

    1.代码中添加debugger关键字 2.360急速浏览器中选择工具--开发人员选项,如下图所示,在sources面板中可以看到正在运行的JS代码,F10可以单步函数执行,在鼠标放在变量上可以跟踪变量 ...

  7. [Windows Powershell]-学习笔记(3)

    Powershell 通过函数扩展别名 在powershell中设置别名的确方便快捷,但是在设置别名的过程中并设置参数的相关信息,尽管别名会自动识别参数,但是如何把经常使用的参数默认设定在别名里面呢? ...

  8. http协议中客户端8种请求方法

    http请求中的8种请求方法 1.opions   返回服务器针对特定资源所支持的HTML请求方法   或web服务器发送*测试服务器功能(允许客户端查看服务器性能) 2.Get   向特定资源发出请 ...

  9. IDEA创建Spring Boot的项目

    IDEA创建SpringBoot的项目非常的方便智能,可以实现零配置,只需要在创建的时候勾选你需要的功能,比如mybatis,mysql等等,它会帮你自动下载导入响应的jar,不用自己再去手动填写. ...

  10. java 加密解密

    https://www.cnblogs.com/kingsleylam/category/752546.html <java加密与解密艺术>代码可抄袭.