2

I am trying to go through Stem's tutorial for Python, using Ubuntu 14.04. After using sudo apt-get install python-stem and installing Stem, I found myself not knowing how to use it.

I tried to run simple code below, which I got from https://stem.torproject.org/api/connection.html#stem.connection.connect

import sys

from stem.connection import connect

if __name__ == '__main__':
  controller = connect()

  if not controller:
    sys.exit(1)  # unable to get a connection

  print 'Tor is running version %s' % controller.get_version()
  controller.close()

but I get this error:

~/example$ python controller.py
Traceback (most recent call last):
  File "controller.py", line 3, in <module>
    from stem.connection import connect
ImportError: cannot import name connect

Seems like Python cannot find the Stem code.
My question is how to fix this? Do I need to do something with installed Stem file?

Georgy
  • 12,464
  • 7
  • 65
  • 73
shaoyibai
  • 55
  • 1
  • 7

1 Answers1

0

I was able to get it running by using:

sudo apt-get install python-pip
sudo pip install stem

Pip is the Python package manager which will install the modules to the correct paths for Python.

drew010
  • 68,777
  • 11
  • 134
  • 162
  • when running the first command, lot of 404 Not Found, so "sudo: pip: command not found" for second command – shaoyibai Nov 25 '15 at 18:19
  • got pip installed by advise here: http://askubuntu.com/questions/561377/pip-wont-run-throws-errors-instead – shaoyibai Nov 25 '15 at 18:36
  • If you get lots of 404's using apt-get install, run `sudo apt-get update` first to update your package lists. – drew010 Nov 25 '15 at 18:58