abarker / pdfCropMargins

pdfCropMargins -- a program to crop the margins of PDF files
Other
363 stars 35 forks source link

PyPDF2 Python package was found #50

Closed sgi1e closed 1 year ago

sgi1e commented 1 year ago

$ pdf-crop-margins input.pdf -p4 100 100 100 1000 -o output.pdf Error in pdfCropMargins: No system PyPDF2 Python package was found. Reinstall pdfCropMargins via pip or install that dependency ('pip install pypdf2'). $ pip install pypdf2 --user Requirement already satisfied: pypdf2 in /home/ti/.local/lib/python3.6/site-packages (2.12.1) Requirement already satisfied: typing_extensions>=3.10.0.0 in /home/ti/.local/lib/python3.6/site-packages (from pypdf2) (4.1.1) Requirement already satisfied: dataclasses in /home/ti/.local/lib/python3.6/site-packages (from pypdf2 ) (0.8)

$ pip show PyPDF2 Name: PyPDF2 Version: 2.12.1 Summary: A pure-python PDF library capable of splitting, merging, cropping, and transforming PDF files Home-page: Author: Author-email: Mathieu Fenniak biziqe@mathieu.fenniak.net License:Location: /home/ti/.local/lib/python3.6/site-packages Requires: dataclasses, typing_extensions Required-by: pdfCropMargins

$ python3 -c "import PyPDF2; print(PyPDF2.__version__)" 2.12.1

$ pdf-crop-margins Error in pdfCropMargins: No system PyPDF2 Python package was found. Reinstall pdfCropMargins via pip or install that dependency ('pip install pypdf2').

SO: CentOS 7

abarker commented 1 year ago

That same version of pypdf2 is working fine for me on Ubuntu. What version of pdfCropMargins are you running? Are you sure pdfCropMargins is getting installed in the same Python system as pypdf2?

abarker commented 1 year ago

You can run pdf-crop-margins --version to see which version you have installed. The latest is 1.1.15.

sgi1e commented 1 year ago

https://github.com/abarker/pdfCropMargins/issues/50#issuecomment-1456500791


Yes, in pip and pip3.

sgi1e commented 1 year ago

pdf-crop-margins --version

$ pdf-crop-margins --version Error in pdfCropMargins: No system PyPDF2 Python package was found. Reinstall pdfCropMargins via pip or install that dependency ('pip install pypdf2').

$ pip show pdfCropMargins Name: pdfCropMargins Version: 1.0.5 Summary: A command-line program to crop the margins of PDF files, with many options. Home-page: https://github.com/abarker/pdfCropMargins Author: Allen Barker Author-email: Allen.L.Barker@gmail.com License: GPL Location: /home/ti/.local/lib/python3.6/site-packages Requires: pillow, PyPDF2, wheel Required-by:

abarker commented 1 year ago

This is likely the problem: Version: 1.0.5. That's a pretty old version and PyPDF2 changed some of their naming since then. Try updating with pip install pdfcropmargins --user --upgrade.

sgi1e commented 1 year ago

$ pip install pdfcropmargins --user --upgrade Requirement already satisfied: pdfcropmargins in ./.local/lib/python3.6/site-packages (1.0.5) Collecting pdfcropmargins Downloading pdfCropMargins-1.1.15-py2.py3-none-any.whl (1.8 MB) |████████████████████████████████| 1.8 MB 8.1 MB/s 01 Downloading pdfCropMargins-1.1.14-py2.py3-none-any.whl (1.8 MB) |████████████████████████████████| 1.8 MB 61.3 MB/s 01 Using cached pdfCropMargins-1.1.13-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.12-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.11-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.10-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.9-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.8-py2.py3-none-any.whl (1.8 MB) Requirement already satisfied: PyPDF2>=2.11.0 in ./.local/lib/python3.6/site-packages (from pdfcropmargins) (2.12.1) Using cached pdfCropMargins-1.1.7-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.6-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.5-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.4-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.3-py2.py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.2-py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.1-py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.1.0-py3-none-any.whl (1.8 MB) Using cached pdfCropMargins-1.0.9.tar.gz (1.8 MB) Preparing metadata (setup.py) ... done Requirement already satisfied: wheel in ./.local/lib/python3.6/site-packages (from pdfcropmargins) (0.37.1) Using cached pdfCropMargins-1.0.8.tar.gz (1.8 MB) Preparing metadata (setup.py) ... done Using cached pdfCropMargins-1.0.7.tar.gz (1.8 MB) Preparing metadata (setup.py) ... done Using cached pdfCropMargins-1.0.6.tar.gz (1.8 MB) Preparing metadata (setup.py) ... done Requirement already satisfied: pillow>=7.1.0 in ./.local/lib/python3.6/site-packages (from pdfcropmargins) (8.4.0) Requirement already satisfied: typing_extensions>=3.10.0.0 in ./.local/lib/python3.6/site-packages (from PyPDF2>=2.11.0->pdfcropmargins) (4.1.1) Requirement already satisfied: dataclasses in ./.local/lib/python3.6/site-packages (from PyPDF2>=2.11.0->pdfcropmargins) (0.8)

