如何用Python3安装PyRTF?

时间:2016-07-01 00:38:58

标签: python python-3.x rtf

我尝试从PyPi安装PyRTF,但这不起作用。

可以找到包裹本身:

$ pip3 search PyRTF
PyRTF (0.45)  - PyRTF - Rich Text Format Document Generation

但安装失败了:

$ sudo -H pip3 install PyRTF
Collecting PyRTF
  Could not find a version that satisfies the requirement PyRTF (from versions: )
No matching distribution found for PyRTF

我很困惑。

2 个答案:

答案 0 :(得分:4)

您可以使用sourceforge页面中的原始网址来获取它:

pip install https://sourceforge.net/projects/pyrtf/files/pyrtf/0.45/PyRTF-0.45.tar.gz/download 

但是,说实话,我不认为这个库是在项目网站上维护的,最后一次更新来自2005,11年前。此外,它使用了以下形式的一行:

from types import StringType

仅存在于Python 2.x而不是3.x中。导入它也会引发特定错误:

>>> import PyRTF
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jim/anaconda3/lib/python3.5/site-packages/PyRTF/__init__.py", line 1, in <module>
    from    PropertySets    import  *
  File "/home/jim/anaconda3/lib/python3.5/site-packages/PyRTF/PropertySets.py", line 12, in <module>
    from    types       import  StringType
ImportError: cannot import name 'StringType'

所以它可能是为Python 2.x而设计的?我忘记了从StringType系列中移除3.x的时间,也许是针对旧版本的。{/ p>

答案 1 :(得分:2)

PyRTF的Python 3版本称为PyRTF3。你可以找到它Here

PS - 对于Python 2使用pip install PyRTF3pip install rtfwpip install PyRTF无效。