0
votes

So I'm trying to execute this basic Python script in Terminal (Mac) but it fails over when it's not able to find module.

Ran the same code into repl.it and works just fine so it's something on my machine which Python doesn't like.

Have attempted to install requests via:

pip3 install requests

But that fails over with:

m@mo-testmbp ~ % pip3 install requests Traceback (most recent call last): File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 10, in sys.exit(main()) TypeError: 'module' object is not callable

Python script:

    import requests
    from random import randint


    url = 'https://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain'

    r = requests.get(url)
    text = r.text

    individual_words = text.split()
    random_num = randint(0,len(individual_words))

    print(individual_words[random_num] + str(random_num))

The code script fails with:

m@mo-testmbp ~ % /usr/bin/python3 "/Users/m/OneDrive - Mo/Training/Coding-mojoMac/Python/username_gen.py" Traceback (most recent call last): File "/Users/m/OneDrive - Mo/Training/Coding-mojoMac/Python/username_gen.py", line 1, in import requests ModuleNotFoundError: No module named 'requests'

1
Have you tried installing requests using pip3 on the terminal of your computer, instead os VS Code? Otherwise perhaps try to reinstall pip3? - bastantoine
Possibly related: github.com/Homebrew/homebrew-core/issues/… (in this case, I would try rm -rfing requests) - Mateen Ulhaq
Also, you may need sudo. - Mateen Ulhaq
@BastienAntoine Yep went to Terminal first time but I've found the answer now so cheers anyways bud - nullHip_nullSquare

1 Answers

0
votes

I think this could help you.

Try to use

python -m pip install requests

Or

python3 -m pip install requests