Repository: spyder-ide/spyder

Issue:
Code analysis fails with `No module named pylint` on pip based installation
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Just open spyder, open a file, and click for code analysis in the GUI

### Traceback
```python-traceback
pylint error:

C:\Program Files\Python310\pythonw.exe: No module named pylint

```

## Versions

* Spyder version: 5.3.3  (pip)
* Python version: 3.10.7 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.5
* Operating System: Windows 10

### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0          :  1.4.1 (OK)
chardet >=2.0.0               :  5.0.0 (OK)
cloudpickle >=0.5.0           :  2.1.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.31.1;<8.0.0       :  7.34.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.6.0 (OK)
keyring >=17.0.0              :  23.5.0 (OK)
nbconvert >=4.0               :  6.5.0 (OK)
numpydoc >=0.6.0              :  1.2 (OK)
paramiko >=2.4.0              :  2.11.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.2 (OK)
pygments >=2.0                :  2.12.0 (OK)
pylint >=2.5.0;<3.0           :  2.15.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.5.0;<1.6.0          :  1.5.0 (OK)
pylsp_black >=1.2.0           :  1.2.0 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.3 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.0.3 (OK)
qtconsole >=5.3.2;<5.4.0      :  5.3.2 (OK)
qtpy >=2.1.0                  :  2.1.0 (OK)
rtree >=0.9.7                 :  1.0.0 (OK)
setuptools >=49.6.0           :  65.3.0 (OK)
sphinx >=0.6.6                :  5.1.1 (OK)
spyder_kernels >=2.3.3;<2.4.0 :  2.3.3 (OK)
textdistance >=4.2.0          :  4.4.0 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.9 (OK)
zmq >=22.1.0                  :  23.2.1 (OK)

# Optional:
cython >=0.21                 :  0.29.32 (OK)
matplotlib >=3.0.0            :  3.5.3 (OK)
numpy >=1.7                   :  1.23.3 (OK)
pandas >=1.1.1                :  1.4.4 (OK)
scipy >=0.17.0                :  1.9.1 (OK)
sympy >=0.7.3                 :  1.11.1 (OK)
```



Discussion:
Hi @r-jean-pierre thank you for the feedback! Are you by any chance using a custom interpreter? Also, if you import pylint from Spyder' `internal console` (you can make it visible by selecting from the `View > Panes` menu the `Internal console` entry) that works?

Any further info is greatly appreciated, let us know!
Hi dalthviz,
I'm using a regular python interpreter from python.org
(Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)])

For the second question I just dicovered the internal console :) and I can import pylint from there (and also from the ipython)

![2022-09-15 21_34_15-Spyder (Python 3 10)](https://user-images.githubusercontent.com/9727894/190493333-52595e69-81e8-4e5b-90b9-a013811ff4a3.png)

![2022-09-15 21_35_39-Spyder (Python 3 10)](https://user-images.githubusercontent.com/9727894/190493483-74a10d00-3aa6-464a-9858-462b4ee49899.png)

It only fails when i press the green play button:
![2022-09-15 21_36_22-Code analysis fails while pylint is installed and works in both command line or ](https://user-images.githubusercontent.com/9727894/190493710-b57fc6bc-58f8-49fd-ae43-9cce4a406ffe.png)


And from outside it works:
![2022-09-15 21_38_06-C__Windows_system32_cmd exe](https://user-images.githubusercontent.com/9727894/190493982-01487a20-109f-43b6-847c-f28a7cc733de.png)

Could you share the path where `pylint` is installed? Thinking about it, maybe we are missing setting/passing some env vars when launching the `pytlint` process and that makes the Python interpreter unable to find the installed `pylint` (at least on pip based installs 🤔 ?):

https://github.com/spyder-ide/spyder/blob/bed973b661bfc136f1f507001932200a02b5ff2a/spyder/plugins/pylint/main_widget.py#L365-L381
The lib itself seems to be there for me:

C:\Users\Admin\AppData\Roaming\Python\Python310\site-packages

and binaries:
C:\Users\Admin\AppData\Roaming\Python\Python310\Scripts\

![2022-09-15 22_13_33-UltraSearch Free](https://user-images.githubusercontent.com/9727894/190500107-18c30550-a7a7-42a9-b535-b21479095f25.png)

(PS all my libs are installed using `pip install xxxxx`)

Maybe the env var missing to add in the process Spyder launches is `APPDATA` 🤔

Could you try to add the following code around line 374 of the file I referenced above? : `processEnvironment.insert("APPDATA", os.environ.get("APPDATA") )`

Hi,

Yes: it works now!
I can run it and see in the pane the results of pylint

Thank you

![2022-09-16 10_39_06-C__Users_Admin_AppData_Roaming_Python_Python310_site-packages_spyder_plugins_pyl](https://user-images.githubusercontent.com/9727894/190595588-cb2392b7-fd72-428e-9493-2eff2d981142.png)


Resolving patch:
diff --git a/spyder/plugins/pylint/main_widget.py b/spyder/plugins/pylint/main_widget.py
--- a/spyder/plugins/pylint/main_widget.py
+++ b/spyder/plugins/pylint/main_widget.py
@@ -31,7 +31,8 @@
 from spyder.api.config.decorators import on_conf_change
 from spyder.api.translations import get_translation
 from spyder.api.widgets.main_widget import PluginMainWidget
-from spyder.config.base import get_conf_path, running_in_mac_app
+from spyder.config.base import get_conf_path, is_pynsist, running_in_mac_app
+from spyder.config.utils import is_anaconda
 from spyder.plugins.pylint.utils import get_pylintrc_path
 from spyder.plugins.variableexplorer.widgets.texteditor import TextEditor
 from spyder.utils.icon_manager import ima
@@ -365,12 +366,16 @@ def _start(self):
         processEnvironment = QProcessEnvironment()
         processEnvironment.insert("PYTHONIOENCODING", "utf8")
 
-        # Needed due to changes in Pylint 2.14.0
-        # See spyder-ide/spyder#18175
         if os.name == 'nt':
+            # Needed due to changes in Pylint 2.14.0
+            # See spyder-ide/spyder#18175
             home_dir = get_home_dir()
             user_profile = os.environ.get("USERPROFILE", home_dir)
             processEnvironment.insert("USERPROFILE", user_profile)
+            # Needed for Windows installations using standalone Python and pip.
+            # See spyder-ide/spyder#19385
+            if not is_pynsist() and not is_anaconda():
+                processEnvironment.insert("APPDATA", os.environ.get("APPDATA"))
 
         # resolve spyder-ide/spyder#14262
         if running_in_mac_app():


Test patch: