Repository: spyder-ide/spyder

Issue:
No such file or directory when trying to access %userprofile
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

  File "C:\Users\HP\Anaconda2\lib\site-packages\spyder\widgets\mixins.py", line 758, in add_to_history
    encoding.write(text, self.history_filename, mode='ab')
  File "C:\Users\HP\Anaconda2\lib\site-packages\spyder\utils\encoding.py", line 227, in write
    with open(filename, mode) as textfile:
IOError: [Errno 2] No such file or directory: u'%userprofile\\.spyder\\history.py'


## Version and main components

* Spyder Version: 3.2.3 
* Python Version: 2.7.13
* Qt Versions: 5.6.2, PyQt5 5.6 on Windows

## Dependencies
```
pyflakes >=0.5.0  :  1.5.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pygments >=2.0    :  2.2.0 (OK)
pandas >=0.13.1   :  0.20.3 (OK)
numpy >=1.7       :  1.13.1 (OK)
sphinx >=0.6.6    :  1.6.3 (OK)
rope >=0.9.4      :  0.10.5 (OK)
jedi >=0.9.0      :  0.10.2 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.26.1 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0;<6.0:  5.4.1 (OK)
pylint >=0.25     :  1.7.2 (OK)

```



Discussion:
Please update to our latest release, 3.2.6, and try again.
Also, if that doesn't work, please try the steps listed in the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ), specifically the [Basic First Aid](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ#basic-first-aid-general-troubleshooting) and [Emergency CPR](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ#emergency-cpr-spyder-wont-launch) sections.

If it still isn't working, please describe in detail the circumstances in which the error occurred, and post the information listed in [relevant subsection](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ#must-have-and-helpful-items-to-include) of the Calling for Help section as a comment to this issue, and we'll try to help if we can. Otherwise, your issue will likely have to be closed after one week (7 days). Thanks, and best of luck!
Closed due to lack of response.

Resolving patch:
diff --git a/spyder/config/base.py b/spyder/config/base.py
--- a/spyder/config/base.py
+++ b/spyder/config/base.py
@@ -106,21 +106,30 @@ def get_home_dir():
     """
     try:
         # expanduser() returns a raw byte string which needs to be
-        # decoded with the codec that the OS is using to represent file paths.
+        # decoded with the codec that the OS is using to represent
+        # file paths.
         path = encoding.to_unicode_from_fs(osp.expanduser('~'))
-    except:
+    except Exception:
         path = ''
-    for env_var in ('HOME', 'USERPROFILE', 'TMP'):
-        if osp.isdir(path):
-            break
-        # os.environ.get() returns a raw byte string which needs to be
-        # decoded with the codec that the OS is using to represent environment
-        # variables.
-        path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
-    if path:
+
+    if osp.isdir(path):
         return path
     else:
-        raise RuntimeError('Please define environment variable $HOME')
+        # Get home from alternative locations
+        for env_var in ('HOME', 'USERPROFILE', 'TMP'):
+            # os.environ.get() returns a raw byte string which needs to be
+            # decoded with the codec that the OS is using to represent
+            # environment variables.
+            path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
+            if osp.isdir(path):
+                return path
+            else:
+                path = ''
+
+        if not path:
+            raise RuntimeError('Please set the environment variable HOME to '
+                               'your user/home directory path so Spyder can '
+                               'start properly.')
 
 
 def get_clean_conf_dir():


Test patch: