Repository: spyder-ide/spyder

Issue:
Code Analysis not working in packaged 4.2 MacOS app
 
### What steps will reproduce the problem?

<!--- You can use Markdown here --->

1. Launch MacOS Spyder Application (4.2.0)
2. Open script to be analysed
2. Open Code Analysis Pane
3. Click Analyze

Following error gets thrown:

```
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = '/Applications/Spyder.app/Contents/MacOS/python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/Applications/Spyder.app/Contents/MacOS/python'
  sys.base_prefix = '/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8'
  sys.base_exec_prefix = '/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8'
  sys.executable = '/Applications/Spyder.app/Contents/MacOS/python'
  sys.prefix = '/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8'
  sys.exec_prefix = '/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8'
  sys.path = [
    '/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
    '/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
    '/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000112447e00 (most recent call first):
<no Python frame>
```



Discussion:
Looping in @mrclary as I know you've been instrumental in the development of the MacOS app :)

Resolving patch:
diff --git a/installers/macOS/setup.py b/installers/macOS/setup.py
--- a/installers/macOS/setup.py
+++ b/installers/macOS/setup.py
@@ -101,6 +101,9 @@ def make_app_bundle(dist_dir, make_lite=False):
         Note: only applicable to not-Lite build
     pygments :
         ModuleNotFoundError: No module named 'pygments.formatters.latex'
+    pylint :
+        No module named pylint.__main__; 'pylint' is a package and cannot be
+        directly executed
     pyls :
         <path>/Contents/MacOS/python: No module named pyls
         Note: still occurs in alias mode
@@ -126,8 +129,8 @@ def make_app_bundle(dist_dir, make_lite=False):
     logger.info('Creating %s app bundle...', build_type)
 
     PACKAGES = ['alabaster', 'astroid', 'blib2to3', 'ipykernel', 'IPython',
-                'jedi', 'jinja2', 'keyring', 'parso', 'pygments', 'pyls',
-                'pyls_black', 'pyls_spyder', 'qtawesome', 'setuptools',
+                'jedi', 'jinja2', 'keyring', 'parso', 'pygments', 'pylint',
+                'pyls', 'pyls_black', 'pyls_spyder', 'qtawesome', 'setuptools',
                 'sphinx', 'spyder', 'spyder_kernels']
 
     if make_lite:
diff --git a/spyder/plugins/pylint/widgets/pylintgui.py b/spyder/plugins/pylint/widgets/pylintgui.py
--- a/spyder/plugins/pylint/widgets/pylintgui.py
+++ b/spyder/plugins/pylint/widgets/pylintgui.py
@@ -13,6 +13,7 @@
 
 # Standard library imports
 from __future__ import print_function, with_statement
+import os
 import os.path as osp
 import re
 import sys
@@ -26,7 +27,8 @@
                             QVBoxLayout, QWidget)
 
 # Local imports
-from spyder.config.base import get_conf_path, get_translation
+from spyder.config.base import (get_conf_path, get_translation,
+                                running_in_mac_app)
 from spyder.py3compat import pickle, to_text_string
 from spyder.utils import icon_manager as ima
 from spyder.utils.qthelpers import create_toolbutton
@@ -441,6 +443,12 @@ def start(self):
         pylint_args.append(filename)
         processEnvironment = QProcessEnvironment()
         processEnvironment.insert("PYTHONIOENCODING", "utf8")
+
+        # resolve spyder-ide/spyder#14262
+        if running_in_mac_app():
+            pyhome = os.environ.get("PYTHONHOME")
+            processEnvironment.insert("PYTHONHOME", pyhome)
+
         self.process.setProcessEnvironment(processEnvironment)
 
         self.process.start(sys.executable, pylint_args)


Test patch: