Repository: spyder-ide/spyder

Issue:
Error when getting Pygments lexers
## 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 "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2760, in get_entry_map
    ep_map = self._ep_map
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2731, in __getattr__
    raise AttributeError(attr)
AttributeError: _ep_map

Traceback (most recent call last):
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/spyder/utils/introspection/manager.py", line 220, in get_completions
    info = self._get_code_info('completions', automatic=automatic)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/spyder/utils/introspection/manager.py", line 216, in _get_code_info
    **kwargs)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/spyder/utils/introspection/utils.py", line 75, in __init__
    self._get_info()
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/spyder/utils/introspection/utils.py", line 87, in _get_info
    lexer = find_lexer_for_filename(self.filename)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/spyder/utils/introspection/utils.py", line 180, in find_lexer_for_filename
    lexer = get_lexer_for_filename(filename)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pygments/lexers/__init__.py", line 203, in get_lexer_for_filename
    res = find_lexer_class_for_filename(_fn, code)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pygments/lexers/__init__.py", line 168, in find_lexer_class_for_filename
    for cls in find_plugin_lexers():
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pygments/plugin.py", line 52, in find_plugin_lexers
    for entrypoint in iter_entry_points(LEXER_ENTRY_POINT):
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 737, in iter_entry_points
    entries = dist.get_entry_map(group)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2763, in get_entry_map
    self._get_metadata('entry_points.txt'), self
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2492, in parse_map
    for group, lines in data:
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3095, in split_sections
    for line in yield_lines(s):
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2352, in yield_lines
    for ss in strs:
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2688, in _get_metadata
    if self.has_metadata(name):
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1488, in has_metadata
    return self.egg_info and self._has(self._fn(self.egg_info, name))
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1840, in _has
    return zip_path in self.zipinfo or zip_path in self._index()
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1717, in zipinfo
    return self._zip_manifests.load(self.loader.archive)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1677, in load
    manifest = self.build(path)
  File "/Users/Apple/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1650, in build
    with zipfile.ZipFile(path) as zfile:
  File "/Users/Apple/anaconda3/lib/python3.6/zipfile.py", line 1090, in __init__
    self.fp = io.open(file, filemode)
IsADirectoryError: [Errno 21] Is a directory: '/Users/Apple/anaconda3/lib/python3.6/site-packages/bulbea-0.1.0-py3.6.egg'


## Version and main components

* Spyder Version: 3.2.6 
* Python Version: 3.6.3
* Qt Versions: 5.6.2, PyQt5 5.6 on Darwin

## Dependencies
```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.22.0 (OK)
numpy >=1.7      :  1.14.3 (OK)
sphinx >=0.6.6   :  1.6.6 (OK)
rope >=0.9.4     :  0.10.7 (OK)
jedi >=0.9.0     :  0.11.1 (OK)
psutil >=0.3     :  5.4.3 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.27.3 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.3.1 (OK)
pylint >=0.25    :  1.8.2 (OK)

```



Discussion:
> IsADirectoryError: [Errno 21] Is a directory: '/Users/Apple/anaconda3/lib/python3.6/site-packages/bulbea-0.1.0-py3.6.egg'

The most probable cause of this error is that you installed a package with pip that is interfering with your other conda packages.

You have two options here:

1. Remove the directory `/Users/Apple/anaconda3/lib/python3.6/site-packages/bulbea-0.1.0-py3.6.egg` and try again. That could be enough to make Spyder work again.
2. Uninstall and reinstall Anaconda again. That's the safest path.

Resolving patch:
diff --git a/spyder/utils/introspection/utils.py b/spyder/utils/introspection/utils.py
--- a/spyder/utils/introspection/utils.py
+++ b/spyder/utils/introspection/utils.py
@@ -21,10 +21,8 @@
 )
 
 from pygments.lexer import words
-from pygments.lexers import (
-    get_lexer_for_filename, get_lexer_by_name, TextLexer
-)
-from pygments.util import ClassNotFound
+from pygments.lexers import (get_lexer_for_filename, get_lexer_by_name,
+                             TextLexer)
 from pygments.token import Token
 
 
@@ -178,7 +176,7 @@ def find_lexer_for_filename(filename):
     else:
         try:
             lexer = get_lexer_for_filename(filename)
-        except ClassNotFound:
+        except Exception:
             return TextLexer()
     return lexer
 


Test patch: