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

ImportError: cannot import name '_imaging' #4982

Closed
AndreasLuckert opened this issue Oct 15, 2020 · 15 comments
Closed

ImportError: cannot import name '_imaging' #4982

AndreasLuckert opened this issue Oct 15, 2020 · 15 comments
Labels
Installation Usually a problem with … Linux

Comments

@AndreasLuckert
Copy link

What did you do?

I converted a PNG to a jp2-file via convert sample.png -quality 0 sample.jp2.
Next, I wanted to convert the resulting jp2-file to a proper PDF:
img2pdf -o sample.pdf sample.jp2

What did you expect to happen?

The jp2-image should have been converted to a PDF via the command img2pdf -o sample.pdf sample.jp2.

What actually happened?

The following error occurred:

User$ img2pdf -o sample.pdf sample.jp2
Traceback (most recent call last):
  File "/usr/bin/img2pdf", line 11, in <module>
    load_entry_point('img2pdf==0.2.3', 'console_scripts', 'img2pdf')()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 473, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2447, in load
    return self.resolve()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2453, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/img2pdf.py", line 24, in <module>
    from PIL import Image
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging'

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 18.04

  • Python: Python 3.8.5 (default, Jul 22 2020, 18:54:26)
    [GCC 5.4.0 20160609] on linux

  • Pillow:
    Version: 7.2.0
    Summary: Python Imaging Library (Fork)
    Home-page: https://python-pillow.org
    Author: Alex Clark (PIL Fork Author)
    Author-email: aclark@python-pillow.org
    License: HPND
    Location: /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages
    Requires:
    Required-by: scikit-image, matplotlib, imageio, geos, bokeh

@radarhere radarhere changed the title from . import _imaging as core --> ImportError: cannot import name '_imaging' ImportError: cannot import name '_imaging' Oct 15, 2020
@radarhere
Copy link
Member

Hi. Could you provide some detail on how you installed Pillow?

@radarhere radarhere added the Installation Usually a problem with … label Oct 15, 2020
@AndreasLuckert
Copy link
Author

I installed it with linuxbrew and pip.
If you need any specific output, please let me know.

@radarhere
Copy link
Member

radarhere commented Oct 15, 2020

Knowing the specific commands that you've run could be helpful, and the output of those commands as well ideally.

Two ideas

  • Could you check that if you uninstall Pillow, and then try to import PIL, that it fails with ModuleNotFoundError? This assures us that you don't have both PIL (before our fork) and Pillow installed simultaneously, or something odd like that.
  • Could you try upgrading pip and then re-installing Pillow?

@AndreasLuckert
Copy link
Author

I played around a bit to find out more about the issue.

First, I started python in a standard UNIX-terminal.

andylu@andylu-ThinkPad-Edge-E130:~$ python
Python 3.8.5 (default, Jul 22 2020, 18:54:26) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

Next, I confirmed that it is still that counterintuitive that the "pillow" package needs to imported with "import PIL" in python.

>>> import pil
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pil'
>>> import pillow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pillow'

>>> import PIL
# Astoundingly, the Image script will be imported without the failure which gave rise to this thread initially.
>>> from PIL import Image
>>> Image
<module 'PIL.Image' from '/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/Image.py'>
>>> quit()

So why is that?
First, let's uninstall pillow as required.

andylu@andylu-ThinkPad-Edge-E130:~$ pip uninstall PIL
WARNING: Skipping PIL as it is not installed.
andylu@andylu-ThinkPad-Edge-E130:~$ pip uninstall pillow
Found existing installation: Pillow 7.2.0
Uninstalling Pillow-7.2.0:
  Would remove:
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/*
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow-7.2.0.dist-info/*
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libXau-312dbc56.so.6.0.0
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libXdmcp-e15573e7.so.6.0.0
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libfreetype-b35627f5.so.6.17.2
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libjpeg-ba7bf5af.so.9.4.0
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/liblcms2-db671c5b.so.2.0.10
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/liblzma-99449165.so.5.2.5
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libopenjp2-b3d7668a.so.2.3.1
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libpng16-bedcb7ea.so.16.37.0
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libtiff-41910f6d.so.5.5.0
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libwebp-122bd20b.so.7.1.0
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libwebpdemux-2db559e5.so.2.0.6
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libwebpmux-ec1d5c76.so.3.0.5
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libxcb-2dfad6c3.so.1.1.0
    /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs/libz-a147dcb0.so.1.2.3
Proceed (y/n)? y
  Successfully uninstalled Pillow-7.2.0

Next, start python again in the terminal and try to import pillow.

andylu@andylu-ThinkPad-Edge-E130:~$ python
Python 3.8.5 (default, Jul 22 2020, 18:54:26) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
# Weirdly enough it works, so there must indeed be a parallel installation of pillow somewhere on the system.
>>> import PIL
>>> quit()

Let's find out where it is with the magical "find"-command:

# Indeed there are still some installations on the system.
andylu@andylu-ThinkPad-Edge-E130:~$ sudo find / -type d -path "*/Pil*"
/usr/lib/python3/dist-packages/Pillow-5.1.0.egg-info
/usr/lib/python2.7/dist-packages/Pillow-5.1.0.egg-info

# Also under the name "PIL" apart from "pillow".
# NOTE: my main and favorite package manager to use is linuxbrew, the other directories are from the UNIX-system directly.
andylu@andylu-ThinkPad-Edge-E130:~$ sudo find / -type d -path "*/PIL*"
/usr/lib/python3/dist-packages/PIL
/usr/lib/python3/dist-packages/PIL/__pycache__
/usr/lib/python2.7/dist-packages/PIL
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/__pycache__

# Now, try to uninstall the pillow package again, this time using sudo since it's located in the system-python-directory.
andylu@andylu-ThinkPad-Edge-E130:~$ sudo -H pip uninstall pillow
Uninstalling Pillow-5.1.0:
  Would remove:
    /usr/lib/python3/dist-packages/PIL
    /usr/lib/python3/dist-packages/Pillow-5.1.0.egg-info
Proceed (y/n)? y
  Successfully uninstalled Pillow-5.1.0

Try again to import the pillow package in a python environment.

andylu@andylu-ThinkPad-Edge-E130:~$ python
Python 3.8.5 (default, Jul 22 2020, 18:54:26) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
# It still works, so there must be more to uninstall/delete.
>>> import PIL
>>> quit()

Since it is not installed anymore on the system..

andylu@andylu-ThinkPad-Edge-E130:~$ pip uninstall pillow
WARNING: Skipping pillow as it is not installed.

.. the next thing to do is removing the remainders directly:

# First check for the contents
andylu@andylu-ThinkPad-Edge-E130:~$ ls -R /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL:
__pycache__

/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/__pycache__:
_binary.cpython-36.pyc    __init__.cpython-36.pyc  _version.cpython-36.pyc
Image.cpython-36.pyc      TiffTags.cpython-36.pyc
ImageMode.cpython-36.pyc  _util.cpython-36.pyc

# Delete contents and folder itself
andylu@andylu-ThinkPad-Edge-E130:~$ rm -r /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL

# Check again whether removal was successful
andylu@andylu-ThinkPad-Edge-E130:~$ ls -R /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL
ls: cannot access '/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL': No such file or directory

FINAL CHECK for "import PIL".
Should produce an ModuleNotFoundError now.

andylu@andylu-ThinkPad-Edge-E130:~$ python
Python 3.8.5 (default, Jul 22 2020, 18:54:26) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
# Indeed, it does finally.
>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PIL'
>>> quit()

This also shows up, when executing the initial command:

andylu@andylu-ThinkPad-Edge-E130:~/Desktop/Master_project/WWTP La Oliva/Top_view_of_WWTP$ img2pdf -o sample.pdf sample.jp2
Traceback (most recent call last):
  File "/usr/bin/img2pdf", line 11, in <module>
    load_entry_point('img2pdf==0.2.3', 'console_scripts', 'img2pdf')()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 473, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2447, in load
    return self.resolve()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2453, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/img2pdf.py", line 24, in <module>
    from PIL import Image
ModuleNotFoundError: No module named 'PIL'

Next, I'm going to upgrade pip, as required

andylu@andylu-ThinkPad-Edge-E130:~$ pip install --upgrade pip
Requirement already up-to-date: pip in /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages (20.2.3)

Then, I'm reinstalling the pillow package:

andylu@andylu-ThinkPad-Edge-E130:~$ pip install pillow
Collecting pillow
  Downloading Pillow-8.0.0-cp38-cp38-manylinux1_x86_64.whl (2.2 MB)
     |████████████████████████████████| 2.2 MB 2.1 MB/s 
Installing collected packages: pillow
Successfully installed pillow-8.0.0

Now, testing again the intially failed command, which will unfortunately fail again for the same reason:

andylu@andylu-ThinkPad-Edge-E130:~/Desktop/Master_project/WWTP La Oliva/Top_view_of_WWTP$ img2pdf -o sample.pdf sample.jp2
Traceback (most recent call last):
  File "/usr/bin/img2pdf", line 11, in <module>
    load_entry_point('img2pdf==0.2.3', 'console_scripts', 'img2pdf')()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 473, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2447, in load
    return self.resolve()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2453, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/img2pdf.py", line 24, in <module>
    from PIL import Image
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging'

Yet and again, it's possible to import the PIL package and its Image-script flawlessly in a standard python environment

andylu@andylu-ThinkPad-Edge-E130:~/Desktop/Master_project/WWTP La Oliva/Top_view_of_WWTP$ python
Python 3.8.5 (default, Jul 22 2020, 18:54:26) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> from PIL import Image
>>> quit()

Checking again where the pillow packages are installed.
It shows that they have only been installed where they were supposed to be,
i.e. in the linuxbrew site-packages.
NOTE: the python2.7 - directory should not matter in all of these cases

andylu@andylu-ThinkPad-Edge-E130:~$ sudo find / -type d -path "*/PIL*"
[sudo] password for andylu: 
/usr/lib/python2.7/dist-packages/PIL
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/__pycache__

andylu@andylu-ThinkPad-Edge-E130:~$ sudo find / -type d -path "*/Pil*"
/usr/lib/python2.7/dist-packages/Pillow-5.1.0.egg-info
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow-8.0.0.dist-info
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/Pillow.libs

By and large, the same question remains as I initially posed:
where does the error ImportError: cannot import name '_imaging' come from in this specific context
when at the same time it doesn't occur in a standard console python3 - environment?

@radarhere
Copy link
Member

I think the fact that console python3 can import it successfully indicates that the problem isn't with your Pillow installation as such - I think img2pdf hasn't correctly packaged Pillow into /usr/bin/img2pdf

@AndreasLuckert
Copy link
Author

Yes, this could be true. Thanks for your help.

@josch
Copy link

josch commented Oct 16, 2020

Hi, img2pdf author here. I'm not saying that this is a PIL bug but @AndreasLuckert just opened an issue against img2pdf and I do not see how this can possibly be a bug in img2pdf. Given this backtrace:

Traceback (most recent call last):
  File "/usr/bin/img2pdf", line 11, in <module>
    load_entry_point('img2pdf==0.2.3', 'console_scripts', 'img2pdf')()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 473, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2843, in load_entry_point
    return ep.load()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2447, in load
    return self.resolve()
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2453, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/img2pdf.py", line 24, in <module>
    from PIL import Image
  File "/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging'

All that img2pdf does is to do a from PIL import Image -- what is wrong about that statement? How should img2pdf fix this?

To me this looks more like a wrong installation of PIL, no?

@josch
Copy link

josch commented Oct 16, 2020

I strongly suspect that there is something wrong with your setup. I created a ubuntu 18.04 chroot using sudo debootstrap bionic ubuntu-bionic and added the universe repository to the apt sources. Installing img2pdf using pip will not work because qpdf in ubuntu 18.04 is too old for pikepdf. Instead, I can simply run: apt install img2pdf and everything will be fine.

To test installation via pip I created a chroot of ubuntu 20.04 using debootstrap and then ran pip3 install img2pdf:

Collecting img2pdf
  Downloading img2pdf-0.4.0.tar.gz (107 kB)
     |████████████████████████████████| 107 kB 5.8 MB/s 
Collecting Pillow
  Downloading Pillow-8.0.0-cp38-cp38-manylinux1_x86_64.whl (2.2 MB)
     |████████████████████████████████| 2.2 MB 10.0 MB/s 
Collecting pikepdf
  Downloading pikepdf-1.19.3-cp38-cp38-manylinux2010_x86_64.whl (10.1 MB)
     |████████████████████████████████| 10.1 MB 19.2 MB/s 
Collecting lxml>=4.0
  Downloading lxml-4.5.2-cp38-cp38-manylinux1_x86_64.whl (5.4 MB)
     |████████████████████████████████| 5.4 MB 85.3 MB/s 
Building wheels for collected packages: img2pdf
  Building wheel for img2pdf (setup.py) ... done
  Created wheel for img2pdf: filename=img2pdf-0.4.0-py3-none-any.whl size=40500 sha256=96ec10d0826db80ec4fc45b772135aedf0a26d8ea08d845de108217c64c74283
  Stored in directory: /root/.cache/pip/wheels/f4/1e/f8/2c3c9bc7be99a752d40f8a09b5e7c7d02b1196db55b3eddd35
Successfully built img2pdf
Installing collected packages: Pillow, lxml, pikepdf, img2pdf
Successfully installed Pillow-8.0.0 img2pdf-0.4.0 lxml-4.5.2 pikepdf-1.19.3

And then tried converting some images:

$ img2pdf -o out.pdf /usr/share/doc/libexpat1-dev/expat.html/expat.png
$ echo $?
0

And out.pdf looks fine as well. So everything works on a fresh installation. So most likely something is wrong with your setup.

@radarhere
Copy link
Member

Hi. Ok, @AndreasLuckert, could you try these commands.

  • python -c "from PIL import Image" - if this fails, then there is a problem with your Pillow installation.
  • python -c "import img2pdf" - if this fails, then the problem lies between the Pillow and the img2pdf installations.

