Setup OSX 10.7.4 Eclipse Indigo, Pydev, Tweepy-1.9
I thought this should be relatively simple but I keep getting an error. I am looking to specify the Tweepy API using sys.path.append( ) However PyDev keeps showing me an “Unresolved import: tweepy” Error
My Code
import sys
sys.path.append('/Applications/tweepy-1.9')
import tweepy
There are several similar posts on this which I have looked at but they seem to give conflicting advice as to whether to link to the top level file or to a particular file within the directory.
My question is should I be linking directly to the top level folder as I am now (/Applications/tweepy-1.9) or to a particular file within this folder? Machaku provided me with some information on a related question saying I could do both but I would have to create a file named “init.py” and link to it.
I have tried both but neither seems to work.
Any suggestions as always are much appriciated
The Error
Traceback (most recent call last):
File "/Users/brendan/Documents/workspace/Tweeter/src/rate_limit.py", line 13, in <module>
print api.rate_limit_status()
File "build/bdist.macosx-10.5-fat3/egg/tweepy/binder.py", line 185, in _call
return method.execute()
File "build/bdist.macosx-10.5-fat3/egg/tweepy/binder.py", line 149, in execute
raise TweepError('Failed to send request: %s' % e)
tweepy.error.TweepError: Failed to send request: [Errno 61] Connection refused
tweepy-1.9 file structure
-
tweepy-1.9
-
build
- bdist.macosx-10.5-fat3
- lib
- tweepy
- init.py (with 2 underscores either side of ” init “)
- api.py
- auth.py
- binder.py
- cache.py
- cursor.py
- error.py
- models.py
- oauth.py
- parsers.py
- streaming.py
- utils.py
- tweepy
-
dist
- tweepy-1.9-py2.7.egg
- PKG-INFO
- README
- setup.cfg
- tweepy
- init.py (with 2 underscores either side of ” init “)
- api.py
- auth.py
- binder.py
- cache.py
- cursor.py
- error.py
- models.py
- oauth.py
- parsers.py
- streaming.py
- utils.py
- tweepy.egg-info
- dependency_links.txt
- PKG-INFO
- SOURCES.txt
- top_level.txt
- zip_safe
-
Given the stack trace, your Tweepy library is found, so your
sys.path.appendhas worked. However, if you read the last line,tweepy.error.TweepError: Failed to send request: [Errno 61] Connection refusedthe error seems to be that the library cannot connect to the twitter service.
Concerning what to put in
sys.path, it should be the folder that contains the directory where your top level package lives. So for example, if I have the following structureand I want to be able to do
from my_package import module_1thensys.pathmust contain the absolute path tosrc. Also, the__init__.pyfile must be present to makemy_packagea Python package.However, dynamically updating
sys.pathis definitely not the recommended way to make python packages and modules accessible from another Python program.There are much better solutions:
calling
python setup.py install, as recommended in the Tweepy install guide (preferably using a virtualenv)updating PYTHONPATH to include the root path to the Tweety library.
using
.pthfiles that are read by the site moduleYou can find more details in the Python doc on Installing Python Modules and in particular the Modifying Python’s search path section