Forums

ImportError: cannot import name Client

Hi,

I have a short script I have placed on a schedule. But it seems there is an error in the import code. I'm using standard Twilio boilerplate code and, as far as I can tell, the twilio module is installed.

Here's the error code:

ImportError: cannot import name Client

And here's my script with anonymized data: <pre> from twilio.rest import Client import random

with open('quotes.txt', 'r', encoding='utf-8') as f: quote = random.choice(list(f))

textQuote = "Today's Bruce Lee Quote: \n{}".format(quote)

client = Client("##############", "###############")

client.messages.create(to="+1########", from_="+1########", body=textQuote) </pre>

Any help would be appreciated. I am new to python and pythonanywhere, so it's most likely something simple.

Thanks

Are you running your scheduled task in the same version of Python as where you've installed twilio or in the right virtualenv? See http://help.pythonanywhere.com/pages/ScheduledTasks/ and http://help.pythonanywhere.com/pages/VirtualEnvInScheduledTasks/

I am having the same issue with twilio and pythonanywhere.

First, when I try to install twilio with PIP it tells me the requirements are already satisfied.

Then if I just go to any interpreter (python or ipython) and enter -> from twilio.rest import Client

I get the above import error.

I am guessing the original installation of the twilio library may be an issue here. Any help is greatly appreciated?

Thank-you

I think that from twilio.rest import Client depends on a later version of Twilio to the one that we have installed. You can upgrade the version installed for your account by running

pip3.6 install --user --upgrade twilio

...changing the 3.6 to reflect the version of Python that you want to use if necessary.

That was the problem.

Thank-you!

No problem!