How to install the `twitter` python package from PyPI?

I needed a python library twitter 1.17.1. I downloaded the .whl file from PyPI (`twitter-1.17.1-py2.py3-none-any.whl). The tutorial I was following, (where I was told to install the library), gave some commands to run:

$ python setup.py --help
$ python setup.py build
$ python setup.py install

I downloaded the file on Download directory, and from there on the terminal, I executed the first command. But it says there's no setup.py file. Where should I move the .whl file and how to install the library?

7

1 Answer

You've downloaded the .whl file from PyPI, but you aren't trying to install the 'built' automated installer. You need to install from the source code.

The source distribution (or, in Python / PyPI terms, the "Source Wheel") is a .tar.gz file, and is actually listed right on the PyPI page. (direct link for 1.17.1)

Download that .tar.gz to your Downloads folder, and then do this in the terminal, in order:

cd ~/Downloads
tar xvf twitter-1.17.1.tar.gz
cd ~/Downloads/twitter-1.17.1
python setup.py build
sudo python setup.py install

This will build the actual module and install it.

Later, you can import it with import twitter - remember that things are case-sensitive, and the case for this package is twitter not Twitter (these are different things to Python)


However, this module is on PyPI, and you should just be able to install it this way (you'll need the python-pip or python3-pip packages installed via apt, for python 2 and python 3 respectively, for these to work:

# For Python 2:
sudo pip install --upgrade 'twitter>=1.17.1'
# For Python 3:
sudo pip3 install --upgrade 'twitter>=1.17.1'

Follow-up from Chat*

There's a few things going on in your code that you did share, and your screenshot:

  1. You have twitter.py in the same folder as the item doing the import twitter code. That's going to break things, because it's conflicting names and will import what's likely NOT the twitter module and fail. (It imports from the local directory first and then tries other library directories).

  2. You have a bad import statement somewhere. You have import Twitter,... in the traceback from the screenshot you shared, and that's bad form. It needs to be from twitter import Twitter,... to properly work.

Fix those issues, and it shouldn't error out anymore with import failures.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like