mpcabd / python-arabic-reshaper

Reconstruct Arabic sentences to be used in applications that don't support Arabic
MIT License
398 stars 80 forks source link

ConfigParser 2 vs 3 import issue #24

Closed m-macaskill closed 6 years ago

m-macaskill commented 6 years ago

Hi Abdullah,

python-arabic-reshaper is now a valuable dependency in the PsychoPy project https://github.com/psychopy/psychopy, many thanks for your work.

Some (but oddly, not all) of our Python 2 users are reporting an import issue though:

File "/Applications/PsychoPy3.app/Contents/Resources/lib/python2.7/arabic_reshaper/arabic_reshaper.py", line 31, in <module>
from configparser import ConfigParser
ImportError: No module named configparser

I can't replicate this myself but the import of this particular library does seem to be used as a classic example for maintaining compatibility between Python 2 and 3 code. Some suggestions include first attempting to import the Python 3 module name and if that fails, fall back on the Python 2 name (http://python3porting.com/noconv.html):

try:
    import configparser
except ImportError:
    import ConfigParser as configparser

but a more specific example gives this (https://stackoverflow.com/questions/32507715/standard-solution-for-supporting-python-2-and-python-3):

from six.moves import configparser
import six

if six.PY2:
  ConfigParser = configparser.SafeConfigParser
else:
  ConfigParser = configparser.ConfigParser

which might be more useful here maybe.

Any chance of incorporating something like this into arabic_reshaper? I'm not keen on submitting a pull request myself, as not being able to replicate the name conflict issue, I wouldn't be able to test it properly.

mpcabd commented 6 years ago

Hello,

Thanks for the report.

The problem is mainly when the user doesn't install the dependencies properly, this package depends on configparser and future, and the error you might get for configparser is when you don't install the linked configparser module, to fix that you just need to do pip install configparser.

Since you've declared arabic_reshaper as a dependency in psychopy then pip will install the dependencies properly, so the problem is with people who are not using pip or setuptools to install your module.

As for the import in my code, I just follow this sheet.

Regards.