When python calls caffe, ImportError: No module named _caffe appears

       A seemingly simple question has been tossing me for a long time, and today I suddenly realized that, of course, I am too low and my understanding is not deep enough.

      As an amateur novice, I configured ubuntu 16.04 +CUDA8.0 +caffe+opencv 2.13 +CUDNN5.1 environment half a year ago, and successfully ran through deep learning frameworks such as SSD and FlowNet2.0. Of course, Dongcha Xicha also It took a long time, and then it was used very smoothly on the basis of this environment. A few days ago, I accidentally deleted the ibus related to the input method, and then there was a problem with the system, which could not be solved for a long time, so I was very confident. Installed a system, but everything was not so smooth...

      When calling the previous python file, the following problem will occur: ImportError: No module named _caffe, then I recompile the next project, for example, my project path is: ~/flownet-caffe-master, enter this directory in the terminal, clean up and recompile the project:

make clean  
make all -j4
make test -j4

The following steps are optional:

make runtest -j4

The problem with running the program is as follows:

     

Solution:

First enter the terminal under the project path and execute:

sudo make pycaffe

Note: You need to execute after every recompile of caffe: sudo make pycaffe

Then add the project caffe path to the environment variable:

Method 1: (one-time)

Enter directly in the terminal: (note to change to your project path)

PYTHONPATH=/media/rongsong/3082E76F580983D6/ubnutu/Downloads/flownet2-master/python

This method is a one-time use, and the changes are lost when the terminal is closed and reopened.

Method 2: (permanent)

Execute in terminal:

sudo gedit ~/.bashrc

Add after the open file:

export PYTHONPATH=/media/rongsong/3082E76F580983D6/ubnutu/Downloads/flownet2-master/python:$PYTHONPATH

To make changes to the environment take effect immediately, type in the terminal:

source ~/.bashrc

If ImportError: No module named cv2 appears in the python code, try to execute it in the terminal:

sudo apt-get install python-opencv  


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326297816&siteId=291194637