繁体   English   中英

如何在Python2.7中配置Whoosh

[英]How to configure Whoosh in Python2.7

我的机器上有两个Python设置。 其中之一是Enthought Canopy随附的Python 2.7.6,也是我从Python网站下载的2.7.9文件。

我试图在两者中都安装Whoosh。 一切顺利。 在Enthought中,我已将其安装为以下命令提示符下给出的pip install whoosh,即Microsoft Windows [Version 6.1.7601]版权所有(c)2009 Microsoft Corporation。 版权所有。

C:\\ Users \\ Admin>

我正在尝试练习https://pythonhosted.org/Whoosh/quickstart.html#a-quick-introduction中给出的示例。在Python 2.7.9的IDLE中,它运行良好,但在Python 2.7的IDLE中。认为有6个错误,因为

Python 2.7.6 | 64-bit | (default, Sep 15 2014, 17:36:35) [MSC v.1500 64 bit (AMD64)] on win32
    Type "copyright", "credits" or "license()" for more information.
    >>> import whoosh
    >>> from whoosh.index import create_in
    >>> from whoosh.fields import *
    >>> schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
    >>> ix = create_in("index", schema)

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    ix = create_in("index", schema)
  File "C:\Users\Admin\AppData\Local\Enthought\Canopy\User\lib\site-packages\whoosh\index.py", line 102, in create_in
    return FileIndex.create(storage, schema, indexname)
  File "C:\Users\Admin\AppData\Local\Enthought\Canopy\User\lib\site-packages\whoosh\index.py", line 425, in create
    TOC.create(storage, schema, indexname)
  File "C:\Users\Admin\AppData\Local\Enthought\Canopy\User\lib\site-packages\whoosh\index.py", line 605, in create
    for filename in storage:
  File "C:\Users\Admin\AppData\Local\Enthought\Canopy\User\lib\site-packages\whoosh\filedb\filestore.py", line 81, in __iter__
    return iter(self.list())
  File "C:\Users\Admin\AppData\Local\Enthought\Canopy\User\lib\site-packages\whoosh\filedb\filestore.py", line 518, in list
    files = os.listdir(self.folder)
WindowsError: [Error 3] The system cannot find the path specified: 'index/*.*'
>>> 

我试图从网上找到一个解决方案,并试图修复Pythonpath。

但是按照我的设置,IDLE 2.7.6根本没有打开。

请提出我该如何解决。

我正在以2.7.9的开始>所有程序> IDLE(Python GUI)和开始>所有程序> Enthought Canopy(64位)> IDLE(64位)打开IDLE标准方式。

我将PYTHONPATH设置为Start(开始)> Computer(计算机),然后从其中单击Advanced System Settings(高级系统设置),在此处单击Advanced(高级)选项卡,然后单击Environment Variables(环境变量)。

当您使用“ index”指定目录时,通常相对于“当前目录”。 python脚本在启动时永远不要假设当前目录是哪个目录。 相反,您应该指定完整的目录路径(典型的最佳实践),或者在需要时在脚本中显式更改当前目录(良好实践),或者至少在运行脚本之前明确更改目录(可接受)。 我不知道您的“索引”目录在哪里,但是假设它与脚本在同一目录中,那么最简单的解决方案是当脚本在编辑器中时,告诉Canopy“更改到编辑器目录”。 该命令在Python面板顶部的下拉列表中。 您还可以在运行脚本之前使用IPython magic %cd命令更改当前目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM