Python 导入caffe错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28177298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:52:18  来源:igfitidea点击:

Import caffe error

pythoncaffe

提问by pbu

i compiled caffe successfully in my ubuntu machine but cannot import in python.

我在我的 ubuntu 机器上成功编译了 caffe,但无法在 python 中导入。

Caffe is installed /home/pbu/Desktop/caffe

Caffe安装在/home/pbu/Desktop/caffe

i tried adding the /home/pbu/caffe/python path to sys.path.append, still not working

我尝试将 /home/pbu/caffe/python 路径添加到 sys.path.append,仍然无法正常工作

i am trying to import caffe

我正在尝试导入 caffe

root@pbu-OptiPlex-740-Enhanced:/home/pbu/Desktop# python ./caffe/output.py
Traceback (most recent call last):
  File "./caffe/output.py", line 13, in <module>
    import caffe
  File "/home/pbu/Desktop/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver
  File "/home/pbu/Desktop/caffe/python/caffe/pycaffe.py", line 10, in <module>
    from ._caffe import Net, SGDSolver
ImportError: No module named _caffe

采纳答案by Anoop K. Prabhu

This happens when you have not run makefor the python files separately.

当您没有make单独运行python 文件时会发生这种情况。

Run make pycaffesoon after running makein the Caffe directory.

在 Caffe 目录中运行make pycaffe后立即运行make

You may have to set the path to the python library correctly in Makefile.config

您可能必须在中正确设置 python 库的路径 Makefile.config

回答by Harsh Wardhan

Well, I use the cmake-guifor makingCaffe. There you need to set the Python paths to the Anaconda-python:

好吧,我用的是cmake-guifor makingCaffe。在那里你需要设置 Anaconda-python 的 Python 路径:

PYTHON_EXECUTABLE <path_to_anaconda_home>/bin/python2.7
PYTHON_INCLUDE_DIRECTORY <path_to_anaconda_home>/include/PYTHON2.7
PYTHON_LIBRARY <path_to_anaconda_home>/lib/libpython2.7.so

回答by yhlleo

You should build caffe and pycaffe using the command:

您应该使用以下命令构建 caffe 和 pycaffe:

cd $FRCN_ROOT/caffe-fast-rcnn
make -j8 && make pycaffe

and before the compilation, you should create a Makefile.configfile and set the corresponding library path, such as python.

并且在编译之前,你应该创建一个Makefile.config文件并设置相应的库路径,比如python。

More details are presented on the web: bgirshick/py-faster-rcnn.

更多细节在网络上提供:bgirshick/py-faster-rcnn

What's more, when I run the "Beyond the demo" section, it seams that if I Create a symlink of the folder "VOCdevkit" as "VOCdevkit2007" which turns out to be "can't find the dataset". So, I change the folder name as "VOCdevkit2007", and it runs well.

更重要的是,当我运行“Beyond the demo”部分时,如果我将文件夹“VOCdevkit”的符号链接创建为“VOCdevkit2007”,结果是“找不到数据集”。因此,我将文件夹名称更改为“VOCdevkit2007”,并且运行良好。

回答by Victoria Stuart

I posted my Caffe install notes (my architecture: Arch Linux x86_64 | Intel i7 CPU ...) in an Anaconda Python 2.7 virtual environment here:

我在 Anaconda Python 2.7 虚拟环境中发布了我的 Caffe 安装说明(我的架构:Arch Linux x86_64 | Intel i7 CPU ...):

Caffe Installation Notes

Caffe安装注意事项

https://gist.github.com/victoriastuart/fb2cb22209ccb2771963a25c06221213

I also encountered the (downstream) "Import caffe error," for which I needed to resolve my $PYTHONPATH to complete the make compilation and get Caffe finally installed, and also to be able to import it (in Python).

我还遇到了(下游)“导入 caffe 错误”,为此我需要解决我的 $PYTHONPATH 以完成 make 编译并最终安装 Caffe,并且还能够导入它(在 Python 中)。

回答by Bhaskar Chakradhar

Adding to the above best answer. After you run makefor python files by running make pycaffewhere you ran your previous makes. Then you have to export that python path by running export PYTHONPATH=<path-to-caffe>/python. You can choose to run this everytime before running a python code which utilizes caffe or add it to your ~/.bashrc.

添加到上述最佳答案。在make通过运行make pycaffe之前运行的地方运行python 文件之后make。然后你必须通过运行导出该 python 路径export PYTHONPATH=<path-to-caffe>/python。您可以选择在每次运行使用 caffe 的 python 代码之前运行它或将其添加到您的~/.bashrc.