Groups | Search | Server Info | Login | Register


Groups > de.comp.lang.python > #6055

Re: [Python-de] Re: Pfade, Modulnamen und import-Statements

From Bastian Blank <usenet@waldi.eu.org>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Re: Pfade, Modulnamen und import-Statements
Date 2024-05-05 10:32 +0000
Organization A thinking site
Message-ID <slrnv3eo1s.mt.usenet@mobilewave.waldi.eu.org> (permalink)
References <ZjYYBgoIiqLkxkB3@torres.zugschlus.de> <a1b0c3e8-9e07-4cde-9b19-2bc800d51db0@crazy-compilers.com> <ZjdBpXoZUmsZAWaG@torres.zugschlus.de>

Show all headers | View raw


Marc Haber wrote:
> [37/5247]mh@swivel:~/git/zg2dns $ grep -E 'class|import' get-root zg2dns/*
> get-root:from zg2dns.rootdata import DNSRootDataParser
> zg2dns/query.py:from rootdata import DNSRootDataParser
> zg2dns/query.py:class Zg2DNSQuery:
> zg2dns/rootdata.py:class DNSRootDataParser:

Versuche mal "zg2dns.query" zu importieren:

| Traceback (most recent call last):
|   File "/tmp/t/test", line 3, in <module>
|     import zg2dns.query
|   File "/tmp/t/zg2dns/query.py", line 1, in <module>
|     from rootdata import DNSRootDataParser
| ModuleNotFoundError: No module named 'rootdata'

> Ich finde es wenig schön dass man abhängig vom Ort der Nutzung
> unterschiedliche Import-Statements schreiben muss, aber wenn das so ist
> kann ich damit leben. Ich hatte das Verhalten halt nicht für pythonisch
> gehalten.

Dein Fehler ist ein komplett anderer.

Der Python-Interpreter fügt das Verzeichnis, in dem das aktuelle Script
liegt, dem Suchpfad hinzu.

Rufst du "get-root" auf, dann ist es ".". Damit findet "import
zg2dns.rootdata" auch "zg2dns/rootdata.py".

Rufst du aber "zg2dns/query.py" direkt auf, dann ist auf einmal
das Verzeichnis "zg2dns" im Suchpfad. Also referenziert "import
rootdata" auf einmal was anderes.

> Wäre ich dnspython-Entwickler, hätte ich ja meine workingcopy von mir
> aus unter ~/git/dnspython ausgecheckt, und wenn ich irgendwas
> ausprobiere, würde das "import dns.query" in
> ~/git/dnspython/dns/resolver.py ja das dns/query.py aus dem Pythonpath
> anziehen und nicht das aus meiner Workingcopy, weil ich ja sicher auch
> die Releaseversion der Library installiert hätte.

Dafür gibt es "pip install -e ." z.B. Damit macht man das aktuelle
Projekt im globalen Suchpfad des benutzten Interpreters verfügbar.

> Wir arbeiten Modulentwicker in so einer Situation?

Module werden nicht als Scripte direkt aufgerufen, sind also auch nie
ausführbar. Statt dessen werden sie mittels "python3 -m" aufgerufen.

Im nächsten Schritt kommen dann Entry-Points, aus denen dann Scripte
entstehen, welche in $prefix/bin landen.

Bastian

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

[Python-de] Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-04 13:12 +0200
  [Python-de] Re: Pfade, Modulnamen und import-Statements Hartmut Goebel <h.goebel@crazy-compilers.com> - 2024-05-04 19:22 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-05 10:21 +0200
      Re: [Python-de] Re: Pfade, Modulnamen und import-Statements Bastian Blank <usenet@waldi.eu.org> - 2024-05-05 10:32 +0000
        [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-10 11:37 +0200
          [Python-de] Re: Pfade, Modulnamen und import-Statements Hartmut Goebel <h.goebel@crazy-compilers.com> - 2024-05-11 17:49 +0200
  Re: [Python-de] Pfade, Modulnamen und import-Statements "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2024-05-05 02:26 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-05 10:25 +0200
      Re: [Python-de] Re: Pfade, Modulnamen und import-Statements "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2024-05-05 12:38 +0200
        [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-10 11:39 +0200
          Re: [Python-de] Re: Pfade, Modulnamen und import-Statements "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2024-05-10 19:25 +0200
  Re: [Python-de] Pfade, Modulnamen und import-Statements Hermann Riemann <nospam.ng@hermann-riemann.de> - 2024-05-05 12:02 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Marc Haber <mh+python-de@zugschlus.de> - 2024-05-05 12:35 +0200
  Re: [Python-de] Pfade, Modulnamen und import-Statements Hermann Riemann <nospam.ng@hermann-riemann.de> - 2024-05-10 20:05 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Christopher Arndt <chris@chrisarndt.de> - 2024-05-11 15:18 +0200
    [Python-de] Re: Pfade, Modulnamen und import-Statements Hartmut Goebel <h.goebel@goebel-consult.de> - 2025-01-26 21:21 +0100

csiph-web