2017-06-24 6 views
0

Also habe ich andere sehr ähnliche Probleme durchforstet und viele Variationen ausprobiert, aber ich kann das nicht zum Laufen bringen.ModuleNotFoundError: Kein Modul namens 'myfile.py'

Ich habe Code in einer separaten Datei unter folgenden Struktur erstellt:

/somefolder/#Dies ist, wo mein Hauptcode /somefolder/src residiert/das ist, wo meine myfile.py liegt, dass ich will einführen.

Mein Haupt Code beginnt wie folgt:

import os.path 
import sys 

sys.path.append(os.path.join(os.path.dirname(__file__), '../src')) 

import myfile as mine 

aber dann bekomme ich teh folgende Fehlermeldung:

ModuleNotFoundError: No module named 'myfile' 

Jede Hilfe wäre sehr willkommen.

+0

Was importieren ist Ihr aktuelles Verzeichnis, während das Hauptprogramm zu beginnen? – swapnilsm

+0

'C: \ Benutzer \ Benutzer \ Dokumente \ Visual Studio 2017 \ Projekte \ PythonApplication1 \ PythonApplication1' Das Modul befindet sich unter' C: \ Benutzer \ Benutzer \ Dokumente \ Visual Studio 2017 \ Projekte \ PythonApplication1 \ PythonApplication1 \ src' – Paul

Antwort

0

Angenommen, Ihr aktuelles Verzeichnis lautet PythonApplication1, können Sie folgendermaßen auf das Modul myfile zugreifen.

  1. erstellen __init__.py Datei in beiden PythonApplication1 und PythonApplication1\src Verzeichnisse
  2. Jetzt Meinedat als from src import myfile as mine
Verwandte Themen