Installing Twitter Python Module

13,515

Solution 1

1) Run CMD as administrator
2) Type this:
set path=%path%;C:\Python27\
3) Download python-twitter, if you haven't already did, this is the link I recommend:
https://code.google.com/p/python-twitter/
4) Download PeaZip in order to extract it:
http://peazip.org/
5) Install PeaZip, go to where you have downloaded python-twitter, right click, extract it with PeaZip.
6) Copy the link to the python-twitter folder after extraction, which should be something like this:
C:\Users\KiDo\Downloads\python-twitter-1.1.tar\dist\python-twitter-1.1
7) Go back to CMD, and type:
cd python-twitter location, or something like this:
cd C:\Users\KiDo\Downloads\python-twitter-1.1.tar\dist\python-twitter-1.1
8) Now type this in CMD:
python setup.py install

And it should work fine, to confirm it open IDLE, and type:

import twitter

Now you MAY get another error, like this:

>>> import twitter Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\twitter.py", line 37, in <module> import requests ImportError: No module named requests

Then you have to do kinda same steps in order to download the module requests.

Solution 2

Looking at the directory structure you have, I am assuming that you are using Windows. So my recommendation is to use a package manager system such as pip. pip allows you to install python packages very easily.

You can install pip here: pip for python

Or if you want the windows specific version, there are some pre built windows binaries here: pip for windows

Doing python setup.py install in IDLE will not work because that is an interactive python interpreter. You would want to call python from the command line to install.

with pip, you can go to the command line and run something like this:

"pip install twitter-python"

Not all python packages are found with pip but you can search using

"pip search twitter-python"

The nature of pip is that you have to type out the exact name of the module that you want.

So in a nutshell, my personal recommendation to get python packages installed is:

  • Install pip executable
  • Go to the command line
  • Type "pip search python_package"
  • Find the package you want from the list.
  • Type "pip install python_package"

This should install everything without a hitch.

Share:
13,515
AdrianBoeh
Author by

AdrianBoeh

Updated on June 06, 2022

Comments

  • AdrianBoeh
    AdrianBoeh almost 2 years

    I am trying to install Twitter-Python and I am just not getting it. According to everything I've read this should be easy. I have read all that stuff about easy_install, python setup.py install, command lines, etc, but I just don't get it. I downloaded the "twitter-1.9.4.tar.gz", so I now have the 'twitter-1.9.4' folder in my root 'C:\Python27' and tried running

    >>> python setup.py install
    

    in IDLE... and that's not working. I was able to install a module for yahoo finance and all I had to do was put the code in my 'C:\Python27\Lib' folder.

    How are these different and is there a REALLY BASIC step-by-step for installing packages?

  • AdrianBoeh
    AdrianBoeh almost 11 years
    Thank you for helping me make some progress. I was able to install pip and get to the command line, but when I type in "pip search python_package" I get a "SyntxError: Invalid syntax". I thought maybe I needed to import pip so when I tried that it gave me "ImportError: No module named pkg_resources"
  • AdrianBoeh
    AdrianBoeh almost 11 years
    Thank you for the help. The command prompt says that "python is not a recognized as an internal or external command, operable program or batch file."
  • Stephen Lu
    Stephen Lu almost 11 years
    I apologize, When using pip, you need to be using the command line. Just go into your command line. To access your command line. Hit the windows button and search "cmd". That should result in your command line. In that command line, you should be able to type "pip search python_package". The interpreter is only need when you are doing things at the language level and not the operating system level.
  • Stephen Lu
    Stephen Lu almost 11 years
    You might need to configure your path variable in windows so that windows knows where your python scripts are located and can execute them. When pip is installed, it is installed in your python path. Without that in your environment, windows doesn't know how to retrieve that python file.Configure python for windows
  • artdanil
    artdanil almost 11 years
    It should be if you installed IDLE correctly. Otherwise add the directory containing 'Python.exe' (probably C:\Python27 for you) to System Path.
  • AdrianBoeh
    AdrianBoeh almost 11 years
    So, I guess I still don't get it... I added C:\Python27\Lib to the environment variables, I "set PYTHONPATH=%PYTHONPATH%;C:\Python27\Lib", and I even put "set PYTHONPATH=%PYTHONPATH%;C:\Python27\Lib" in the autoexec.bat file. Python and pip are still not recognized from the command line and when I "echo %path%" it doesn't appear in the list. Is there a way around this - like another way to install the Twitter-Python package?
  • AdrianBoeh
    AdrianBoeh almost 11 years
    So, I guess I still don't get it... I added C:\Python27\Lib to the environment variables, I "set PYTHONPATH=%PYTHONPATH%;C:\Python27\Lib", and I even put "set PYTHONPATH=%PYTHONPATH%;C:\Python27\Lib" in the autoexec.bat file. Python and pip are still not recognized from the command line and when I "echo %path%" it doesn't appear in the list. Is there a way around this - like another way to install the Twitter-Python package?
  • artdanil
    artdanil almost 11 years
    Not the PYTHONPATH, but PATH variable - set path=%path%;C:\Python27. Note the path added ('C:\Python27') should be the one where your python.exe file is located. For example, in my installation the python.exe file is in the install root directory (e.g. 'Python27'), not in the 'Lib' directory.
  • AdrianBoeh
    AdrianBoeh almost 11 years
    That's awesome! I was able to add that directory and can see it in echo %path%... but I still can't figure out pip or how to install Twitter-Python
  • AdrianBoeh
    AdrianBoeh almost 11 years
    Thank you! This is as far as I have gotten so far. I am now able to see these directories in %path% and the command line is recognizing pip... however now it is saying "ImportError: No module named pkg_resources" when I try "pip search python_packages". Do I need to put this Twitter-Python folder some where special? Thanks again for the help, really appreciate it.
  • Selrac
    Selrac almost 8 years
    When I try 'import twitter' I get another error: File "C:\xxxx\PhythonTests\python-twitter-1.1.tar\dist\python-twi‌​tter-1.1\twitter.py"‌​, line 54 </next line/> raise ImportError, "Unable to load a json library" <//> I have version 3.5.0 <//> on line 54, which follows this line: from django.utils import simplejson
  • KiDo
    KiDo almost 8 years
    @Selrac try import json if you get any error then you need to get another version maybe.