Module installieren.

L I V E Stammtisch ab 20:30 Uhr im Chat
  • Hallo zusammen,

    ich habe einen Pi 4 Model B Rev 1.5 (Revision : b03115 mit Pi reference 2023-02-21) und möchte ein Python Script (*.pyw als Endung) zum Laufen bekommen, was aber nicht von mir ist. (Ich bin nur Anwender)

    Die Infos vom damaligen Entwickler waren

    Das Script wurde unter Python 3.7 begonnen und läuft aktuell unter Python 3.9.

    Es werden folgende Software-Module importiert/benutzt:

    import time

    import math

    import mouse

    import csv

    import tkinter as tk

    from tkinter import ttk

    from tkVideoPlayer import TkinterVideo

    from os import system

    from threading import Timer, Thread

    from PIL import Image, ImageTk

    import smbus

    import board

    import busio

    import digitalio

    from adafruit_mcp230xx.mcp23017 import MCP23017

    Wenn ich in IDLE (siehe Anhang) das Script starte kommt die Meldung:

    Traceback (most recent call last):

    File "/home/pi/Desktop/CRM_Game_V1.0.pyw", line 18, in <module>

    from tkVideoPlayer import TkinterVideo

    File "/usr/local/lib/python3.9/dist-packages/tkVideoPlayer/__init__.py", line 1, in <module>

    from tkVideoPlayer.tkvideoplayer import TkinterVideo

    File "/usr/local/lib/python3.9/dist-packages/tkVideoPlayer/tkvideoplayer.py", line 6, in <module>

    from PIL import ImageTk, Image, ImageOps

    ImportError: cannot import name 'ImageTk' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)

    >>>

    Soweit ich das jetzt durch Anlesen verstanden habe, benötigt er die Module und die fehlen.

    Am Anfang hat er auch nach "mouse" gefragt. Das habe ich dann mit

    Code
    sudo pip3 install mouse

    installiert und es scheint geklappt zu haben.

    Wenn ich aber andere installiere kommen Fehlermeldungen wie:

    Code
    pi@crm:~ $ sudo pip3 install imageTk
    Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
    ERROR: Could not find a version that satisfies the requirement imageTk
    ERROR: No matching distribution found for imageTk

    Kann mir jemand helfen bzw. sagen was ich falsch mache bzw. wo ich suchen muss/bzw. machen muss?

    Herzlichen Dank.

  • from PIL import ImageTk, Image, ImageOps

    Versuch mal mit

    Code
     sudo apt install python3-pil


    //Edit

    keepfear Bist Du mit pillow sicher? Weil:

    Warning

    Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.

  • OK, vielen Dank für die schnelle HIlfe. Das

    Code
     sudo apt install python3-pil

    hab ich jetzt noch nicht ausgeführt. Die pip Liste lautet

  • klappt nicht wirklich würde ich sagen

  • hyle Man kann PIL und Pillow nicht gleichzeitig installieren, aber wenn über pip installiert wird, dann ist es tatsächlich Pillow. Was ich persönlich auch immer mache, weil PIL schon ziemlich abgestanden ist und 2009 das letzte mal was daran gemacht wurde, während Pillow aktiv weiterentwickelt wird.

    Edit: Ui, wusste ich bis eben gar nicht: Der Autor von PIL ist im November 2021 gestorben. Da wird auch in Zukunft ganz sicher nichts mehr weiterentwickelt: https://pillow.readthedocs.io/en/stable/rele…l#fredrik-lundh

    “Dawn, n.: The time when men of reason go to bed.” — Ambrose Bierce, “The Devil's Dictionary”

    Einmal editiert, zuletzt von __blackjack__ (29. März 2023 um 22:27)

  • Man kann PIL und Pillow nicht gleichzeitig installieren, aber wenn über pip installiert wird, dann ist es tatsächlich Pillow

    Ja ich weiß (Little Britain)! :lol: Siehe Edit in Beitrag #3.

    Btw. Bei mir war PIL schon per apt installiert und ich glaube auch nicht, das ich das mal manuell instaliert hatte.

    Dann vielleicht andersherum rangehen und python3-pil purgen?! :conf:

  • Zitat

    PermissionError: [Errno 13] Keine Berechtigung: '/usr/lib/python3/dist-packages/PIL' -> '/tmp/pip-uninstall-ndfgyrba'

    Pakete via PIP als Root zu installieren, bringt das OS ganz schön durcheinander. In dist-packages werden die Python-Module durch den Paketmanager apt-get installiert, aber nicht direkt via pip. Also erst deinstallieren (mit sudo pip) das falsch installierte Paket deinstallieren.

    Zur Sicherheit auch noch mal das Paket python3-pil mit apt-get deinstallieren:

    Code
    sudo python3 -m pip uninstall pil pillow
    # beides müsste gehen pil oder pillow
    
    sudo apt-get purge python3-pil
    sudo apt-get install python3-pil

    Dann sollte das Modul von der Distribution installiert werden und global verfügbar sein.

    Eine andere Methode, die fast immer funktioniert und für Projekte bevorzugt verwendet werden sollte, sind venvs.

    Code
    python3 -m venv my_env
    source my_env/bin/activate
    pip install pillow 
    
    # ggf. später das venv deaktiveren
    deactivate

    Wenn man dann z.B. ein Programm mit dem venv laufen lassen will, kann man auch direkt den symlink des Interpreters addressieren oder mit activate arbeiten.

    Variante 1:

    Code
    my_venv/bin/python mein_programm.py

    Variante 2:

    Code
    source my_venv/bin/activate
    python mein_programm.py
  • Also ich bin jetzt @DeaD_EyE 's Vorschlag gefolgt und habe ausgeführt

    Code
    sudo python3 -m pip uninstall pil
    sudo apt-get purge python3-pil
    sudo apt-get install python3-pil

    danach bin ich der Empfehlung autoremove gefolgt und er hat nicht genutze Dateien entfernt.

    pip list bringt jetzt:

    Aber wenn ich das Script starte mit IDLE SHell 3.9.2

    kommt immer noch:

    Traceback (most recent call last):

    File "/home/pi/Desktop/CRM_Game_V1.0.pyw", line 18, in <module>

    from tkVideoPlayer import TkinterVideo

    File "/usr/local/lib/python3.9/dist-packages/tkVideoPlayer/__init__.py", line 1, in <module>

    from tkVideoPlayer.tkvideoplayer import TkinterVideo

    File "/usr/local/lib/python3.9/dist-packages/tkVideoPlayer/tkvideoplayer.py", line 6, in <module>

    from PIL import ImageTk, Image, ImageOps

    ImportError: cannot import name 'ImageTk' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)

    >>>

    Muss ich da jetzt noch weitere Pakete installieren? Für mich sieht das so aus als ob TkinterVideo fehlt

  • Ich hatte das

    Code
    # beides müsste gehen pil oder pillow

    als Auswahl verstanden, bei

    sudo python3 -m pip uninstall pil pillow

    ist das Ergebnis

    WARNING: Skipping pil as it is not installed.

    Found existing installation: Pillow 8.1.2

    Not uninstalling pillow at /usr/lib/python3/dist-packages, outside environment /usr

    Can't uninstall 'Pillow'. No files were found to uninstall.

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!