2

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?

Dylan Hettinger
  • 731
  • 1
  • 11
  • 20
  • Does this answer your question? [pylint false positive E0401 import errors in vscode while using venv](https://stackoverflow.com/questions/51095449/pylint-false-positive-e0401-import-errors-in-vscode-while-using-venv) – crissal Jan 06 '22 at 20:43
  • Thanks, but no, that is about getting pylint in VS to recognize modules within the package being developed. I'm not using VS or having problems with modules internal to my package. – Dylan Hettinger Jan 06 '22 at 20:58
  • Can you provide your pylint and astroid versions ? – Pierre.Sassoulas Jan 08 '22 at 08:56
  • @Pierre.Sassoulas pylint version is 2.12.2 and astroid is 2.9.0 – Dylan Hettinger Jan 09 '22 at 22:03

1 Answers1

0

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.

mikebob
  • 311
  • 1
  • 5