如何在conda环境中用克隆的GitHub版本替换libprotobuf的conda包

2024-06-16 12:25:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在conda环境中安装caffeCaffe需要谷歌的protobuf软件包。我已经git cloneprotobuf,并且在我的\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

我所能想到的就是用我从GitHub克隆构建protobuf时安装的文件替换~\anaconda2\envs\dnn_track5子目录中由conda安装的每个文件。我说得对吗(我怀疑)

如何创建一个conda环境,在这个环境中,我可以使用caffe,但仍然有一个工作的protobuf


Tags: basemake环境condacaffeprojectsccinternal
1条回答
网友
1楼 · 发布于 2024-06-16 12:25:22

没有直接的方法可以使用conda直接从github repo安装,因此值得一看代码在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依赖项下载的版本实际上比您试图在代码中使用的版本更新

您现在有几个选项:

  1. 请求具有要使用的API的protobuf的特定版本。即3.10.0,自2019年10月3日起:

    conda create -n caffe -c conda-forge python=3.7 caffe libprotobuf=3.10.0

  2. 创建一个自定义康达频道,并将您自己的libprotobuf.tar.bz2放在那里

  3. 调整代码以使用最新的libprotobufAPI

相关问题 更多 >