Why I can not import the package in Python? - 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!

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.

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

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

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

Related

Can't import cElementTree on Python 2.7

I cannot import xml.etree.cElementTree on Python 2.7. On the web, it says its already implemented, so I don't have to install it. (It's working on Python 3.6 for me, but I need 2.7 for reasons here)
Thats the console output:
Python 2.7.15+ (default, Nov 27 2018, 23:36:35)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.etree.cElementTree
Failed to import cElementTree from any known place
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named etree.cElementTree
I hope you can help me.
Kind regards,
Markus
I just found out that theres an old xml.pyc file in that directory, which didnt show up in PyCharm. It stopped the "real" XML from loading.

ImportError: cannot import name 'timezone' while importing NLTK

While importing NLTK in Python2 or Python3, the error shows up that 'timezone' cannot be imported while importing NLTK. It worked fine few days earlier.
Someone please help. The output is below.
For Python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
........
........
from datetime import timezone
ImportError: cannot import name 'timezone'
For Python2
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 89, in <module>
from nltk.internals import config_java
File "/usr/local/lib/python2.7/dist-packages/nltk/internals.py", line 31, in <module>
from nltk import compat
File "/usr/local/lib/python2.7/dist-packages/nltk/compat.py", line 45, in <module>
from datetime import tzinfo, timedelta
ImportError: cannot import name tzinfo
Moved solution from question to answer:
UPDATE (Problem Solved)
The issue has been solved now - turns out the problem was that i had a folder named datetime in my current working directory which was actually being imported by the file since the first element of the searched path is The directory containing the input script (or the current directory when no file is specified).
In short, Just renaming that folder solved all the problems. Thanks anyway to all.
I think you need to install dateutil package of python.
dateutil provides datetime parsing and timezone conversion.
Then try importing nltk

Virtual server ImportError: No module named fuzzywuzzy

Running an ec2 instance on aws; when attempting to run a script that imports several packages, all packages import correctly except one: 'fuzzywuzzy' (used for fuzzy string matching). I tried installing fuzzywuzzy from source code within the virtual server but aws reacted by auto-uninstalling it.
[ec2-user#ip-172-31-39-215 BearTrap]$ python
Python 2.7.9 (default, Apr 1 2015, 18:18:03)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> import string
>>> import ast
>>> import itertools
>>> from collections import OrderedDict
>>> import fuzzywuzzy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fuzzywuzzy

Utils module not imported

I have downloaded this package of Python Utils , and tried to install it, by entering the folder and typing:
python setup.py install
The output seems fine: the package installed and all dependencies processed.
However, when I try to import:
$ python
Python 2.7.2 (default, Dec 12 2011, 16:10:05)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named utils
What am I getting wrong?
The package is called python_utils, not utils. import python_utils should work.

Python how to import urlib?

mirko#mirko-imedia-S2870 ~ $ /usr/bin/python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named urlib
I'm using python from the command line, with a fresh installation of Mint Linux 14.
What must I do to make this work?
Perhaps adding an l could help:
import urllib
You are missing one l in urllib, but I would highly recommend that you use urllib2 if it is available on your installation.
Other good alternatives that requires you to install 3rd party packages are urllib3 or requests.

Categories