0

I originally asked this question and took up Martijn Pieters solution and did as he posted:

enter image description here

However, I'm still unable to run my file out of Terminal. I should see files being saved in to the folder thisdir.

I've changed my directory to the directory of the file and I run

./my_file.py --todir thisdir foobar

But I'm still getting

Traceback (most recent call last):
  File "my_file.py", line 13, in <module>
    import requests
ImportError: No module named requests

I don't know if it matters, but I've tried running it with the first line of my file containing

#!/usr/bin/env python

as well as

#!/usr/bin/python

I really have no idea what I'm doing here, could someone please help me through this?


Update:

I replaced the shebang in my code, and I no longer get an error, but I also don't get any output (the issue isn't a bug in the code as I tested it fully). Here's the part of my code that requires requests

The part of my code that uses requests is below. I don't know if it

    for i in xrange(urls_count):
        r = requests.get(urls[i], stream=True)
        with open(save_here + '/file' + str(i), 'wb') as f_in:
            f_in.write(r.content)

I should see files being saved into thisdir and also in Terminal, a list of the newly created file's names being print out (in Terminal). So the issue isn't to add print the content (as suggested by hd1).

Also, not sure if this is relevant, but I clicked the box for "Install to user's site packages directory (/Users/AlanH/.local)

Community
  • 1
  • 1
TheRealFakeNews
  • 7,512
  • 16
  • 73
  • 114

1 Answers1

3

Your shebang line should read:

#!/path/to/anaconda/python

instead of /usr/bin/python or /usr/bin/env python.

Per your comment, the solution posted on this question may sort you. If not, leave another comment.

You aren't printing anything to stdout from your code. The snippet below should sort that:

for i in xrange(urls_count):
   r = requests.get(urls[i], stream=True)
   with open(save_here + '/file' + str(i), 'wb') as f_in:
       f_in.write(req.content)
       print req.content
Community
  • 1
  • 1
hd1
  • 33,938
  • 5
  • 80
  • 91