lebedov / python-pdfbox

Python interface to Apache PDFBox command-line tools.
Other
75 stars 24 forks source link

'Version' object has no attribute 'major' in macOS 11 #28

Closed somyost-ginkgo closed 3 years ago

somyost-ginkgo commented 3 years ago

I got issue 'Version' object has no attribute 'major'

Screen Shot 2564-04-09 at 15 10 31

My environment have python 3.7 java 15.0.2

lebedov commented 3 years ago

I can't reproduce this with Python 3.7.10 on MacOS 10.15.7. Can you try adding the line

print(p.result)

right before the line

versions = list(filter(lambda v: pkg_resources.parse_version(v).major<3,
                                  p.result))

in ~/opt/anaconda3/lib/python3.7/site-packages/pdfbox/__init__.py ensure that ~/Library/Caches/python-pdfbox does not exist, and try running

import pdfbox
p = pdfbox.PDFBox()

again and post what you observe?

kontrol commented 3 years ago

I actually have the same error on macOS: 10.15.7 python: 3.8.1 java: openjdk version "1.8.0_222"

I'm not using anaconda in this case.

Running print(p.result) gives the following output

['1.1.0', '1.2.0', '1.2.1', '1.3.1', '1.4.0', '1.5.0', '1.6.0', '1.7.0', '1.7.1', '1.8.0', '1.8.1', '1.8.10', '1.8.11', '1.8.12', '1.8.13', '1.8.14', '1.8.15', '1.8.16', '1.8.2', '1.8.3', '1.8.4', '1.8.5', '1.8.6', '1.8.7', '1.8.8', '1.8.9', '2.0.0-RC1', '2.0.0-RC2', '2.0.0-RC3', '2.0.0', '2.0.1', '2.0.10', '2.0.11', '2.0.12', '2.0.13', '2.0.14', '2.0.15', '2.0.16', '2.0.17', '2.0.18', '2.0.19', '2.0.2', '2.0.20', '2.0.21', '2.0.22', '2.0.23', '2.0.3', '2.0.4', '2.0.5', '2.0.6', '2.0.7', '2.0.8', '2.0.9', '3.0.0-RC1']

Running

import pdfbox
p = pdfbox.PDFBox()

Gives me the same error.

['1.1.0', '1.2.0', '1.2.1', '1.3.1', '1.4.0', '1.5.0', '1.6.0', '1.7.0', '1.7.1', '1.8.0', '1.8.1', '1.8.10', '1.8.11', '1.8.12', '1.8.13', '1.8.14', '1.8.15', '1.8.16', '1.8.2', '1.8.3', '1.8.4', '1.8.5', '1.8.6', '1.8.7', '1.8.8', '1.8.9', '2.0.0-RC1', '2.0.0-RC2', '2.0.0-RC3', '2.0.0', '2.0.1', '2.0.10', '2.0.11', '2.0.12', '2.0.13', '2.0.14', '2.0.15', '2.0.16', '2.0.17', '2.0.18', '2.0.19', '2.0.2', '2.0.20', '2.0.21', '2.0.22', '2.0.23', '2.0.3', '2.0.4', '2.0.5', '2.0.6', '2.0.7', '2.0.8', '2.0.9', '3.0.0-RC1']
Traceback (most recent call last):
  File "test_this.py", line 3, in <module>
    p = pdfbox.PDFBox()
 File "~/.venv/lib/python3.8/site-packages/pdfbox/__init__.py", line 139, in __init__
    self.pdfbox_path = self._get_pdfbox_path()
 File "~/.venv/lib/python3.8/site-packages/pdfbox/__init__.py", line 112, in _get_pdfbox_path
    pdfbox_url = self._get_latest_pdfbox_url()
 File "~/.venv/lib/python3.8/site-packages/pdfbox/__init__.py", line 80, in _get_latest_pdfbox_url
    versions = list(filter(lambda v: pkg_resources.parse_version(v).major<3,
 File "~/.venv/lib/python3.8/site-packages/pdfbox/__init__.py", line 80, in <lambda>
    versions = list(filter(lambda v: pkg_resources.parse_version(v).major<3,
AttributeError: 'Version' object has no attribute 'major'
somyost-ginkgo commented 3 years ago

I can't reproduce this with Python 3.7.10 on MacOS 10.15.7. Can you try adding the line

print(p.result)

right before the line

versions = list(filter(lambda v: pkg_resources.parse_version(v).major<3,
                                  p.result))

in ~/opt/anaconda3/lib/python3.7/site-packages/pdfbox/__init__.py ensure that ~/Library/Caches/python-pdfbox does not exist, and try running

import pdfbox
p = pdfbox.PDFBox()

again and post what you observe?

I got this ['1.1.0', '1.2.0', '1.2.1', '1.3.1', '1.4.0', '1.5.0', '1.6.0', '1.7.0', '1.7.1', '1.8.0', '1.8.1', '1.8.10', '1.8.11', '1.8.12', '1.8.13', '1.8.14', '1.8.15', '1.8.16', '1.8.2', '1.8.3', '1.8.4', '1.8.5', '1.8.6', '1.8.7', '1.8.8', '1.8.9', '2.0.0-RC1', '2.0.0-RC2', '2.0.0-RC3', '2.0.0', '2.0.1', '2.0.10', '2.0.11', '2.0.12', '2.0.13', '2.0.14', '2.0.15', '2.0.16', '2.0.17', '2.0.18', '2.0.19', '2.0.2', '2.0.20', '2.0.21', '2.0.22', '2.0.23', '2.0.3', '2.0.4', '2.0.5', '2.0.6', '2.0.7', '2.0.8', '2.0.9', '3.0.0-RC1']

lebedov commented 3 years ago

@kontrol Strange - I can't replicate the error with Python 3.8.2 from conda-forge. It seems that the Version class returned by pkg_resources.parse_version() in the Python 3.8.2 that comes with MacOS doesn't have the same attributes as the one in conda-forge:

MacOS:

Python 3.8.2 (default, Nov  4 2020, 21:23:28)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> dir(pkg_resources.parse_version('1.1.0'))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_compare', '_key', '_regex', '_version', 'base_version', 'is_postrelease', 'is_prerelease', 'local', 'public']

conda-forge:

Python 3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 07:56:27)
[Clang 9.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> dir(pkg_resources.parse_version('1.1.0'))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_compare', '_key', '_regex', '_version', 'base_version', 'dev', 'epoch', 'is_devrelease', 'is_postrelease', 'is_prerelease', 'local', 'major', 'micro', 'minor', 'post', 'pre', 'public', 'release']
dalaomai commented 3 years ago

I got same problem in Centos7.

Python 3.7.0 (default, Oct 14 2020, 02:26:46) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import p
KeyboardInterrupt
>>> import pkg_resources
>>> dir(pkg_resources.parse_version('1.1.0'))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_compare', '_key', '_regex', '_version', 'base_version', 'is_postrelease', 'is_prerelease', 'local', 'public']
java 16.0.1 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)
thorge commented 3 years ago

Same AttributeError: 'Version' object has no attribute 'major' here on Ubuntu 20.04:

Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> dir(pkg_resources.parse_version('1.1.0'))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_compare', '_key', '_regex', '_version', 'base_version', 'is_postrelease', 'is_prerelease', 'local', 'public']

For a workaround see PR https://github.com/lebedov/python-pdfbox/pull/29 by @bgiesbrecht

lebedov commented 3 years ago

PR applied.