Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


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

Re: [Python-de] Import problem im Eigendem Module Paket

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Hartmut Goebel <h.goebel@goebel-consult.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Import problem im Eigendem Module Paket
Date Sun, 7 Oct 2018 10:52:13 +0200
Organization Goebel Consult
Lines 69
Message-ID <mailman.5.1538902734.2799.python-de@python.org> (permalink)
References <pp85j1$7e1$1@tota-refugium.de> <b9c91295-ec62-b4ec-6dcb-39a9992b32b6@goebel-consult.de>
Mime-Version 1.0
Content-Type multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="------------ms090301080600030600090500"
X-Trace news.uni-berlin.de b1E8IwlB8569RX3tj/vFBAXCy47b5U+idoxIB+APJYkA==
Return-Path <h.goebel@goebel-consult.de>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
X-Virus-Scanned amavisd-new at mnet-online.de
Openpgp preference=signencrypt
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1
In-Reply-To <pp85j1$7e1$1@tota-refugium.de>
X-Content-Filtered-By Mailman/MimeDel 2.1.29
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.29
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <b9c91295-ec62-b4ec-6dcb-39a9992b32b6@goebel-consult.de>
X-Mailman-Original-References <pp85j1$7e1$1@tota-refugium.de>
Xref csiph.com de.comp.lang.python:5262

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Hallo,

Am 05.10.2018 um 19:04 schrieb Manfred Gil:
> Mein Problem ist das ich kein Module aus einem Übergeordnetem 
> Ordner importieren kann.
>
> Ich bekomme stets die Fehlermeldung:
>
> File "import_test.py", line 4, in <module>
>     from ..config import daten as da
> SystemError: Parent module '' not loaded, cannot perform relative import

Um das bisher geschriebene noch zu ergänzen, bzw. deutlich zu machen:

Das "import" Statement bezieht sich immer auf Module, *nie* auf
Verzeichnisse. Der relative Import bezieht sich also auf übergeordnete
Module. Auch wenn Module in Verzeichnissen zu Paketen gesammelt werden,
geht es nicht um Verzeichnisse.

Wie Peter schon geschrieben hat

Wenn Du die Datei my_paket/daten/import_test.py so aufrufst "python
my_paket/daten/import_test.py", dann ist es ein Skript und eben nicht
Teil einen Pakets. Und damit funktionieren relative Imports nicht, denn
die sind nur in Paketen zulässig.

Verwendest Du jedoch "python -m my_paket.daten.import_test", dann führst
Du das Module mit diesem Namen aus. Das Module "kennt" das Paket, zu dem
es gehört und damit funktionieren relative Imports.

-- 
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software
Development

Goebel Consult, Landshut
http://www.goebel-consult.de

Blog:
https://www.goe-con.de/blog/dsl-fernkonfiguration-ist-kritisch-fur-den-datenschutz

Kolumne:
https://www.goe-con.de/hartmut-goebel/cissp-gefluester/2012-04-compliance-bringt-keine-sicherheit


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


Thread

Import problem im Eigendem Module Paket Manfred Gil <manfred-gil@t-online.de> - 2018-10-05 17:04 +0000
  Re: [Python-de] Import problem im Eigendem Module Paket Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2018-10-05 20:49 +0200
  Re: Import problem im Eigendem Module Paket Peter Otten <__peter__@web.de> - 2018-10-05 22:10 +0200
  Re: Import problem im Eigendem Module Paket Hermann Riemann <nospam.ng@hermann-riemann.de> - 2018-10-06 10:19 +0200
  Re: [Python-de] Import problem im Eigendem Module Paket Hartmut Goebel <h.goebel@goebel-consult.de> - 2018-10-07 10:52 +0200
    Re: [Python-de] Import problem im Eigendem Module Paket Manfred Gil <manfred-gil@t-online.de> - 2018-10-07 09:20 +0000

csiph-web