If both of those pass, but /usr/bin/img2pdf fails, then that's how I came to my idea that something has gone wrong in packaging /usr/bin/img2pdf. I had presumed that /usr/bin/img2pdf was created by the img2pdf installation - but having tried to install img2pdf myself, it's not present, so you created it some other way, right?

The output from python -c "import sys;print(sys.path)" may also help.

@josch
Copy link

josch commented Oct 16, 2020

There are two ways to install img2pdf on ubuntu 18.04. Since @AndreasLuckert has /usr/bin/img2pdf it seems they installed it using apt install and not via pip, because pip installs it into /usr/local/bin/img2pdf.

As I showed above, both methods of installing img2pdf (via apt and via pip) work just fine on a fresh Ubuntu installation. So what we are now actually trying to figure out here is what is wrong in the setup of @AndreasLuckert and not what is wrong in either img2pdf or PIL.

@AndreasLuckert
Copy link
Author

AndreasLuckert commented Oct 16, 2020

I tried to execute both commands and they worked successfully:

andylu@andylu-ThinkPad-Edge-E130:~$ python -c "from PIL import Image"
andylu@andylu-ThinkPad-Edge-E130:~$ python -c "import img2pdf"

The command revealing the system paths you suggested has the following output:

andylu@andylu-ThinkPad-Edge-E130:~$ python -c "import sys;print(sys.path)"
['', '/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages', '/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts', '/usr/lib/python3/dist-packages', '/home/andylu', '/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python38.zip', '/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8', '/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/lib-dynload', '/home/andylu/.local/lib/python3.8/site-packages', '/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/site-packages', '/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.5/lib/python3.8/site-packages/geos']

Next, checking where img2pdf has been installed:

andylu@andylu-ThinkPad-Edge-E130:~$ which img2pdf
/usr/bin/img2pdf

Check also whether it can be installed via pip:

andylu@andylu-ThinkPad-Edge-E130:~$ pip install img2pdf
Requirement already satisfied: img2pdf in /usr/lib/python3/dist-packages (0.2.3)

Finally, print out all files and directories related to img2pdf on the system:

andylu@andylu-ThinkPad-Edge-E130:~$ sudo find / -iname "*img2pdf*"
[sudo] password for andylu: 
/usr/bin/img2pdf
/usr/share/doc/img2pdf
/usr/share/doc/python3-img2pdf
/usr/share/man/man1/img2pdf.1.gz
/usr/lib/python3/dist-packages/img2pdf.py
/usr/lib/python3/dist-packages/img2pdf-0.2.3.egg-info
/usr/lib/python3/dist-packages/__pycache__/img2pdf.cpython-36.pyc
/var/lib/dpkg/info/python3-img2pdf.list
/var/lib/dpkg/info/img2pdf.list
/var/lib/dpkg/info/python3-img2pdf.md5sums
/var/lib/dpkg/info/python3-img2pdf.postinst
/var/lib/dpkg/info/python3-img2pdf.prerm
/var/lib/dpkg/info/img2pdf.md5sums
/home/andylu/.pylint.d/img2pdf1.stats

I hope this helps in further diagnosis.

@josch
Copy link

josch commented Oct 16, 2020

You installed img2pdf via apt (as proven by it being located in /usr/bin/img2pdf and by your output of pip install img2pdf) and you are mixing it with a lot of python libraries that were not installed by apt (as proven by your output of sys.path). You are thus essentially circumventing the dependency system of apt. I'm not surprised that it doesn't work. Trying running img2pdf without all the extra bits from your $HOME.

@hugovk
Copy link
Member

hugovk commented Oct 16, 2020

A general tip: use python -m pip install instead of pip install to avoid env problems: https://snarky.ca/why-you-should-use-python-m-pip/

A virtualenv (or similar) may also help isolate things.

@AndreasLuckert
Copy link
Author

So should I uninstall img2pdf via apt, then install it via python -m pip install img2pdf?

@AndreasLuckert
Copy link
Author

AndreasLuckert commented Oct 16, 2020

Finally everything works like a charm!
Thanks a lot for your time and tips.

The problem was the installation with apt instead of python -m pip.
Now all packages involved are installed in the same place in my linuxbrew directory via pip.

I uninstalled img2pdf via apt with sudo apt purge img2pdf, then installed it again via python -m pip install img2pdf.

Now, the location is correct:

andylu@andylu-ThinkPad-Edge-E130:~$ which img2pdf
/home/linuxbrew/.linuxbrew/bin/img2pdf

The final test, which worked out successfully:

andylu@andylu-ThinkPad-Edge-E130:~$ convert sample.png -quality 0 sample.jp2
andylu@andylu-ThinkPad-Edge-E130:~$ img2pdf -o sample.pdf sample.jp2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Installation Usually a problem with … Linux
Projects
None yet
Development

No branches or pull requests

4 participants