Pylint in Spyder is raising "E401 Unable to import" whithin conda environment

Viewed 895

I am having some trouble with Spyder and pylint. I run Spyder in a conda environment by selecting the correct Python interpreter, and it works fine: I can import packages that are only installed in the environment. However, when I launch code analysis (F8), pylint complains that it cannot import them, with an error E0401: Unable to import 'package'. Pylint is installed in the conda environment.

Just as an example, flask is installed in my "web" environment but not in the base workspace. Import flask works fine in Spyder's console, but E0401 is raised by pylint.


Edit: Spyder is NOT installed in the conda environment; following the "modular approach" described in Working with packages and environments in Spyder, I only installed spyder-kernels in the environment. If I install spyder directly in the environment, the pylint problem disappears.


Edit 2: I created a new clean environment to test this problem. I am running windows 10, and here is the result of conda list:

astroid 2.4.2 py38_0
backcall 0.2.0 py_0
ca-certificates 2020.7.22 0
certifi 2020.6.20 py38_0
click 7.1.2 py_0
cloudpickle 1.6.0 py_0
colorama 0.4.3 py_0
decorator 4.4.2 py_0
flask 1.1.2 py_0
ipykernel 5.3.4 py38h5ca1d4c_0
ipython 7.18.1 py38h5ca1d4c_0
ipython_genutils 0.2.0 py38_0
isort 5.5.2 py38_0
itsdangerous 1.1.0 py_0
jedi 0.15.2 py38_0 conda-forge
jinja2 2.11.2 py_0
jupyter_client 6.1.6 py_0
jupyter_core 4.6.3 py38_0
lazy-object-proxy 1.4.3 py38he774522_0
libsodium 1.0.18 h62dcd97_0
markupsafe 1.1.1 py38he774522_0
mccabe 0.6.1 py38_1
openssl 1.1.1g he774522_1
parso 0.5.2 py_0
pickleshare 0.7.5 py38_1000
pip 20.2.2 py38_0
prompt-toolkit 3.0.7 py_0
pygments 2.7.1 py_0
pylint 2.6.0 py38_0
python 3.8.5 h5fd99cc_1
python-dateutil 2.8.1 py_0
pywin32 227 py38he774522_1
pyzmq 19.0.2 py38ha925a31_1
setuptools 49.6.0 py38_0
six 1.15.0 py_0
spyder-kernels 1.9.4 py38_0
sqlite 3.33.0 h2a8f88b_0
toml 0.10.1 py_0
tornado 6.0.4 py38he774522_1
traitlets 4.3.3 py38_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.16.27012 hf0eaf9b_3
wcwidth 0.2.5 py_0
werkzeug 1.0.1 py_0
wheel 0.35.1 py_0
wincertstore 0.2 py38_0
wrapt 1.11.2 py38he774522_0
zeromq 4.3.2 ha925a31_3
zlib 1.2.11 h62dcd97_4

And pip list:

Package Version


astroid 2.4.2
backcall 0.2.0
certifi 2020.6.20
click 7.1.2
cloudpickle 1.6.0
colorama 0.4.3
decorator 4.4.2
Flask 1.1.2
ipykernel 5.3.4
ipython 7.18.1
ipython-genutils 0.2.0
isort 5.5.2
itsdangerous 1.1.0
jedi 0.15.2
Jinja2 2.11.2
jupyter-client 6.1.6
jupyter-core 4.6.3
lazy-object-proxy 1.4.3
MarkupSafe 1.1.1
mccabe 0.6.1
parso 0.5.2
pickleshare 0.7.5
pip 20.2.2
prompt-toolkit 3.0.7
Pygments 2.7.1
pylint 2.6.0
python-dateutil 2.8.1
pywin32 227
pyzmq 19.0.2
setuptools 49.6.0.post20200814
six 1.15.0
spyder-kernels 1.9.4
toml 0.10.1
tornado 6.0.4
traitlets 4.3.3
wcwidth 0.2.5
Werkzeug 1.0.1
wheel 0.35.1
wincertstore 0.2
wrapt 1.11.2

1 Answers

A few things I can suggest:

  1. You should verify again that the Pylint installation is indeed associated with the Python interpreter. You can do so by running this command in the Terminal:

    pip show pylint

then under Location verify the correct location of the package.

If you don't have terminal for Spyder, you can install it from here.

or download the package from Conda Terminal with:

conda install -c conda-forge spyder-terminal

or if it doesn't work maybe with this:

conda install spyder-terminal -c spyder-ide
  1. If it does not show or seems right but still not working you can try to install pylint again running this command in the terminal:

    pip install -U pylint

  2. I saw a reoccurring problems with Spyder related to the F8 button. Verify that you indeed use the F8 button and not other methods. See this discussion for further insight

If all does not work for you, please provide more details about your Python version and operating system that might also be the cause of this linking problem.

Related