question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pylint instance doesn't respect PYTHONPATH and/or source roots

See original GitHub issue

Step 1: Are you in the right place?

This is highly related to https://github.com/leinardi/pylint-pycharm/issues/10, but it has been closed.

  • I have verified there are no duplicate active or recent bugs, questions, or requests
  • I have verified that I am using the latest version of the plugin.

Step 2: Describe your environment

  • Plugin version: v0.11.0
  • PyCharm/IDEA version: 2018.3.5 (Community Edition)
  • Pylint version: 2.3.1

Step 3: Describe the problem:

Pylint run by the plugin doesn’t put source roots into PYTHONPATH. Therefore, all import statements involving project files trigger no-name-in-module error.

Steps to reproduce:

  1. Create a new project under directory ${some_directory}/xxx, using virtualenv under ${some_directory}/xxx/rt; activate the virtualenv by cd ${some_directory}/xxx; . rt/bin/activate.
  2. Install pylint: pip install pylint
  3. Create directory ${some_directory}/xxx/src, and mark it as source root in pycharm. Create two files, ${some_directory}/xxx/src/utils.py, filled with def f(x): return x + 1, and ${some_directory}/xxx/src/hello.py, filled with import utils; def hello(n): print('hello:', utils.f(n)). (The code is written in one line for clarity. See the actual layout in screenshot below)
  4. Run pylint plugin on ${some_directory}/xxx/src/hello.py.

Observed Results:

Screen Shot 2019-03-31 at 12 19 58 AM
  • In terminal, under working directory ${some_directory}/xxx, with the virtualenv rt activated, run PYTHONPATH="$(pwd)/src" pylint src/hello.py. It doesn’t report module 'utils' has no 'f' member. However, the Pylint plugin does report.
  • Interestingly, the Pylint plugin stops reporting the error some time later. I haven’t thought of a way to measure the time lapse.

Expected Results:

  • The plugin should not report module xxx has no yyy member in such case, and should behave the same as the terminal pylint.

Relevant Code:

  • src/hello.py
import utils

def greeting(n):
    print('hello:', utils.f(n))
  • src/utils.py
def f(x):
    return x + 1

Event Log: Yes there’s exclamation mark around Event Log in the screenshot. However I removed the test project before I saw the comment about pasting the event log. I tend to believe the problem has been partially fixed. IMHO the scanning of source roots might not be done every time before running pylint. I also tested removing the mark source root on src. While pycharm inspection immediately underlines import utils in hello.py, there’s no response from the pylint plugin (after it has stopped reporting the error).

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

1reaction
JosephViolagocommented, May 29, 2020

I was able to resolve this by adding PYTHONPATH=./src to my .env file.

Source

Context: I am also using pipenv to allow Automatic Loading of .env.

0reactions
mrm-davidcommented, Nov 23, 2020

I also have the same problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyLint "Unable to import" error - how to set PYTHONPATH?
In my setup the package in question was outside the root of the project, therefore my line looks like this: init-hook="from pylint.config import...
Read more >
Bountysource
Pylint instance doesn't respect PYTHONPATH and/or source roots.
Read more >
Changelog - Apache Airflow Documentation
Dockerfile: The group of embedded DAGs should be root to be ... [AIRFLOW-7017] Respect default dag view in trigger dag origin (#7667).
Read more >
Untitled
... 0001-applet-Pass-instance-pointer-to-signal-handler.patch ... 0001-Include-the-libcroco-sources-directly-under-src-st-c.patch ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found