after successfully compiling the Caffe source code, you can use Caffe in a Python environment. In an Ubuntu environment, Importerror:no module named may appear when you open the Python interpreter and enter import Caffe Caffe
>>>import Caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Importerror:no Module named Caffe
this typically does not add a path to Python-related content in Caffe to the compiled path of Python. You can resolve the problem by using the following methods: in Ubuntu, press Ctrl+alt+t to open the terminal, type "Python" to open the Python interpreter, and enter: Import Sys
Sys.path.append ("/(Your Caffe-master path)/caffe-master/python") sys.path.append ("/(Your Caffe-master path)/caffe-master/python/caffe") tip: Press ENTER after entering each line to allow the command to execute. After three commands have been executed, there is usually no problem. Because Python's compile path "path" is a property of model "SYS", use the command "import sys" first.
Well, I admit that this method is not a cure. After the Python interpreter enters the above command, there is a problem using import caffe, but the same error is reported after you restart the Python interpreter and import Caffe. It is not an error to open the Python interpreter using import caffe only under Caffe-master/python this folder. Then a workaround was found, and when using Python to invoke Caffe, add the following four sentences to the top of the corresponding. py file:
#设置caffe源码所在的路径 caffe_root = '.. /.. /.. /caffe-master/(This is the Caffe-master folder path, this is the relative path, absolute and relative paths are OK.) Absolute path:/. /.. /caffe-master/) ' Import sys sys.path.insert (0, caffe_root + ' python ') import Caffe
So there's no problem. Of course, all of the. py files that invoke the Caffe framework include these words. You can also encapsulate the above sentences into a Python class that is designed to implement the "Import Caffe" operation. Only to find these methods for the time being, everyone forgive me ha.