$ pdf-crop-margins --version Error in pdfCropMargins: No system PyPDF2 Python package was found. Reinstall pdfCropMargins via pip or install that dependency ('pip install pypdf2').

$ pip install pypdf2 --user --upgrade Requirement already satisfied: pypdf2 in ./.local/lib/python3.6/site-packages (2.12.1) Collecting pypdf2 Using cached pypdf2-3.0.1-py3-none-any.whl (232 kB) Requirement already satisfied: typing_extensions>=3.10.0.0 in ./.local/lib/python3.6/site-packages (from pypdf2) (4.1.1) Requirement already satisfied: dataclasses in ./.local/lib/python3.6/site-packages (from pypdf2) (0.8) Installing collected packages: pypdf2 Attempting uninstall: pypdf2 Found existing installation: pypdf2 2.12.1 Uninstalling pypdf2-2.12.1: Successfully uninstalled pypdf2-2.12.1 Successfully installed pypdf2-3.0.1

$ pdf-crop-margins --version Error in pdfCropMargins: No system PyPDF2 Python package was found. Reinstall pdfCropMargins via pip or install that dependency ('pip install pypdf2').


This problem persist ;-;

abarker commented 1 year ago

The current version of pdfCropMargins does not work with pypdf2.3 versions.

I'm not sure what's going on with all those cached versions on your machine. Maybe try installing without the cache, with either pip cache purge or the --no-cache-dir option (see this stackoverflow question).

Try these steps:

pip install --user -U pip # if your pip is older than 6.0
pip install --user --no-cache-dir -U pip # if your pip is 6.0 or greater

pip uninstall pypdf2
pip install --user --no-cache-dir -U pdfcropmargins

Consider purging the cache with pip cache purge if the above fixes the problem.

sgi1e commented 1 year ago

I did all the steps, but the problem persists :/


¿The problem is version python?

# python --version Python 2.7.5

sgi1e commented 1 year ago

Changed version python to 3.6.8 and uninstall pdfCropMargins. Executed $ pip install pdfcropmargins --user --upgrade. Result installed PyPDF2-3.0.1 pdfcropmargins-1.0.5


Executed $ pip install --upgrade --user --no-cache-dir -U pdfCropMargins==1.1.15. Collecting pdfCropMargins==1.1.15 Downloading pdfCropMargins-1.1.15-py2.py3-none-any.whl (1.8 MB) |████████████████████████████████| 1.8 MB 4.7 MB/s Collecting PyPDF2<3.0.0,>=2.11.0 Downloading pypdf2-2.12.1-py3-none-any.whl (222 kB) |████████████████████████████████| 222 kB 51.4 MB/s Collecting PySimpleGUI>=4.40.0 Downloading PySimpleGUI-4.60.4-py3-none-any.whl (509 kB) |████████████████████████████████| 509 kB 31.0 MB/s Requirement already satisfied: wheel in ./.local/lib/python3.6/site-packages (from pdfCropMargins==1.1.15) (0.37.1) ERROR: Could not find a version that satisfies the requirement PyMuPDF>=1.20.0 (from pdfcropmargins) (from versions: 1.11.2, 1.12.5, 1.13.20, 1.14.19.post2, 1.14.19.2, 1.14.20, 1.14.21, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.16.7, 1.16.8, 1.16.8.1, 1.16.9, 1.16.10, 1.16.11, 1.16.12, 1.16.13, 1.16.14, 1.16.15, 1.16.16, 1.16.17, 1.16.18, 1.17.0, 1.17.1, 1.17.2, 1.17.3, 1.17.4, 1.17.5, 1.17.6, 1.17.7, 1.18.0, 1.18.1, 1.18.2, 1.18.3, 1.18.4, 1.18.5, 1.18.6, 1.18.7, 1.18.8, 1.18.9, 1.18.10, 1.18.11, 1.18.12, 1.18.13, 1.18.14, 1.18.15, 1.18.16, 1.18.17, 1.18.18, 1.18.19, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.19.5, 1.19.6, 1.20.0rc1) ERROR: No matching distribution found for PyMuPDF>=1.20.0

sgi1e commented 1 year ago

$ pip install --upgrade --user --no-cache-dir -U PyMuPDF

