(Linux) Use conda to configure the env environment compatible with TensorFlow and PyTorch

            Table of contents

1. Create a new virtual environment:

2. Enter the environment and check the python version

3. Use conda to install TensorFlow2.2.0, first install tf!

4. Install torch1.10 version (make sure tf has no problem)

5. Check TensorFlow and pytorch import projects at the same time:


        Both Tensorflow and pytorch are common frameworks in the field of machine learning. When importing, there are requirements for the python version and compilation environment. If you want to use Tensorflow and pytorch at the same time, you need to install them in the same environment. After trying many times, I configured a compatible environment. In this environment, the TensorFlow model and the pytorch model can be deployed on a unified system architecture. Go directly to the steps:

1. Create a new virtual environment:

conda create --name [环境名称] python=3.6

Enter y to confirm the installation:

2. Enter the environment and check the python version

source activate newEnv

python --version / -V

3. Use conda to install TensorFlow2.2.0, first install tf!

conda install tensorflow==2.2.0

Check if TensorFlow installation was successful:

>>python

>>import tensorflow as tf

>>tf.__version__

4. Install torch1.10 version (make sure tf has no problem)

Don't use conda! use pip

#后安装的torch不用锁定版本,自动下载最新的1.10.x

 pip install torch

Check pytorch:

>>python

>>import torch

>>torch.__version__

5. Check TensorFlow and pytorch import projects at the same time:

vim test.py
import tensorflow as tf
import torch

print(tf.__version__)
print(torch.__version__)

Save and exit, execute test.py:

TensorFlow and pytorch are imported into one project at the same time.

Testing is not easy, if it helps you, give it a like and leave

Guess you like

Origin blog.csdn.net/qq_52213943/article/details/124617468