2016-05-06 8 views
1

Ich verwende den Code von hier: https://github.com/Jefferson-Henrique/GetOldTweets-pythonWarum kann ich das Paket nicht in Python importieren?

Und jedes Mal, wenn ich versuche, die Datei-Ordner zu importieren, import got, wird es erhöhen:

Traceback (most recent call last): 
    File "C:\Users\USER\Desktop\python\get_old_tweet\Main.py", line 1, in <module> 
    import got 
    File "C:\Users\USER\Desktop\python\get_old_tweet\got\__init__.py", line 1, in <module> 
    import models 
ImportError: No module named 'models' 

Ich habe die Datei überprüfen und ziemlich sicher gewesen, dass sie Haben Sie den Dateiordner models

Und der Dateiordner enthält auch __init__.py Datei.

So sollte es gut funktionieren ..

Ich habe keine Ahnung, wie es funktioniert nicht. Bitte hilf mir!

Antwort

2

Welche Version von Python verwenden Sie?

Die Bibliothek https://github.com/Jefferson-Henrique/GetOldTweets-python mit Python geschrieben ist 2. Python 2 und Python 3 etwas anderes Verhalten mit dem Import haben: https://www.python.org/dev/peps/pep-0404/#imports

mir Beispiel für Import in Bezug auf Ihren Fall Lassen Sie teilen:

$ python3 
Python 3.5.0 |Anaconda 2.4.0 (x86_64)| (default, Oct 20 2015, 14:39:26) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import got 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Users/viach/Downloads/GetOldTweets-python-master/got/__init__.py", line 1, in <module> 
    import models 
ImportError: No module named 'models' 
>>> ^C 
KeyboardInterrupt 

$ python2 
Python 2.7.10 (default, Aug 22 2015, 20:33:39) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import got 

So , schnelle Lösung für Sie: Verwenden Sie Python 2 in Ihrer App, die von GetOldTweets-python abhängt.

+1

Sie haben Recht. Ich schreibe das Paket auf Python 3 und es funktioniert endlich! Danke für Ihre Hilfe! –

0

Es hängt davon ab, wo Sie importieren. Im Repository haben Sie einen Link zu models als Unterordner von got gefunden. Versuchen Sie folgendes:

from got import models 
+0

Vielen Dank für Ihre Hilfe, aber das funktioniert nicht .... –

+0

Wenn das Python-Modul 'models.py' im Unterverzeichnis 'got' ist, sollten Sie eine leere Datei namens '__init__.py' hinzufügen das 'got' -Verzeichnis sollte dann funktionieren. – Dave

0

Python nur sucht die Standardbibliothekspfade standardmäßig (einschließlich des laufenden Skript Pfad). Sie müssen sie also in die Python-Standardbibliothekspfade einfügen oder den Modulpfad an diese Pfade anhängen.

den Pfad Array anhängen:

>>> import sys 
>>> sys.path.append("path/to/the_module") 
>>> import the_module 

Wenn obige Lösung nicht funktioniert hat, versuchen:

>>> from models import got 
+0

wirklich schätzen für Ihre Hilfe. Aber das funktioniert auch nicht .... Immer noch "ImportError" –