leinardi / pylint-pycharm

A plugin providing both real-time and on-demand scanning of Python files with PyLint from within PyCharm/IDEA.
Apache License 2.0
196 stars 35 forks source link

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

Open kkew3 opened 5 years ago

kkew3 commented 5 years ago

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.

Step 2: Describe your environment

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

Expected Results:

Relevant Code:

def greeting(n): print('hello:', utils.f(n))


* `src/utils.py`

```python
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).

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

dan-bar-dov commented 4 years ago

I have the same problem.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

ronaldofas commented 4 years ago

I have the same problem to PyCharm 2020.01 PyLint 0.12.2.

JosephViolago commented 4 years ago

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.

mrm-david commented 3 years ago

I also have the same problem.

prasannasrinivasan1989 commented 1 year ago

I have the same problem

VikalpRusia commented 1 year ago

I have same problem