Repository: spyder-ide/spyder

Issue:
PermissionError while launching Spyder
## Description

### What steps will reproduce the problem?

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

Hi, I am getting the following error while launchine Spyder. My Anaconda version is 5.3.0 in Windows 7. Your suggestion to remove this error will be highly appreciated.

### Traceback
```python-traceback
  File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 110, in _save
    _write_file(fname)
  File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 106, in _write_file
    with open(fname, 'w', encoding='utf-8') as configfile:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Administrator\\.spyder-py3\\spyder.ini'

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\spyder\plugins\__init__.py", line 440, in set_option
    CONF.set(self.CONF_SECTION, str(option), value)
  File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 445, in set
    self._save()
  File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 120, in _save
    raise(e)
  File "C:\Anaconda3\lib\site-packages\spyder\config\user.py", line 114, in _save
    os.remove(fname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\Administrator\\.spyder-py3\\spyder.ini'
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
```

## Versions

* Spyder version: 3.3.1 
* Python version: 3.7.0
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 7

### Dependencies

```
pyflakes >=0.6.0  :  2.0.0 (OK)
pycodestyle >=2.3 :  2.4.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.7.9 (OK)
rope >=0.9.4      :  0.11.0 (OK)
jedi >=0.9.0      :  0.12.1 (OK)
nbconvert >=4.0   :  5.4.0 (OK)
pandas >=0.13.1   :  0.23.4 (OK)
numpy >=1.7       :  1.15.1 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.28.5 (OK)
qtconsole >=4.2.0 :  4.4.1 (OK)
IPython >=4.0     :  6.5.0 (OK)
matplotlib >=2.0.0:  2.2.3 (OK)
pylint >=0.25     :  2.1.1 (OK)
```



Discussion:
There's no way to avoid this error right now other than you using a Windows Administrator console to start Spyder.

However, we'll add a fix for this problem in our next version (3.3.2).

Resolving patch:
diff --git a/spyder/config/user.py b/spyder/config/user.py
--- a/spyder/config/user.py
+++ b/spyder/config/user.py
@@ -108,16 +108,16 @@ def _write_file(fname):
 
         try:  # the "easy" way
             _write_file(fname)
-        except IOError:
+        except EnvironmentError:
             try:  # the "delete and sleep" way
                 if osp.isfile(fname):
                     os.remove(fname)
                 time.sleep(0.05)
                 _write_file(fname)
             except Exception as e:
-                print("Failed to write user configuration file.")  # spyder: test-skip
-                print("Please submit a bug report.")  # spyder: test-skip
-                raise(e)
+                print("Failed to write user configuration file to disk, with "
+                      "the exception shown below")  # spyder: test-skip
+                print(e)  # spyder: test-skip
 
     def filename(self):
         """Defines the name of the configuration file to use."""


Test patch: