[英]NameError: name 'unicode' is not defined when compile with python3
我正在尝试使用python3编译caffe。 编译后,当我尝试导入Caffe时出现以下错误
In [1]: import caffe
Failed to include caffe_pb2, things might go wrong!
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-1cca3aa1f8c5> in <module>()
----> 1 import caffe
/library_install_dir/caffe/python/caffe/__init__.py in <module>()
1 from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
2 from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list
----> 3 from .proto.caffe_pb2 import TRAIN, TEST
4 from .classifier import Classifier
5 from .detector import Detector
/library_install_dir/caffe/python/caffe/proto/caffe_pb2.py in <module>()
975 name='type', full_name='caffe.FillerParameter.type', index=0,
976 number=1, type=9, cpp_type=9, label=1,
--> 977 has_default_value=True, default_value=unicode("constant", "utf-8"),
978 message_type=None, enum_type=None, containing_type=None,
979 is_extension=False, extension_scope=None,
NameError: name 'unicode' is not defined
我试图修改proto / caffe_pb2,但无法正常工作。
任何与咖啡有类似问题的人。 我的裸机上有一个运行中的python3支持的caffe,现在我正尝试对其进行docker化。
提前致谢。
我有同样的问题。 unicode
适用于Python2。 使用make pycaffe
命令后,您可以检查/opt/caffe-1.0/python/caffe/proto/caffe_pb2.py
文件,如果文件中有任何unicode
,问题仍然存在。 您可以删除caffe_pb2.py
并再次运行make pycaffe
。
解决方案是安装适当版本的protoc
和protobuf
。
A)安装协议> = 2.6.1
(协议== 2.5.0无法正常工作)
https://cuongba.com/protocol-buffers-and-rabbitmq-on-ubuntu-14-04-part-1
wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar -xzvf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
sudo ./configure
make
make check
sudo make install
sudo ldconfig
protoc --version
B)安装protobuf> = 3.4.0
pip3 install protobuf>=3.4.0
在Python 3中,Str默认为Unicode,因此,在977行中,请将unicode函数替换为str函数
--> 977 has_default_value=True, default_value=Str("constant", "utf-8"), ## Replace with Str
希望这可以帮助!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.