问题描述
我试图使在装有Ubuntu 12.04LTS的计算机上运行。
完成上的所有步骤之后,我成功地训练了LeNet模型,并尝试将其用作 。然后我收到以下错误:
I am trying to make caffe running on my machine equipped with Ubuntu 12.04LTS.After finishing all the steps on the Installation page, I trained the LeNet model successfully and tried to use it as the tutorial from here. Then I got the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named caffe
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 18, in <module>
import problem_report
File "/usr/lib/python2.7/dist-packages/problem_report.py", line 14, in <module>
import zlib, base64, time, sys, gzip, struct, os
File "/usr/lib/python2.7/gzip.py", line 10, in <module>
import io
File "${HOME}/path/to/caffe/python/caffe/io.py", line 2, in <module>
import skimage.io
File "/usr/local/lib/python2.7/dist-packages/skimage/io/__init__.py", line 11, in <module>
from ._io import *
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_io.py", line 1, in <module>
from io import BytesIO
ImportError: cannot import name BytesIO
Original exception was:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named caffe
我设置 PYTHONPATH
在 .bashrc
文件中,然后执行上述操作。
有什么问题?任何人都可以给点提示吗?我真的很困惑。
运行命令 python -c’import io之后;在非常目录中打印io .__ file __'
:
I set the PYTHONPATH
in .bashrc
file before I did the above.What is the problem? Could anyone give some hint? I am really confused.After running the command python -c 'import io; print io.__file__'
in the very directory:
Traceback (most recent call last):
File "${HOME}/path/to/caffe/python/caffe/io.py", line 2, in <module>
import skimage.io
File "/usr/local/lib/python2.7/dist-packages/skimage/io/__init__.py", line 11, in <module>
from ._io import *
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_io.py", line 1, in <module>
from io import BytesIO
ImportError: cannot import name BytesIO
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 18, in <module>
import problem_report
File "/usr/lib/python2.7/dist-packages/problem_report.py", line 14, in <module>
import zlib, base64, time, sys, gzip, struct, os
File "/usr/lib/python2.7/gzip.py", line 10, in <module>
import io
File "${HOME}/path/to/caffe/python/caffe/io.py", line 2, in <module>
import skimage.io
File "/usr/local/lib/python2.7/dist-packages/skimage/io/__init__.py", line 11, in <module>
from ._io import *
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_io.py", line 1, in <module>
from io import BytesIO
ImportError: cannot import name BytesIO
Original exception was:
Traceback (most recent call last):
File "${HOME}/path/to/caffe/python/caffe/io.py", line 2, in <module>
import skimage.io
File "/usr/local/lib/python2.7/dist-packages/skimage/io/__init__.py", line 11, in <module>
from ._io import *
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_io.py", line 1, in <module>
from io import BytesIO
ImportError: cannot import name BytesIO
问题变成:如何解决名称问题?
P.S .:我还在中插入了一个问题。
So, the problem becomes to: how to solve the name issue?P.S.: I also inserted an issue at the repository of caffe.
推荐答案
您似乎在自己的包中有名为 io
的程序包或模块隐藏标准库包的Python路径。它是导入的,但是没有要导入的 BytesIO
对象。
You appear to have a package or module named io
in your Python path that is masking the standard library package. It is imported instead but doesn't have a BytesIO
object to import.
尝试运行:
python -c 'import io; print io.__file__'
在运行本教程的位置,并重命名或移动名为通过该导入,假定它不是标准库版本(以 lib / python2.7 / io.pyc
结尾)。
in the same location you are running the tutorial and rename or move the file named by that import, presuming it is not the standard library version (ending in lib/python2.7/io.pyc
).
可能是您将Python路径设置为错误的目录。您应包括 path / to / caffe / python
,而不是 path / to / caffe / python / caffe
,也不应您尝试运行python,并将后者作为当前工作目录。在两种情况下而不是标准库版本。
It could be you set your Python path to the wrong directory. You should include path/to/caffe/python
, not path/to/caffe/python/caffe
, nor should you try and run python with the latter as your current working directory. In both cases caffe/python/caffe/io.py
instead of the standard library version.
这里的安装说明没有错误;他们清楚地告诉您使用:
The installation instructions are not at fault here; they clearly tell you to use:
export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
请注意,缺少 / caffe
在该路径的末尾。
Note the lack of /caffe
at the end of that path.
这篇关于在Ubuntu上导入Caffe时,ImportError无法导入名称BytesIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!