Search code examples
pythonpython-importpython-module

How to debug failed import for Python dragnet module?


I'm trying to use a python module called dragnet: https://pypi.python.org/pypi/dragnet

I am inexperienced in the python ecosystem. I am following the setup example on that page. Which looks like it should be straightforward. My current code is:

import requests
from dragnet import content_extractor

# fetch HTML
url = 'https://moz.com/devblog/dragnet-content-extraction-from-diverse-feature-sets/'
r = requests.get(url)

# get main article without comments
content = content_extractor.analyze(r.content)

I'm getting an error:

Kevs-MBP:bin kev$ python dragnet.py
Traceback (most recent call last):
  File "dragnet.py", line 2, in <module>
    from dragnet import content_extractor
  File "/Users/kev/code/easeread/bin/dragnet.py", line 2, in <module>
    from dragnet import content_extractor
ImportError: cannot import name content_extractor

I am on OSX.

Kevs-MBP:bin kev$ python --version
Python 2.7.13

Solution

  • Ok apparently python doesn't like the entry point sharing the same name as the module you're importing so renaming dragnet.py solved it