Repository: spyder-ide/spyder

Issue:
UnicodeEncodeError when pylint tries to print non-ascii character
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

## Problem Description

Static code analysis output has an error trace instead of the output. Running pylint on the command line works fine. (Sorta similar theme to #7031 and #7930 but not exactly the same.)

### What steps reproduce the problem?

1. Make the following text file:
```
# -*- coding: utf-8 -*-
""" Test """
ω = 3
```
2. Run static code analysis

### What is the expected output? What do you see instead?

When I run pylint on the same file in the command line, I get
```
************* Module test
test.py:5:0: C0103: Constant name "ω" doesn't conform to UPPER_CASE naming style (invalid-name)

-----------------------------------
Your code has been rated at 0.00/10
```

But when I run the static code analysis in Spyder, I get a big error trace:
```
Traceback (most recent call last):
  File "C:\xx\miniconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\xx\miniconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\xx\miniconda3\lib\site-packages\pylint\__main__.py", line 8, in <module>
    pylint.run_pylint()
  File "C:\xx\miniconda3\lib\site-packages\pylint\__init__.py", line 20, in run_pylint
    Run(sys.argv[1:])
  File "C:\xx\miniconda3\lib\site-packages\pylint\lint.py", line 1628, in __init__
    linter.check(args)
  File "C:\xx\miniconda3\lib\site-packages\pylint\lint.py", line 943, in check
    self._do_check(files_or_modules)
  File "C:\xx\miniconda3\lib\site-packages\pylint\lint.py", line 1075, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "C:\xx\miniconda3\lib\site-packages\pylint\lint.py", line 1158, in check_astroid_module
    walker.walk(ast_node)
  File "C:\xx\miniconda3\lib\site-packages\pylint\utils.py", line 1303, in walk
    self.walk(child)
  File "C:\xx\miniconda3\lib\site-packages\pylint\utils.py", line 1303, in walk
    self.walk(child)
  File "C:\xx\miniconda3\lib\site-packages\pylint\utils.py", line 1300, in walk
    cb(astroid)
  File "C:\xx\miniconda3\lib\site-packages\pylint\checkers\base.py", line 1753, in visit_assignname
    self._check_name("const", node.name, node)
  File "C:\xx\miniconda3\lib\site-packages\pylint\checkers\base.py", line 1816, in _check_name
    self._raise_name_warning(node, node_type, name, confidence)
  File "C:\xx\miniconda3\lib\site-packages\pylint\checkers\base.py", line 1783, in _raise_name_warning
    self.add_message("invalid-name", node=node, args=args, confidence=confidence)
  File "C:\xx\miniconda3\lib\site-packages\pylint\checkers\__init__.py", line 110, in add_message
    self.linter.add_message(msg_id, line, node, args, confidence, col_offset)
  File "C:\xx\miniconda3\lib\site-packages\pylint\utils.py", line 496, in add_message
    message_definition, line, node, args, confidence, col_offset
  File "C:\xx\miniconda3\lib\site-packages\pylint\utils.py", line 571, in add_one_message
    confidence,
  File "C:\xx\miniconda3\lib\site-packages\pylint\reporters\text.py", line 152, in handle_message
    self.write_message(msg)
  File "C:\xx\miniconda3\lib\site-packages\pylint\reporters\text.py", line 142, in write_message
    self.writeln(msg.format(self._template))
  File "C:\xx\miniconda3\lib\site-packages\pylint\reporters\__init__.py", line 72, in writeln
    print(string, file=self.out)
  File "C:\xx\miniconda3\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u03c9' in position 30: character maps to <undefined>
************* Module test
```
## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 3.3.4
* Python version: 3.7.3
* Qt version: 5.9.6
* PyQt version: 5.9.2
* Operating System name/version: Windows 10

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
IPython >=4.0     :  7.5.0 (OK)
cython >=0.21     :  None (NOK)
jedi >=0.9.0      :  0.13.3 (OK)
matplotlib >=2.0.0:  3.0.3 (OK)
nbconvert >=4.0   :  5.5.0 (OK)
numpy >=1.7       :  1.16.3 (OK)
pandas >=0.13.1   :  0.24.2 (OK)
pycodestyle >=2.3 :  2.5.0 (OK)
pyflakes >=0.6.0  :  2.1.1 (OK)
pygments >=2.0    :  2.4.0 (OK)
pylint >=0.25     :  2.3.1 (OK)
qtconsole >=4.2.0 :  4.4.4 (OK)
rope >=0.9.4      :  0.14.0 (OK)
sphinx >=0.6.6    :  2.0.1 (OK)
sympy >=0.7.3     :  None (NOK)
```



Discussion:

Resolving patch:
diff --git a/spyder/plugins/profiler/widgets/profilergui.py b/spyder/plugins/profiler/widgets/profilergui.py
--- a/spyder/plugins/profiler/widgets/profilergui.py
+++ b/spyder/plugins/profiler/widgets/profilergui.py
@@ -275,6 +275,7 @@ def start(self, wdir=None, args=None, pythonpath=None):
             for envItem in env:
                 envName, separator, envValue = envItem.partition('=')
                 processEnvironment.insert(envName, envValue)
+            processEnvironment.insert("PYTHONIOENCODING", "utf8")
             self.process.setProcessEnvironment(processEnvironment)
 
         self.output = ''
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
@@ -21,7 +21,7 @@
 # Third party imports
 import pylint
 from qtpy.compat import getopenfilename
-from qtpy.QtCore import QByteArray, QProcess, Signal, Slot
+from qtpy.QtCore import QByteArray, QProcess, Signal, Slot, QProcessEnvironment
 from qtpy.QtWidgets import (QHBoxLayout, QLabel, QMessageBox, QTreeWidgetItem,
                             QVBoxLayout, QWidget)
 
@@ -340,6 +340,10 @@ def start(self):
             p_args += [osp.basename(filename)]
         else:
             p_args = [osp.basename(filename)]
+        processEnvironment = QProcessEnvironment()
+        processEnvironment.insert("PYTHONIOENCODING", "utf8")
+        self.process.setProcessEnvironment(processEnvironment)
+
         self.process.start(sys.executable, p_args)
 
         running = self.process.waitForStarted()


Test patch: