AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Wie Embedded-Python und PIP?

Ein Thema von himitsu · begonnen am 13. Jul 2023 · letzter Beitrag vom 12. Jan 2024
 
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.202 Beiträge
 
Delphi 12 Athens
 
#1

Wie Embedded-Python und PIP?

  Alt 13. Jul 2023, 22:33
Ich würde den PackageManager gern benutzen, aber er hasst mich.




Gegeben: Python 3.8.10 Embedded 32-bit + Python4Delphi
Das P4D damals aus GitHub, bzw. hier aus'm Forum (nicht das Neue vom GetIt, k.A. ob es da Unterschiede gibt).

Also im Prinzip das https://www.python.org/ftp/python/3....mbed-win32.zip als pures Verzeichnis.

(Unser Python4Delphi ist zwar bissl angepasst, damit es mit dem Embedded besser geht, weil der Entwickler vorrangig auf ein installiertes Python bedacht war, aber egal ... wir wollten einfach keine externen Abhängigkeiten, wenn z.B. der Kunde bei sich eine andere Python-Version installiert)




Und nun versuchte ich dort via PIP etwas zu "installieren".
z.B. python.exe -m pip install requests des https://pypi.org/project/requests/
So geht das erstmal natürlich nicht, denn es fehlt ja das Modul "pip".

Für das Nachfolgende ist das Embedded (EXE oder DLL im Delphi) egal irrelevant. (unnötig aufwändig, extra noch eine Test-Anwendung in Delphi)
Die python.exe wird also erstmal als "Portable" benutzt. (macht für die Funktion keinen Unterschied)


Einige Standardsachen (Python-Scripts und Modules) liegen als *.pyc in der python38.zip, sowie als *.pyd im Verzeichnis)


PS: Ja, im Python wird ein Modul "request" mitgeliefert (python38.zip), aber benötigt wird "requests".




Versuch 1: https://pip.pypa.io/en/stable/installation/#get-pip-py

Die https://bootstrap.pypa.io/get-pip.py runtergeladen, ins Verzeichnis gelegt
und python.exe get-pip.py macht etwas, lädt es runter und es sieht so aus, als würde es installiert.
Code:
Collecting pip
  Downloading pip-23.1.2-py3-none-any.whl (2.1 MB)
     ------------------------------------------------- 2.1/2.1 MB 11.9 MB/s eta 0:00:00
Collecting setuptools
  Downloading setuptools-68.0.0-py3-none-any.whl (804 kB)
     ------------------------------------------------- 804.0/804.0 kB 24.8 MB/s eta 0:00:00
Collecting wheel
  Downloading wheel-0.40.0-py3-none-any.whl (64 kB)
     ------------------------------------------------- 64.5/64.5 kB ? eta 0:00:00
Installing collected packages: wheel, setuptools, pip
  WARNING: The script wheel.exe is installed in 'C:\*****\Python3\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts pip.exe, pip3.8.exe and pip3.exe are installed in 'C:\*****\Python3\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.1.2 setuptools-68.0.0 wheel-0.40.0
es sind in .\Scripts\ ein paar *.exe aufgetaucht
und unter .\Lib\site-packages\ Unterverzeichnisse mit den 3 runtergeladenen Modulen und weitere Dateien/Verzeichnisse von der Packageverwaltung.

aber python.exe -m pip install requests sagt immernoch, dass es kein PIP gäbe.
Zitat:
python.exe: No module named pip
sowie auch .\Scripts\pip.exe sagt das Gleiche.
Zitat:
ModuleNotFoundError: No module named 'pip'



So, also nun Versuch 2: ebenfalls https://pip.pypa.io/en/stable/installation/#get-pip-py

Die https://bootstrap.pypa.io/pip/pip.pyz runterladen
und python.exe pip.pyz install requests
Code:
Collecting requests
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ------------------------------------------------- 62.6/62.6 kB 1.6 MB/s eta 0:00:00
Collecting charset-normalizer<4,>=2 (from requests)
  Downloading charset_normalizer-3.2.0-cp38-cp38-win32.whl (89 kB)
     ------------------------------------------------- 89.4/89.4 kB 2.6 MB/s eta 0:00:00
Collecting idna<4,>=2.5 (from requests)
  Downloading idna-3.4-py3-none-any.whl (61 kB)
     ------------------------------------------------- 61.5/61.5 kB 814.3 kB/s eta 0:00:00
Collecting urllib3<3,>=1.21.1 (from requests)
  Downloading urllib3-2.0.3-py3-none-any.whl (123 kB)
     ------------------------------------------------- 123.6/123.6 kB 3.7 MB/s eta 0:00:00
Collecting certifi>=2017.4.17 (from requests)
  Downloading certifi-2023.5.7-py3-none-any.whl (156 kB)
     ------------------------------------------------- 157.0/157.0 kB 2.3 MB/s eta 0:00:00
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests
  WARNING: The script normalizer.exe is installed in 'C:\*****\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2023.5.7 charset-normalizer-3.2.0 idna-3.4 requests-2.31.0 urllib3-2.0.3
Hier wird "scheinbar" auch das Gewünschte runtergeladen,
also in .\Scripts\ eine *.exe
und unter .\Lib\site-packages\ das "requests" und dessen Requires (certifi, charset_normalizer, idna und urllib3).

Aber es geht dann dennoch nicht, also wird nicht gefunden.




Dann jetzt mal Testen. (Anhand dem 2. Versuch)
Per Parameter, aber ginge auch als PY-Script.

python -c "print('example')"
oder
print('example') als test.py und python test.py
perfekt
und es gibt auch schön das example aus.

Mit einem Modul (aus der python38.zip) geht's auch.
python -c "import uuid; print(uuid.uuid4())" => 5d6615d3-b65e-467c-b6ca-dfbf6fe7f874

Ebenfalls mit einem Modul von außerhalb. ( _hashlib.pyd im Verzeichnis, nicht hashlib.pyc aus der python38.zip )
python -c "import _hashlib; print(_hashlib.openssl_md5('aaa'.encode('utf-8')).hexdigest())" => 47bce5c74f589f4867dbd57e9ca9f808




Nun aber unser neues Modul.
python -c "import requests" ergibt das bekannte Bild
Zitat:
ModuleNotFoundError: No module named 'requests'

Die Hilfe war auch keine Hilfe. https://docs.python.org/3/reference/import.html
python -c "import Lib.site-packages.requests" will dennoch nicht, denn es mag keine - und ' oder " in sonstwelchen Varianten ändert sowieso nichts.
Außerdem wäre es eh blöd, was IMPORTs in Fremd-Komponenten anginge.


Die Modul-Verzeichnisse von .\Lib\site-packages\ direkt ins Python-Verzeichnis . verschoben/kopiert geht zwar,
python -c "import requests; r=requests.get('https://github.com/timeline.json'); print(r.status_code,' ',r.text)"
aber da könnte ich mir das PIP doch auch sparen und diese Module/Verzeichnisse manuell runterladen.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (14. Jul 2023 um 01:03 Uhr)
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz