Importerror:no Module named Caffe Solution __ Problem Resolution

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.