pylint: unable to import conda installed modules

Viewed 189

I have a package I'm developing in a Conda virtual environment that runs fine and imports all my installed modules as needed. I'm trying to use a pylint git pre-commit hook, but getting E0401 import-errors for installed modules (e.g., Pandas). I've tried several suggestions to edit my path via the .pylintrc init-hook option with no luck. I can add the direct path to my conda environment's site-packages folder, but that of course doesn't work for other collaborators. pylint is installed in the conda environment. I'm using the command line to run pylint.

How do I use pylint with a conda virtual environment?

1 Answers

I haven't discovered why, but I have found that when using pylint inside of a conda environment,

pylint myfile.py

has import errors on things like pandas and torch. However, it seems to work when I do

python -m pylint myfile.py

I believe pylint used by itself is using the python from conda (since pylint is also in conda and the environment is activated). However, I have not yet found why the former fails and the latter works.

I hope this helps you and others coming here.

Related