Tensorflow和jupyter使用问题

  • 在新版本的tensorflow中,会话函数Session()已经抛弃,要这样使用
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
a = tf.constant([1, 2], name="a")
b = tf.constant([3, 4], name="b")
result = a + b
sess = tf.compat.v1.Session()
sess.run(result)
  • coanda activate env_name报错,比如有时候安装了Git可能会报错这个
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'

这时候可以在Git下面使用下面这个命令解决

source activate
  • conda创建一个虚拟环境
conda create -n myenv python=3.6
  • Jupyter导入conda创建的环境
conda install -c anaconda ipykernel
```
python -m ipykernel install --user --name=envname
```

* To remove an environment, in your terminal window or an Anaconda Prompt, run:

conda env remove --name myenv

get the paths of all your kernels

jupyter kernelspec list

uninstall your unwanted-kernel,删除jupyter中的虚拟环境

jupyter kernelspec uninstall unwanted-kernel
  • 在jupyter中使用Tensorflow和PyTorch
    比如通过conda建立了一个Tensorflow的环境,如果要在jupyter中使用,则有如下步骤:

    1. 激活这个环境,在这个环境下安装ipython和jupyter
    conda install ipython 
    conda install jupyter
    
    1. 安装python kernel for Tensroflow或者PyTorch
    ipython kernelspec install-self --user  
    
    1. 在jupyter中添加conda的environment
    python -m ipykernel install --user --name=envname
    
    1. 运行
    Jupyter notebook 
    

    现在就可以在jupyter下面运行Tensorflow了,这样其实相当于在每个环境下都单独安装一个jupyter。

Avatar photo

About Blackford

这是个最好的时代,这是个最坏的时代,这是个充满希望的春天,这是个令人绝望的冬天,我们前面什么都有,我们前面什么都没有。梦想,让我们一次次的走远,又一次次的回头,一个关于人生的梦想还在不断奔跑,带着喜悦和疼痛,不过一切才刚刚开始,并且直到今天也远远没有结束
This entry was posted in AI. Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用*标注