Python - cannot import name viewkeys
<p>I'm importing a module which inturn imports <code>six</code>, but I'm getting this weird error. </p>

<pre><code>Traceback (most recent call last):
  File "/Users/praful/Desktop/got/modules/categories/tests.py", line 13, in &lt;module&gt;
    import microdata
  File "build/bdist.macosx-10.10-intel/egg/microdata.py", line 4, in &lt;module&gt;
  File "/Library/Python/2.7/site-packages/html5lib/__init__.py", line 16, in &lt;module&gt;
    from .html5parser import HTMLParser, parse, parseFragment
  File "/Library/Python/2.7/site-packages/html5lib/html5parser.py", line 2, in &lt;module&gt;
    from six import with_metaclass, viewkeys, PY3
ImportError: cannot import name viewkeys
</code></pre>

<p>I'd a look at <a href="https://github.com/JioCloud/python-six/blob/master/six.py" rel="nofollow">six.py</a>, it has <code>viewkeys</code> in it. </p>

<p>Latest <code>six==1.10.0</code> is installed.</p>

<p>I had the same problem:</p>

<pre><code>&gt; python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import six
&gt;&gt;&gt; import xhtml2pdf.pisa
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Library/Python/2.7/site-packages/xhtml2pdf/pisa.py", line 3, in &lt;module&gt;
    from xhtml2pdf.document import pisaDocument
  File "/Library/Python/2.7/site-packages/xhtml2pdf/document.py", line 2, in &lt;module&gt;
    from xhtml2pdf.context import pisaContext
  File "/Library/Python/2.7/site-packages/xhtml2pdf/context.py", line 23, in &lt;module&gt;
    import xhtml2pdf.parser
  File "/Library/Python/2.7/site-packages/xhtml2pdf/parser.py", line 17, in &lt;module&gt;
    from html5lib import treebuilders, inputstream
  File "/Library/Python/2.7/site-packages/html5lib/__init__.py", line 16, in &lt;module&gt;
    from .html5parser import HTMLParser, parse, parseFragment
  File "/Library/Python/2.7/site-packages/html5lib/html5parser.py", line 2, in &lt;module&gt;
    from six import with_metaclass, viewkeys, PY3
ImportError: cannot import name viewkeys
&gt;&gt;&gt; exit()
</code></pre>

<p>I ran the following steps: <br></p>

<ul>
<li><code>sudo -H pip uninstall six</code></li>
<li><code>sudo -H pip install six==1.9.0</code></li>
<li>Test: Error persists</li>
<li><code>sudo -H pip uninstall six==1.9.0</code></li>
<li><code>sudo -H pip install six==1.10.0</code></li>
</ul>

<p>Test:</p>

<pre><code>&gt; python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; from six import viewkeys
&gt;&gt;&gt; import xhtml.pisa
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ImportError: No module named xhtml.pisa
&gt;&gt;&gt; import xhtml2pdf.pisa
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "xhtml2pdf/pisa.py", line 3, in &lt;module&gt;
    from xhtml2pdf.document import pisaDocument
  File "xhtml2pdf/document.py", line 2, in &lt;module&gt;
    from xhtml2pdf.context import pisaContext
  File "xhtml2pdf/context.py", line 23, in &lt;module&gt;
    import xhtml2pdf.parser
  File "xhtml2pdf/parser.py", line 17, in &lt;module&gt;
    from html5lib import treebuilders, inputstream
ImportError: cannot import name inputstream
&gt;&gt;&gt; exit()
</code></pre>

<p>So the viewkeys-error didn't come back.</p>

<p>The problem importing inputstream seems to be a bug in xhtml2pdf:<br>
<a href="https://github.com/xhtml2pdf/xhtml2pdf/issues/318" rel="nofollow">https://github.com/xhtml2pdf/xhtml2pdf/issues/318</a></p>

<p>For me this fixed the problem:<br>
<code>sudo -H pip install html5lib==1.0b8</code></p>

<p>So afterall, I don't really know if the last command would have fixed the problem overall, but this way it works for me now:</p>

<pre><code>&gt; python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import xhtml2pdf.pisa
&gt;&gt;&gt;  
</code></pre>

python python-six