简体   繁体   中英

How to install PyRTF with Python3?

I tried to install PyRTF from PyPi but this doesn't work.

The package itself can be found:

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

But installing it fails:

$ 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

I am confused.

You could use the raw url from the sourceforge page in order to get it:

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

But, to be honest, I don't think this library is maintained on the project website the last update was from 2005 , 11 years ago.. Additionally, it uses a line of the form:

from types import StringType

which only exists in Python 2.x not 3.x . Importing it raises that specific error too:

>>> 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'

So maybe it was designed for Python 2.x ? I can't remember when StringType was removed from the 3.x series, maybe it targeted an old version of it.

There is a Python 3 version of PyRTF called PyRTF3. You can find it Here .

PS - Use pip install PyRTF3 or pip install rtfw for Python 2, pip install PyRTF doesn't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM