配置conda虚拟环境,在jupyter内核中使用

发布时间 2023-08-29 17:23:19作者: 七三七3

 1.创建虚拟环境并激活进入

conda create -n '名称' 

source activate '名称' 

environment.yml 

name: ‘名称’
channels:
  - defaults
dependencies:
  - python=3.6
  - numpy
  - pandas
  - scikit-learn
  - scipy
  - matplotlib
  - seaborn

 2.安装依赖 

conda env update -f environment.yml 

3.安装对应gpu版本tensorflow -参考:https://blog.csdn.net/weixin_41012765/article/details/124973351

 4. pip install tensorflow-gpu==2.4.0 

5.将虚拟环境对应jupyter内核

pip install ipykernel
python -m ipykernel install --user --name='内核名称'

6.测试tensorflow是否能使用GPU

import tensorflow as tf
print("TensorFlow version:", tf.__version__)
print("GPU available:", tf.config.list_physical_devices('GPU'))