0

I am trying to set up linting for a Python project using pylint in Visual Studio Code. I am managing dependencies using conda and have pylint installed through there, but VSC defaults to putting the global reference to pylint as the path (/Library/Frameworks/Python.framework/Versions/3.7/bin/pylint) instead of the conda installation for this project (/opt/miniconda3/envs/tf/bin/pylint).

I was able to solve linting issues by manually changing the VSC setting to the conda installation; I am wondering if there is a way to include this in the .pylintrc so that my teammates cloning this repo can get linting without messing with their settings.

Jordan
  • 33
  • 2
  • 5

1 Answers1

0

I had a similar problem and found a workaround but I am not sure if it will work with VSC. I always use the pylint from the base env and rewrite the sys.path at pylint init to the currently active conda environment. This prevents E0401 errors without installing pylint in all the conda environments.

I use the following config in ~/.pylintrc:

[MASTER]
init-hook = "import os, sys;\
             sys.path = [s.replace('/opt/anaconda3', os.getenv('CONDA_PREFIX'))\
                         for s in sys.path]"

/opt/anaconda3 is my base anaconda env path and should be replaced by yours (/opt/miniconda3 apparently). I did not find a way to get this value automatically.

The linked pylint exe in my editor config is the one from the base environment.

I then launch my editor from a terminal with the correct conda environment (I use vim so launching the editor from a terminal is not a problem :) )

Florent
  • 142
  • 6