flupke / pypotrace

Python bindings for potrace library
Other
165 stars 43 forks source link

Python3 support for version 1.0.3 #14

Closed jachym closed 6 years ago

jachym commented 7 years ago

Hi,

when pip installing pypotrace (from Git as well as from PyPI), I get following error, if Python3 is used

    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-abrdgocf-build/setup.py", line 70, in <module>
        cython=CYTHONIZE),
      File "/tmp/pip-abrdgocf-build/setup.py", line 51, in create_ext_obj
        pkg_config_flags = get_flags(flags, flag)
      File "/tmp/pip-abrdgocf-build/setup.py", line 24, in get_flags
        return [flag[2:] for flag in flags if flag.startswith(prefix)]
      File "/tmp/pip-abrdgocf-build/setup.py", line 24, in <listcomp>
        return [flag[2:] for flag in flags if flag.startswith(prefix)]
    TypeError: startswith first arg must be bytes or a tuple of bytes, not str

For Python-2 it works

jachym commented 7 years ago

Still, you can not run potrace in python 3:

import potrace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "python3.5/site-packages/potrace/__init__.py", line 1, in <module>
    from potrace._potrace import *
ImportError: python3.5/site-packages/potrace/_potrace.cpython-35m-x86_64-linux-gnu.so: undefined symbol: PyString_FromString
alwansm commented 6 years ago

Does python3 support potrace or not yet? are there any alternative for potrace?

jachym commented 6 years ago

@alwansm well, I switched to python 2 :-|

alwansm commented 6 years ago

@jachym :| Thank you

BaptisteAmato commented 6 years ago

For Python 3 users, you can replace the following method in setup.py:

def get_flags(flags, prefix):
    return [flag[2:].decode() for flag in flags if flag.startswith(prefix.encode())]

You also need to change the _potrace.c file, by replacing "PyString_FromString" by "PyUnicode_FromString" :)