我正在尝试在caffe
环境中安装conda
。 Caffe
需要Google的protobuf
软件包。我已经git clone
了protobuf
,并将其保存在我的\usr
目录中。但是,当我尝试在conda环境中安装caffe时,安装的libprotobuf
版本无法将proto
文件正确转换为c++
代码。
请考虑以下代码:
syntax = "proto2";
package test1;
message Datum {
optional int32 channels = 1;
}
[当我尝试从base
环境中进行翻译时,一切都很好:
(base) me@balin:~/Projects/caffe$ make clean
(base) me@balin:~/Projects/caffe$ make superclean
Deleting the following generated files:
./temp5.pb.cc
./temp5.pb.h
(base) me@balin:~/Projects/caffe$ protoc --cpp_out=. temp5.proto
(base) me@balin:~/Projects/caffe$ g++ temp5.pb.cc -c
(base) me@balin:~/Projects/caffe$
但是,当我在要用于caffe
的环境中尝试相同的操作时,会得到以下结果:
(dnn_track5) me@balin:~/Projects/caffe$ make clean
(dnn_track5) me@balin:~/Projects/caffe$ make superclean
Deleting the following generated files:
./temp5.pb.cc
(dnn_track5) me@balin:~/Projects/caffe$ protoc --cpp_out=. temp5.proto
(dnn_track5) me@balin:~/Projects/caffe$ g++ temp5.pb.cc -c
temp5.pb.cc: In member function ‘virtual const char* test1::Datum::_InternalParse(const char*, google::protobuf::internal::ParseContext*)’:
temp5.pb.cc:150:58: error: ‘ReadVarint’ is not a member of ‘google::protobuf::internal’
channels_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint(&ptr);
^~~~~~~~~~
temp5.pb.cc:150:58: note: suggested alternative: ‘ReadVarint32’
channels_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint(&ptr);
^~~~~~~~~~
ReadVarint32
[我所能做的就是用我从~\anaconda2\envs\dnn_track5
克隆构建conda
时安装的文件替换protobuf
所安装的GitHub
子目录中的每个文件。我是否正确(我对此表示怀疑)。
我如何创建一个conda环境,在其中我可以使用caffe
并且仍然可以使用protobuf
?
没有直接使用conda从github存储库直接安装的方法,因此值得一看为什么您的代码无法在您的caffe
环境中工作。
截至this commit(自2019年10月起)之间有区别>
::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64
和
::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32
[当您
conda install caffe
时,它下载(至少对我而言)libprotobuf-3.11.2
,它是2019年12月的最新版本,因此,作为caffe
的依赖项下载的版本实际上比您尝试的要新。在您的代码中使用。
您现在有几个选择:
请求具有您要使用的API的protobuf的特定版本。即3.10.0,从2019年10月3日开始:
conda create -n caffe -c conda-forge python=3.7 caffe libprotobuf=3.10.0
创建自定义的conda频道并在其中放置自己的libprotobuf.tar.bz2
libprotobuf
API