0

I hope this question will make sense. I have a piece of code that should be run from the command line:

python download_tweets_api.py --dist=tweeti-a.dist.tsv --output=downloaded.tsv

When I run this, it gives me an import error:

ImportError: No module named twitter

To find out why, I opened the Python shell by typing python. Then I checked sys.path, and found that the directory containing the twitter module was not in sys.path. So, I appended that directory, and twitter can now be imported.

However, it seems that

download_tweets_api.py --dist=tweeti-a.dist.tsv --output=downloaded.tsv

cannot be run from the Python shell, maybe because of the specific command line syntax? (I'm not so sure here)

So, I have to exit Python to return back to the 'normal' command line. However, then I lose my sys.path.append, and the twitter directory is no longer in sys.path.

What should I do?

eyllanesc
  • 190,383
  • 15
  • 87
  • 142
Johanna
  • 969
  • 1
  • 8
  • 19
  • 1
    You should add permanently the twitter location to your path. There is a lot of ways of doing this, I suggest you read http://stackoverflow.com/questions/3402168/permanently-add-a-directory-to-pythonpath – Jblasco Jan 20 '17 at 16:27
  • Which OS are you using? Windows? Linux? OSX? – Alex Hall Jan 20 '17 at 16:28
  • I'm using Windows:) – Johanna Jan 20 '17 at 16:29
  • did you add directory to `sys.path` in your script ? Adding directory in Python Shell nothing change. – furas Jan 20 '17 at 16:36
  • 2
    `"cannot be run from the Python shell"` - from Python Shell you can't run any file - you can only `import` file and run function from this file. You can run files only from command line - `python some_script.py` – furas Jan 20 '17 at 16:38

0 Answers0