facebookarchive / caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
https://caffe2.ai
Apache License 2.0
8.42k stars 1.94k forks source link

import caffe2 in jupyter just stuck #2003

Open RunziiMo opened 6 years ago

RunziiMo commented 6 years ago

I'm using jupyter on my mac, I found that it would stuck there and there would be no response if I ever execute

from caffe2.python import core, workspace

and jupyter would simply show ln [ * ] for ever I can successfully execute this through my python command line. Besides, I'm not using GPU support, and this problem happens in jupyter notebook. When I switch to jupyter console, it shows

/Users/xxx/Desktop/caffe2/caffe2/python/core.py in <module>()
     27 from six import binary_type, string_types, text_type
     28 
---> 29 from caffe2.proto import caffe2_pb2
     30 from caffe2.python import scope, utils, workspace
     31 from caffe2.python.control_ops_grad import \

ImportError: cannot import name caffe2_pb2
orionr commented 6 years ago

@RunziiMo did you use the script

scripts/start_ipython_notebook.sh

to start Jupyter? Also make sure you activated your conda environment (if you used that) before running the script.

RunziiMo commented 6 years ago

@orionr I used that but it didn't work. And yeah I can successfully excute python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure" and it shows Success. Luckily, I solved import error problem now. But import caffe2.python.core still stuck.

nykabhishek commented 6 years ago

@RunziiMo Could you please explain how you solve the import problem?

RunziiMo commented 6 years ago

@nykabhishek I found I forget to add export PYTHONPATH=/usr/local:$PYTHONPATH to ~/.bash_profile. And I found that the install tutorial changed on caffe2.ai, I can now install caffe2 by Pre-Built Binaries on Mac. So I execute sudo rm -rf /usr/local/caffe* and reinstall by conda install -c caffe2 caffe2. And import problem solved.

nykabhishek commented 6 years ago

Yeah even I figured it out. I had a typo in my PYTHONPATH. Thanks for the update. Maybe we can go ahead and close this issue.

youngxiao commented 6 years ago

@nykabhishek I build caffe2 from source. And I can successfully execute python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure" and it shows Success. But when I execute python caffe2/python/operator_test/relu_op_test.py to test whether GPU support. It shows a caffe2_pb2 Import Error. So may I ask you how do you solve your caffe2_pb2 Import Error?