Mars Lee
Mars Lee

Reputation: 1945

Why I can not import the package in Python?

I use the code from here: https://github.com/Jefferson-Henrique/GetOldTweets-python

And every time I try to import the file folder, import got, it will raise:

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'

I have check the file and been pretty sure that they do have the file folder called models

And the file folder also contains __init__.py file.

So it should work well..

I have no idea how it doesn't work. Please help me!

Upvotes: 1

Views: 1438

Answers (4)

Dmitry Mottl
Dmitry Mottl

Reputation: 862

You can use a Python3-compatible fork of GetOldTweets-python:
https://github.com/Mottl/GetOldTweets-python3

Upvotes: 0

Viach Kakovskyi
Viach Kakovskyi

Reputation: 1517

Which version of Python do you use?

The library https://github.com/Jefferson-Henrique/GetOldTweets-python is written with Python 2. Python 2 and Python 3 have a bit different behavior with import: https://www.python.org/dev/peps/pep-0404/#imports

Let me share example of import regarding your case:

$ 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, quick solution for you: use Python 2 in your app which depends on GetOldTweets-python.

Upvotes: 2

EngineerCamp
EngineerCamp

Reputation: 671

It depends on where you are importing from. In the repository you proved a link to models is a subfolder of got. Try this:

from got import models

Upvotes: 0

EbraHim
EbraHim

Reputation: 2359

Python only searches its default library paths by default (including the running script path). So you need to put them in Python default library paths or append your module path to those paths.

To append the path array:

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

If above solution doesn't worked, try:

>>> from models import got

Upvotes: 0

Related Questions