简体   繁体   中英

How to configure Whoosh in Python2.7

I have two Python settings in my machine. One is Python 2.7.6 coming with Enthought Canopy, and is the 2.7.9 file I have downloaded from Python website.

I tried to install Whoosh in both of them. It went fine. In Enthought I have installed it as pip install whoosh given in the following command prompt, Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\\Users\\Admin>

I was trying to practice examples given in https://pythonhosted.org/Whoosh/quickstart.html#a-quick-introduction in both.In the IDLE of Python 2.7.9 it ran fine, but in the IDLE of Python 2.7.6 of Enthought it is giving error as,

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/*.*'
>>> 

I tried to find a solution from the web and tried to fix the Pythonpath.

But as I set it the IDLE of 2.7.6 did not open at all.

Please suggest how may I fix it.

I am opening IDLE standard way, Start>All Programs>IDLE(Python GUI) for 2.7.9 and Start>All Programs>Enthought Canopy(64-bit)>IDLE(64-bit).

I am setting PYTHONPATH as Start>Computer right click from there Advanced System Settings, here Advanced tab, then Environment Variables.

When you specify a directory as you do with "index", that is usually relative to the "Current directory". A python script should never make any assumptions about what directory is the current directory when it is started. Instead, you should specify full directory path (typical best practice), or change the current directory explicitly in your script if needed (good practice), or at least be clear to change the directory before you run the script (acceptable). I don't know where your "index" directory is, but assuming that it is in the same directory as your script, then the easiest solution is to tell Canopy to "Change to the editor directory" when the script is in the editor. This command is in the dropdown at the top of the Python panel. You can also use the IPython magic %cd command to change the current directory before you run the script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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