Collecting PyMuPDF Downloading PyMuPDF-1.19.6.tar.gz (2.3 MB) |████████████████████████████████| 2.3 MB 7.6 MB/s Preparing metadata (setup.py) ... done Building wheels for collected packages: PyMuPDF Building wheel for PyMuPDF (setup.py) ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/setup.py'"'"'; file='"'"'/tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-p_435ts9 cwd: /tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/ Complete output (20 lines): running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.6 creating build/lib.linux-x86_64-3.6/fitz copying fitz/init.py -> build/lib.linux-x86_64-3.6/fitz copying fitz/fitz.py -> build/lib.linux-x86_64-3.6/fitz copying fitz/utils.py -> build/lib.linux-x86_64-3.6/fitz copying fitz/main.py -> build/lib.linux-x86_64-3.6/fitz running build_ext building 'fitz._fitz' extension creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/fitz gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/mupdf -I/usr/local/include/mupdf -Imupdf/thirdparty/freetype/include -I/usr/include/freetype2 -I/usr/include/python3.6m -c fitz/fitz_wrap.c -o build/temp.linux-x86_64-3.6/fitz/fitz_wrap.o fitz/fitz_wrap.c:154:21: fatal error: Python.h: No such file or directory

include

                   ^

compilation terminated. error: command 'gcc' failed with exit status 1

ERROR: Failed building wheel for PyMuPDF Running setup.py clean for PyMuPDF Failed to build PyMuPDF Installing collected packages: PyMuPDF Running setup.py install for PyMuPDF ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/setup.py'"'"'; file='"'"'/tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-j_1p972h/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ipscdo/.local/include/python3.6m/PyMuPDF cwd: /tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/ Complete output (20 lines): running install running build running build_py creating build creating build/lib.linux-x86_64-3.6 creating build/lib.linux-x86_64-3.6/fitz copying fitz/init.py -> build/lib.linux-x86_64-3.6/fitz copying fitz/fitz.py -> build/lib.linux-x86_64-3.6/fitz copying fitz/utils.py -> build/lib.linux-x86_64-3.6/fitz copying fitz/main.py -> build/lib.linux-x86_64-3.6/fitz running build_ext building 'fitz._fitz' extension creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/fitz gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/mupdf -I/usr/local/include/mupdf -Imupdf/thirdparty/freetype/include -I/usr/include/freetype2 -I/usr/include/python3.6m -c fitz/fitz_wrap.c -o build/temp.linux-x86_64-3.6/fitz/fitz_wrap.o fitz/fitz_wrap.c:154:21: fatal error: Python.h: No such file or directory

include

                     ^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------

ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/setup.py'"'"'; file='"'"'/tmp/pip-install-2mnbda0r/pymupdf_df9640ad05114668b310c813f9e536f0/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install--record /tmp/pip-record-j_1p972h/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ipscdo/.local/include/python3.6m/PyMuPDF Check the logs for full command output.


¿This problem is in SO CentOS 7?

sgi1e commented 1 year ago

Changed version python to 3.6.8 and uninstall pdfCropMargins. Executed $ pip install pdfcropmargins --user --upgrade. Result installed PyPDF2-3.0.1 pdfcropmargins-1.0.5

PD: I reverted python version 2.7.5 because yum crashed 🫠🙂

abarker commented 1 year ago

You definitely need Python 3.6 or later to run a recent version of pdfCropMargins. When you did pip show pdfCropMargins earlier the program was in the ~/.local/lib/python3.6/site-packages directory where it should have been.

The pypdf2 code still supports Python 3.6, but unfortunately the current PyMuPDF requires Python 3.7. There may be old PyMuPDF wheels for Python 3.6 that still work. What happens if you simply run pip install -U pymupdf? (The basic cropping part of pdfCropMargins doesn't need PyMuPDF as long as you have ghostscript or pdftoppm installed, but the GUI does require PyMuPDF.)

You can try installing pdfCropMargins alone with pip install --user --no-cache-dir --no-deps pdfCropMargins==1.1.15 and the other dependencies separately.

Alternately, you could try to install a more recent version of Python. There might be one in your repos, or there's pyenv (https://github.com/pyenv/pyenv).

sgi1e commented 1 year ago

Thank you very much for your great help. We have made the decision to change the distribution.

abarker commented 1 year ago

I tried installing on an old machine running Python 3.6 and I got the same sort of errors. I lowered the requirement for PyMuPDF to the last version supporting 3.6, but that didn't fix the problem. I found that the Pillow dependency also no longer supports 3.6. In this case lowering the requirement would cause security warnings for my repo, so I'm hesitant to lower it in setup.py.

I got it to work using this command:

pip install --no-deps --user --upgrade wheel pdfcropmargins pysimplegui pillow "pypdf2<3.0" "pymupdf==1.19"
sgi1e commented 1 year ago

Indeed, this can create security holes. So it is better not to demote it. Thank you very much for the follow up 😃😃. In a few days we are going to change the distribution.