microsoft / vscode-pylint

Linting support for python using the pylint library.
https://marketplace.visualstudio.com/items?itemName=ms-python.pylint
MIT License
72 stars 34 forks source link

Pylint doesn't find the path set in `.env` and `terminal.integrated.env.linux` #433

Open eromoe opened 4 years ago

eromoe commented 4 years ago

Steps to cause the bug to occur

  1. Follow https://code.visualstudio.com/docs/python/environments#_use-of-the-pythonpath-variable
  2. add .env with some path like PYTHONPATH=/home/dc/sales_forecast/jobs/airflow:/home/dc/sales_forecast/sales_forecast
  3. add terminal.integrated.env.linux with {"PYTHONPATH": "/home/dc/sales_forecast/jobs/airflow:/home/dc/sales_forecast/sales_forecast"} to .vscode/settings.json
  4. run pylint

still show import error

PS: intelligence is working by set

"python.autoComplete.extraPaths": ["/home/dc/sales_forecast/jobs/airflow", "/home/dc/sales_forecast/sales_forecast"]

Your Jupyter and/or Python environment

Please provide as much info as you readily know

karthiknadig commented 4 years ago

@eromoe Did you run pylint in the terminal or did you set it up via extension settings?

eromoe commented 4 years ago

I run pylint by ctrl + shift + p : image

I found pylint become fine today , shouldn't PYTHONPATH take effect immediately ?

khs26 commented 4 years ago

Not sure whether it's a useful second reference, but this issue seems to be the same I raised in my SO question

It appears that when using a virtual environment, pylint invocation looks like the following:

/path/to/venv/bin/python -m pylint --disable=all --enable=[...list of enabled warnings...] --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text /my/python/file.py

This doesn't apply any modifications to environment variables (including PYTHONPATH) specified in my python.envFile location.

karthiknadig commented 3 years ago

We don't use the .env files when running linters. We don't run the linter is a specific terminal so, the settings there don't apply either. We have plans to move linting into language server process, this should allow for better handling of the environment variables.

pmuller commented 2 years ago

Is there a workaround?

karthiknadig commented 2 years ago

@pmuller You can set environment variables in a terminal outside of vscode from a terminal, then launch VS code from there using, code .

tomaszstepinvest commented 1 year ago

@karthiknadig It does not work for some reason at least not always.

keenan-v1 commented 4 weeks ago

Hello from 2024! This is still an issue as far as I can tell, and the work-around is assuming all workflows are local, which is not ideal.

Please let me know if there's a work-around besides just not linting or disabling specific errors. It's frustrating that a Microsoft-endorsed extension wouldn't support .env given VSCode itself does.

I'll also start looking for alternatives :(