Repository: spyder-ide/spyder

Issue:
IOError when getting saved file names in a project
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Opening spyder from Terminal in macOS with '~/anaconda2/bin/spyder $@' causes an Exception and Spyder does not remember last config. In addition, Spyder creates a new project in the current working directory.

### Traceback
```python-traceback
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/projects.py", line 156, in <lambda>
    lambda v: self.editor.setup_open_files())
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/editor.py", line 2702, in setup_open_files
    filenames = self.projects.get_project_filenames()
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/projects.py", line 341, in get_project_filenames
    recent_files = self.current_active_project.get_recent_files()
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/widgets/projects/type/__init__.py", line 79, in get_recent_files
    default=[])
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py", line 377, in get
    self.set(section, option, default)
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py", line 445, in set
    self._save()
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py", line 120, in _save
    raise(e)
IOError: [Errno 2] No such file or directory: u'sn_0_9996680/.spyproject/workspace.ini'
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'json': {'documentation_url': u'https://developer.github.com/v3', 'message': u'Bad credentials'}, 'code': 401}
```

## Versions

* Spyder version: 3.3.0 
* Python version: 2.7.15
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Darwin 18.0.0

### Dependencies

```
pyflakes >=0.5.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.5 (OK)
rope >=0.9.4      :  0.10.7 (OK)
jedi >=0.9.0      :  0.12.0 (OK)
psutil >=0.3      :  5.4.6 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  0.23.3 (OK)
numpy >=1.7       :  1.14.5 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.28.3 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0;<6.0:  5.7.0 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
pylint >=0.25     :  1.9.2 (OK)
```


Discussion:
> causes an Exception and Spyder does not remember last config

What's the exception?
> In addition, Spyder creates a new project in the current working directory.

What's the problem with that?

Resolving patch:
diff --git a/spyder/widgets/projects/type/__init__.py b/spyder/widgets/projects/type/__init__.py
--- a/spyder/widgets/projects/type/__init__.py
+++ b/spyder/widgets/projects/type/__init__.py
@@ -70,13 +70,20 @@ def set_recent_files(self, recent_files):
         for recent_file in recent_files[:]:
             if not os.path.isfile(recent_file):
                 recent_files.remove(recent_file)
-        self.CONF[WORKSPACE].set('main', 'recent_files',
-                                 list(OrderedDict.fromkeys(recent_files)))
+        try:
+            self.CONF[WORKSPACE].set('main', 'recent_files',
+                                     list(OrderedDict.fromkeys(recent_files)))
+        except EnvironmentError:
+            pass
 
     def get_recent_files(self):
         """Return a list of files opened by the project."""
-        recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',
-                                                default=[])
+        try:
+            recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',
+                                                    default=[])
+        except EnvironmentError:
+            return []
+
         for recent_file in recent_files[:]:
             if not os.path.isfile(recent_file):
                 recent_files.remove(recent_file)


Test patch: