pylint false positive E0401 import errors in vscode while using venv

前端 未结 4 1195
醉话见心
醉话见心 2021-02-05 06:40

I created a venv using python3.6 on my mac os in this folder /Users/kim/Documents/Apps/PythonApps/python36-miros-a3

I ran a pip install pylint

4条回答
  •  旧巷少年郎
    2021-02-05 07:42

    To me, pylint is correct in flagging this error here

    the top level module is database (it contains an __init__.py file)

    Your import should look like (fully absolute)

    from database.database_dispatcher import ...
    

    or (explicit relative) (yes! the . before the module name is intentional)

    from .database_dispatcher import ...
    

    My follow-up guess is that you're currently invoking your script as python ./database/main.py ... which is putting ./database at the beginning of sys.path so it would appear that your imports are working correctly -- this is side-stepping your module structure however. You should be invoking your script using python -m database.main ... instead.

    Note that implicit relative imports were removed in python 3.x -- though this (imo) wart of script sys.path insertion remains.

提交回复
热议问题