0

When I import module tool, I get the following error message,

  File "/Users/bird/Desktop/various-examples-of-web-crawlers/venv/lib/python3.7/site-packages/tool/__init__.py", line 11, in <module>
    from context_locals import app, local
ModuleNotFoundError: No module named 'context_locals'

Operating system:macOS Sierra 10.12.6

IDE: pycharm

Code:

import urllib.request

import urllib.parse

import re

import tool

if __name__ == '__main__':

    #引入工具类
    self_tool = tool.Tool()

I tried to find a solution on google, but failed.

Pavel Vergeev
  • 3,060
  • 1
  • 31
  • 39
张盛强
  • 13
  • 4
  • 1
    can you share the code – Jeril Mar 12 '19 at 07:51
  • 1
    The module you appear to be trying to use hasn't been maintained in over 7 years. It's a dead project, and it's incompatible with Python 3. – user2357112 Mar 12 '19 at 07:55
  • @Jeril # -*- coding:utf-8 -*- import urllib.request import urllib.parse import re import tool if __name__ == '__main__': #引入工具类 self_tool = tool.Tool() – 张盛强 Mar 12 '19 at 07:59

1 Answers1

0

I went ahead and installed the package to reproduce the error.

The problem arises because the package is written for Python 2, and uses implicit local imports. They were prohibited in Python 3. Read more in this question: Changes in import statement python3.

But even after you fix the relative imports problems, you get

ImportError: cannot import name 'alias' from 'argh'

argh is a dependency of tool and a failure to import it indicates that the wrong (more recent) version of argh gets installed.

At this point your options are to try and install the package with Python 2 or port it to Python 3. See How To Port Python 2 Code to Python 3.

Pavel Vergeev
  • 3,060
  • 1
  • 31
  • 39