scrapinghub / python-crfsuite

A python binding for crfsuite
MIT License
770 stars 222 forks source link

AttributeError: module 'pycrfsuite' has no attribute 'Tagger' #62

Closed ankit51 closed 7 years ago

ankit51 commented 7 years ago

I am trying to run a python script from Linux command line and I am getting this error when declaring Tagger.

tagger = pycrfsuite.Tagger()

I am using Python 3.5.2 |Anaconda 4.2.0 (64-bit) This was running fine on some other Linux machine.

What could be the possible solution?

kmike commented 7 years ago

Could you please paste the whole exception?

ankit51 commented 7 years ago

Here it is:

Traceback (most recent call last): File "crf_test_only.py", line 36, in tagger = pycrfsuite.Tagger() AttributeError: module 'pycrfsuite' has no attribute 'Tagger'

kmike commented 7 years ago

Do you by chance run this script from python-crfsuite source checkout? What's the output of

>>> import pycrfsuite
>>> print(pycrfsuite.__file__)
ankit51 commented 7 years ago

I am getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pycrfsuite' has no attribute '__file__'
kmike commented 7 years ago

Hm, that's strange. What does import inspect; inspect.getfile(pycrfsuite) return? I'm trying to figure out where pycrfsuite is imported from; likely it is not imported from a right location, and that's the cause of the error.

ankit51 commented 7 years ago

I am getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/synology/data/home/a.malik/anaconda3/lib/python3.5/inspect.py", line 607, in getfile
    raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'pycrfsuite' (namespace)> is a built-in module
ankit51 commented 7 years ago

Hey thanks

I have found the error. The export path was incorrect.

It should have been: export PATH="/home/tomcat/anaconda3/bin:$PATH"

Really sorry to bother you.

kmike commented 7 years ago

That's strange because pycrfsuite is not a built-in module, pycrfsuite top-level module is pure Python: https://github.com/scrapinghub/python-crfsuite/blob/master/pycrfsuite/__init__.py.

I think you may need to print import sys; print(sys.path) and look for files and subfolders named pycrfsuite located under these paths. Usual suspect is the current directory - do you have anything named pycrfsuite in it?

kmike commented 7 years ago

Ah, glad to see you've resolved it!

MahimaBhargava commented 4 years ago

Do you by chance run this script from python-crfsuite source checkout? What's the output of

>>> import pycrfsuite
>>> print(pycrfsuite.__file__)

I am getting same issue. For print(pycrfsuite.file) command, I am getting the path to the init.py file of pycrfsuite. Can you give me some more pointers>