- 在新版本的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中使用,则有如下步骤:- 激活这个环境,在这个环境下安装ipython和jupyter
conda install ipython conda install jupyter
- 安装python kernel for Tensroflow或者PyTorch
ipython kernelspec install-self --user
- 在jupyter中添加conda的environment
python -m ipykernel install --user --name=envname
- 运行
Jupyter notebook
现在就可以在jupyter下面运行Tensorflow了,这样其实相当于在每个环境下都单独安装一个jupyter。