0

I've installed GrepFunc with:

pip install grepfunc

But when i try to import it in my Jupiter Notebook with:

from grepfunc import grep

i get a Error massage:

No module named 'grepfunc'

1) I checked if grepfunc was installed with:

pip list

And the answer is yes. But I couldn’t find this library among other installed packages

2) Then I downloaded the code from original GitHub link, and copied this to /username/anaconda3/lib/python3.7/grepfunc/ , where are the other libraries.

In this case, when I ran from grepfunc import grep, I get no more any errors. But during an attempt to use the grap function itself, I received the following errors:

StopIteration Traceback (most recent call last) ~/anaconda3/lib/python3.7/grepfunc/grepfunc.py in grep_iter(target, pattern, **kwargs) 234 # done iteration --> 235 raise StopIteration 236

StopIteration:

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last) in 2 3 # grep titles with the word 'dog' in them. Note: i=True will ignore case. ----> 4 grep(movies, "dog")

~/anaconda3/lib/python3.7/grepfunc/grepfunc.py in grep(target, pattern, **kwargs) 94 # use the grep_iter to build the return list 95 ret = [] ---> 96 for value in grep_iter(target, pattern, **kwargs): 97 98 # if quiet mode no need to continue, just return True because we got a value

RuntimeError: generator raised StopIteration

Rob Bricheno
  • 4,467
  • 15
  • 29
  • did you have multiple python versions in use - python2.7 and python3.x? So you have to check which _pip_ is used! As i see you run python _behind anaconda_. Probably another python version in normal installation? this can be a help: [pip behind anaconda](https://stackoverflow.com/questions/41060382/) – jgsedi Aug 20 '19 at 14:58
  • Thanks. The first problem is solved. I installed grepfunc to the new environment directory, and now can **import grep from grepfunc**. But still have a second problem. When i try to use this function i get `the RuntimeError: generator raised StopIteration`, which I described above. – Alexander Kalinovskiy Aug 20 '19 at 16:20
  • The StopIteration Error is raised if the end of the iteration is reached. So we need need more of your code (_But during an attempt to use the grap function itself, I received the following errors_) to discover the problem. – jgsedi Aug 20 '19 at 17:20
  • It's a very simple code from a grepfunc, just for testing a function: `from grepfunc import grep` `movies = ['Ghost Dog', 'Die Hard', 'Matrix', 'The Ring', 'Cats and Dogs', 'Batman', 'Superman', 'Reservoir Dogs']` `grep(movies, "dog", i=True)` – Alexander Kalinovskiy Aug 20 '19 at 17:48
  • but the critical point is how you call **exactly** the _grep_ function of the _grepfunc_ module. Share this code because i got the output `['Ghost Dog', 'Cats and Dogs', 'Reservoir Dogs']` – jgsedi Aug 20 '19 at 18:29
  • Yes. That is what should be the result. On my computer, something is wrong with installing the grepfunc, and what exactly is not clear. I import the function as I wrote above: `from grepfunc import grep` And then: `grep(args)` – Alexander Kalinovskiy Aug 20 '19 at 18:48
  • probably the wrong `grep` func? I'd try it without importing – jgsedi Aug 20 '19 at 21:13

1 Answers1

0

I ran into the same problem today using Python 3.7 and this is due to change in how Python generators are terminated (I'm not sure in which version of Python this change was introduced). Refer to PEP 479 -- Change StopIteration handling inside generators.

I fixed this problem for my needs by editing grepfunc.py, and commenting out line 237.

#raise StopIteration

Find your python cache for grepfunc, delete those files and then you can re-import grepfunc and use.

Issue has been filed at GitHub (https://github.com/RonenNess/grepfunc/issues/2)

XsummusX
  • 43
  • 1
  • 4