Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'module' object has no attribute 'Locale' #251

Open
RichardBradley opened this issue Jun 15, 2020 · 2 comments
Open

AttributeError: 'module' object has no attribute 'Locale' #251

RichardBradley opened this issue Jun 15, 2020 · 2 comments

Comments

@RichardBradley
Copy link

I have the following error when I run make test at the current HEAD version (c553375) of this project on an Amazon Linux 2 VM in a python venv:

$ make test
...
running build_ext
Traceback (most recent call last):
  File "setup.py", line 50, in <module>
    'Programming Language :: Python :: 3.4',
  File "/home/ec2-user/certbot-venv/venv/lib/python2.7/site-packages/setuptools/__init__.py", line 162, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib64/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/ec2-user/certbot-venv/venv/lib/python2.7/site-packages/setuptools/command/test.py", line 237, in run
    self.run_tests()
  File "/home/ec2-user/certbot-venv/venv/lib/python2.7/site-packages/setuptools/command/test.py", line 259, in run_tests
    exit=False,
  File "/usr/lib64/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/lib64/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/usr/lib64/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/usr/lib64/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib64/python2.7/unittest/loader.py", line 103, in loadTestsFromName
    return self.loadTestsFromModule(obj)
  File "/home/ec2-user/certbot-venv/venv/lib/python2.7/site-packages/setuptools/command/test.py", line 55, in loadTestsFromModule
    tests.append(self.loadTestsFromName(submodule))
  File "/usr/lib64/python2.7/unittest/loader.py", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "/home/ec2-user/certbot-venv/parsedatetime-master/tests/TestAlternativeAbbreviations.py", line 16, in <module>
    pdtLocale_en = get_icu('en_US')
  File "/home/ec2-user/certbot-venv/parsedatetime-master/parsedatetime/pdt_locales/icu.py", line 56, in get_icu
    result['icu'] = icu = pyicu.Locale(locale)
AttributeError: 'module' object has no attribute 'Locale'
make: *** [test] Error 1

I believe that the "import icu as pyicu" line here is importing itself. I don't understand why this affects me and not other users, or how this is meant to work.

Here is a full repro:

$ sudo bash
# cat /etc/*release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
Amazon Linux release 2 (Karoo)
# yum install -y git python-pip
# pip install virtualenv pipenv
# virtualenv venv
# source venv/bin/activate
...
# git clone https://github.com/bear/parsedatetime.git && cd parsedatetime
...
# make test
...
AttributeError: 'module' object has no attribute 'Locale'

The following patch fixes this issue for me:

index e09f517..c6f277d 100644
--- a/parsedatetime/pdt_locales/icu.py
+++ b/parsedatetime/pdt_locales/icu.py
@@ -12,13 +12,7 @@ try:
 except NameError:
     pass

-try:
-    import icu as pyicu
-except ImportError:
-    try:
-        import PyICU as pyicu
-    except ImportError:
-        pyicu = None
+import PyICU as pyicu


 def icu_object(mapping):

I encountered this when trying to run certbot.

Can anyone explain what has gone wrong here? Is this a bug in parsedatetime or in Amazon Linux 2?

Is there a better workaround than applying the above patch to my site-packages?

Thanks,

Rich

@tonyg
Copy link
Contributor

tonyg commented Jul 16, 2020

Hi Richard, see #247 (and #245, #246, and #248).

@RichardBradley
Copy link
Author

Thanks!

Hopefully your PR will get merged and released soon. I think there are lots of people still using Python 2, often without explicitly choosing to do so but via provided systems like Amazon Linux 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants