Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylint "unable to import" error but works fine with Pycharm

The basic structure of my program looks like this:

top_dir
__init__.py
readme.rst
    sub_dir
    __init__.py
        sub_sub_dir
        __init__.py
        example_module.py
        sub_sub_dir2
        __init__.py
        module_with_import.py

In Pycharm all imports just work fine. For example I use the following import in 'module_with_import.py':

from sub_dir.sub_sub_dir.example_module import function

However if I run pylint on module_with_import.py I will get the following error:

Unable to import 'sub_dir.sub_sub_dir.example_module' (import-error)

Does anybody see what's wrong here?

like image 524
monpy Avatar asked Jan 12 '16 12:01

monpy


People also ask

How do I fix pylint import error in Vscode?

How do I fix pylint import error? Solution 1: (configure workspace settings to point to fully qualified python executable): Solution 2: (open VS Code from an activated virtual environment): Cause: The path to the python executable is incorrect.

What is ImportError in Python?

ImportError is raised when a module, or member of a module, cannot be imported. There are a two conditions where an ImportError might be raised. If a module does not exist.

How do I import Pytest into Hackerrank?

Press ctrl+shift+p then type pylint in search bar then click on enable/ON. After this run the code your issue is resolved.


1 Answers

Module (package) cannot have minus in name. Rename Sub-dir to sub_dir, Sub-sub-dir to sub_sub_dir and Sub-sub-dir2 to sub_sub_dir2.

Next read PEP-8 The Python Style Guide

like image 156
Tomasz Jakub Rup Avatar answered Sep 23 '22 03:09

Tomasz Jakub Rup