我是python的新手,我正在尝试在使用virtualenv时导入一个模块。
当我导入模块时,我会得到:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.6\helpers\pydev\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named zope.interface我正在尝试使用以下代码行导入zope.interface模块:
import zope.interface我通过调用“pip freeze”来仔细检查这个模块是否已经安装。我还在我的virtualEnv站点-包目录中找到了模块的位置。模块的路径为:
virName\Lib\site-packages\zope\interface在这个目录中,我可以看到__init__.py文件。
我的理解是,__init__.py文件的存在本身就会使它成为一个有效的模块?
我通过执行sys.path仔细检查了我的模块的搜索路径,它确实包含目录“virName packages\”
所以我的问题是。为什么python说它找不到这个模块?
我还需要检查什么?
我还尝试使用以下命令查找模块:
imp.find_module('zope.interface')但我得到了:
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: No module named zope.interface发布于 2018-09-13 16:33:42
试一试
pip install zope.interface从带有pip.exe的目录的命令行提示符,例如
C:\anaconda3\Scripts>pip install zope.interface我遇到了同样的问题,在安装了上面的软件后,问题得到了解决。
发布于 2015-08-02 19:03:26
我也遇到过同样的问题。稍微解释一下,如果您安装了iPython,PyCharm会使用它,而iPython也会使用zope.interface。我在苹果电脑上开发一个金字塔项目(使用zope.inerface),并看到以下行为:
系统终端中的Python
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope.interface
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named interface
>>> 系统终端中的iPython
$ ipython
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import zope.interface
In [2]: 请注意,它导入时没有出现错误-并且它使用了与第一个示例相同的python解释器!
根据PyCharm文档,PyCharm中的Python控制台使用iPython,我们可以从启动输出中看到以下内容:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 -u /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py 63304 63305
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
PyDev console: using IPython 3.1.0
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/Users/someone/PycharmProjects/SMS_PUB_API'])
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
In[2]: import zope.interface
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-bc61dfc4e3ea>", line 1, in <module>
import zope.interface
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named interface
In[3]: 请注意,如果我使用PyCharm的终端特性,然后使用system Python和iPython控制台,我会得到与上面前两个示例相同的结果。
从PyCharm运行金字塔奇怪的是,如果我从PyCharm (它使用zope.interfaces)中运行我的金字塔项目,使用与上面示例相同的项目解释器,它会正常启动
人们很容易认为这是一个问题,因为zope.interface模块的命名中包含一个点-这通常是保留的python术语,用于表示路径。但是,其他zope.*模块可以很好地导入。我进入PyCharm的项目解释器设置,注意到我使用的是zope.interface 4.1.1,而4.1.2已经过时了。更新后(在pycharm中),它运行良好-我现在可以导入zope.interfaces。
注意,这也发生在普通的Mac终端上。在写这篇文章之前,我不能用iPython导入它。升级iPython后,它可以在终端上工作(我上面的第二个例子)。
希望这能有所帮助!
发布于 2016-03-19 13:14:19
我遇到了同样的问题,当与exe一起安装时,无法导入zope。因为zope文件夹下的__init__.py文件丢失了。
easy_install zope.interface-3.8.0.win-amd64-py2.7.exe当像这样安装egg时,它可以工作
easy_install zope.interface-3.8.0-py2.7-win-amd64.egghttps://stackoverflow.com/questions/30746559
复制相似问题