The bug encountered when installing tensorflow under Linux+pycharm

table of Contents

Error 1:

the reason:

Solution:

Error 2:

the reason:

Solution:

Reinstall tensorflow in the new virtual environment

Reconfigure based on the existing virtual environment

Set the operating environment (interpreter) for the current code


Error 1:

When running code with pycharm, the following errors may occur:

  • ImportError: cannot import name 'abs'

the reason:

protobufAnd tensorflowclashes

Solution:

The first step : delete all tensorflow modules

pip uninstall tensorflow

Step 2 : Delete protobuf

pip uninstall protobuf

Step 3 : Reinstall tensorflow

pip install tensorflow==1.9.0

Error 2:

  • illegal instruction (core dumped) core dump problem

the reason:

This is because tensorflow is not installed well under Linux, and the version is wrong.

Solution:

Reinstall tensorflow in the new virtual environment

(How to check whether the virtual environment has tensorflow, please see " 2.  Reconfigure on the basis of the existing virtual environment" section )

Step 1 : Install a new virtual environment in the conda environment

conda create -n tensorflow python=3.6.5

Step 2 : Activate the virtual environment

source activate tensorflow #激活环境

This line of code is to activate the tensorflow environment, and the name after activate can be defined by yourself. Join the definition as tensorflow1, after activation, there will be the words tensorflow environment at the beginning:

Step 3 : Install tensorflow

conda install tensorflow==1.9.0

Among them, the python version of the first line and the tensorflow version of the third line must correspond. It is recommended not to use python after 3.7, which is more troublesome. After tensorflow2.0, many things have changed. Python3.6 is compatible with tensorflow1.9, which is effective for pro-test. (If python is 3.7, tensorflow can use 2.2.0, the Internet says it can)

 

Reconfigure based on the existing virtual environment

Step 1 : Check the existing configuration in the virtual environment:

conda env list

The virtual environments we configure are all in the env package under the conda environment. It can also be found in the file

This is the result after I run it. As you can see, my virtual environment includes three environments, one is base, one is tensorflow, and the other is tensorflow1.

Step 2 : Take tensorflow as an example, reconfigure tensorflow in this existing environment.

carried out:

source activate tensorflow #激活环境
conda install tensorflow==1.9.0

Step 3: After the installation is over, check whether tensorflow is installed successfully

python  #进入python环境

#出现‘>>>’表明已经进入python环境,在后面输入:
import tensorflow as tf

#如果没有报错,可以输入
tf.__version__  #查看tensorflow版本
tf.__path__   #查看tensorflow路径

Set the operating environment (interpreter) for the current code

File——》settings——》python interpreter

——"Click the drop-down bar. If you can see the python environment we configured, select it directly (the tensorflow environment was configured under conda before, and the environment was activated, so there will be Python3.6 (tensorflow) here). If not, see the next step

——"The drop-down bar does not have the environment we just configured, add it manually

First determine where our python environment is:

Refer to the first step of "2.  Reconfiguration on the basis of the existing virtual environment ",

The * in the red box represents our current environment. Seeing that tensorflow is under anaconda3/envs/tensorflow, remember this path by yourself and use it later.

 

——" Click this button in the python interpreter of setting:

There are two items: Add and show all:

——》Click Add, the following interface appears

——"Because of the conda environment used before, so choose the second one:

——"Find in the environment of existence, click...:

——"Select the interpreter according to the python path remembered before, and finally locate python. It’s not python3 or something, just python, then click OK

Finally, apply Apply and OK.

So that the code can actually run.

Guess you like

Origin blog.csdn.net/allein_STR/article/details/112553297