<p><strong>如何复制和修复此错误:</strong></p>
<p>打开python解释器,尝试导入xlrt,得到一个错误:</p>
<pre><code>python
>>> import xlrt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xlrt
</code></pre>
<p><strong>1。安装,或确保已安装pip:</strong></p>
<p><a href="https://stackoverflow.com/questions/5585875/what-is-the-official-preferred-way-to-install-pip-and-virtualenv-systemwide">What is the official "preferred" way to install pip and virtualenv systemwide?</a></p>
<p><strong>2。安装xlrd</strong></p>
<pre><code>pip install xlrd
</code></pre>
<p>普罗蒂普:如果你觉得你必须使用<code>sudo pip install ....</code>来让它工作,那么你需要停下来学习为什么这是危险的。见:<a href="https://stackoverflow.com/questions/21055859/what-are-the-risks-of-running-sudo-pip">What are the risks of running 'sudo pip'?</a></p>
<p>解决方法是使用特定用户安装pip:<code>pip install --user myuser ...</code>在这里使用您自己的最佳判断。确保pip正在操作的目录由试图在其中安装软件包的用户拥有。使用:<code>chown -R $USER /Library/Python/2.7/site-packages</code>。</p>
<p><strong>3。在python解释器上测试:</strong></p>
<pre><code>python
>>> import xlrd
>>> type(xlrd)
<type 'module'>
>>>
</code></pre>
<p>现在它被导入,没有问题了,xlrd是一个python模块。</p>
<p><strong>故障排除:</strong></p>
<p>如果未定义PYTHONPATH,则应定义它:</p>
<pre><code>PYTHONPATH=:/home/el/wherever/where_to_find_modules
</code></pre>