"ImportError: No module named twilio.rest" - python

I have installed python 2.7.10 with PATH access and correctly installed twilio. However, when I try to execute a code I get this error message
Traceback (most recent call last):
File "C:\Users\tmslvo\Google Drive\Desktop\send text.py", line 1, in <module>
from twilio.rest import TwilioRestClient
ImportError: No module named twilio.rest
Now I read that a reason might be that python can't find the twilio package so I tried the
which -a python
which -a twilio
commands (in my Windows command prompt) in which case I get
'which' is not recognized as an internal or external command,
operable program or batch file.
Does anybody have an idea of what I'm doing wrong?
Thank you!

Twilio developer evangelist here.
I think your problem will be that somehow when you installed the library, it failed silently(?). A few things to keep in mind:
When installing Python libraries, always make sure you use pip.
Also, check that none of your files within the project are actually called twilio.py as this will conflict with the actual library.
Check that you're using the version of Python you think you're using by running python --version
All that failing, run the installation again, and all going well (without errors), you should be able to test it quickly with the following code.
import twilio
import twilio.rest
try:
client = twilio.rest.TwilioRestClient(account_sid, auth_token)
message = client.messages.create(
body="Hello World",
to="+14159352345",
from_="+14158141829"
)
except twilio.TwilioRestException as e:
print e

try this: sudo pip3 install twilio --upgrade

I had this problem as well.
In my case, I had named my file twilio.py and that is what caused the error.
Renaming the file to send_sms.py ( or any other name of your choice) will resolve the issue!

Close and then relunch all IDLE instances.
This sounds obvious but it worked for me, since the installations of components were successful

I ran into this same issue. I had used easy_install instead of pip to install twilio which was the problem. To fix this I ran pip uninstall twilio and reinstalled using pip.

rename file name other than twilio.py
EX:send_sms.py

A bit late to the party here but I also ran into this issue.
After some trial and error, it looks like it was due to the pip version I was using. I originally used -
pip3 install twilio.
Now I'm unsure of the underlying reason why this did not work, but it seems that pip3 does not encompass all versions of python 3.x? Using
pip3 list and
pip3.8 list
I noticed I had the twilio module for pip3 but not for pip 3.8.
I used the following and was able to solve the issue
pip3.8 install twilio.
I used pip3.8 because that matched the python3.8 version that I am using.

Pycharm user:
Macs (mid 2017) come with python 2.6 and 2.7 installed. PyCharm uses by default 2.6. When you install twilio (Pip install) the module is installed in python version 2.7. So, when you try to run twilio from PyCharm you get
ImportError: No module named twilio.rest
Solution: change the python interpreter in PyCharm. Go to preferences > project interpreter and from the drop menu Project Interpreter choose python 2.7

I think your pip is not configured properly . You may be getting succefuuly installed message but it is not install where it should be. try pip install --user i am sure it will work for you. pip install may work fine only in virtualenvironment without any config.Try pip install --user package name
#iosCurator

I had first installed twilio with the easy_intall tool
I followed the steps below:
Uninstall twilio with the command pip uninstall twillo
Install twilio with the command pip install twilio
Close the python IDLE and relaunch it.

For the windows user,
I have suggested, pip3 install twilio

Follow these steps (on mac):
Shift + Command + P
search: Configure Language Specific Setting
search: Python
add: "code-runner.runInTerminal": true
That's it!
Ask me any question about it by:
My LinkedIn

I ran into this issue when using poetry for my dependency management. Poetry doesn't recognise it as an existing package yet, hence it won't run your code unless you try the poetry+pip way.

there will be 2 reasons for this
1.make sure you kept right path for python files in environment location
2.install twilio
commands:
1.pip3 install twilio
(or)
pip install twilio
2.python otpv.py

Related

pymongo - "dnspython" module must be installed to use mongodb+srv:// URIs

I am trying to connect MongoDB from Atlas.
My mongo uri is: mongodb+srv://abc:123#something.something.com/admin?retryWrites=True
My pymongo version is 3.6.1
I have installed dnspython and done import dns
But i still get this error:
dnspython module must be installed to use mongodb+srv:// URI
In order to use mongo+srv protocol, you need to install pymongo-srv
Launch this command to do it with python 3:
pip3 install pymongo[srv]
or this one for other versions:
pip install pymongo[srv]
And as suggested by #lukrebs, add quotes for ZSH:
pip3 install 'pymongo[srv]'
I would like to answer my own questions here. As I mentioned in the comment, the kernel of the jupyter notebook has to be restarted in order for the pymongo to take effect of the loaded dnspython.
I solved this problem with:
$ python -m pip install pymongo[srv]
In requirements.txt, replace pymongo with pymongo[tls,srv], as mentioned here.
I got stuck with the same problem and tried
pip install dnspython==2.0.0
This is the latest version from https://pypi.org/project/dnspython/
It worked :D
you can use mongo:// instead of mongodb+srv://
May be the protocol, your URI should start with:
mongo+srv instead of mongo+src
If it still not working please put a pip list with the versions of PyMongo and dnspython (and version of python that you are using)
I had the same problem on Ubuntu 18 but since I am using Anaconda
I just tried
Conda install dns python
I had an IPython running, it did not work while the same instance was open but when I restarted that instance it worked.
On a different machine using
Conda install dns python
and it worked but I had to restart my machine altogether due to a different reason before testing it
I had the same issue and found the following line.
import dns.resolver
dns.resolver.default_resolver=dns.resolver.Resolver(configure=False)
dns.resolver.default_resolver.nameservers=['8.8.8.8']
It worked for me.
pip install dnspython
dnspython is a DNS toolkit for Python. It supports almost all record types. It can be used for queries, zone transfers, and dynamic updates. It supports TSIG authenticated messages and EDNS0.
None of the existing answers had worked for me. I had to do the following:
sudo apt-get install python3-dnspython

Installing python bottle framework for python 3.6.1 version instead of python 2.7.1 version?

I am currently working on a mongo db assignment using pymongo, as part of it we need to install python bottle framework. I have installed bottle on the Mac using the below command:
$ pip install bottle
got the below message returned.
Requirement already satisfied: bottle in /Library/Python/2.7/site-packages
when I run a program from terminal which uses bottle, it throws the below error:
$ python hello_m101p.py
Traceback (most recent call last):
File "hello_m101p.py", line 2, in <module>
import bottle
ModuleNotFoundError: No module named 'bottle'
I noted that i also have python 3.6.4 version installed on my system. I need bottle framework to be saved or installed for this version instead of the default 2.7 version. After a quick lookup around stack overflow, I tried the below command from one the suggested answers. I get the command not found error:
sudo pip-3.6.4 install bottle
sudo: pip-3.6.4: command not found
Any help to correct this error ? I am not sure how to address this. Please let me know if the question is unclear or need more context.
The default name for pip for Python version X.Y.Z is not pip-X.Y.Z, but pipX.Y. Some linux distros use different names for their versions, but I believe on Mac, both the python.org Python installer and the Homebrew python package (and you probably have one of those two) use the default names, at least as of 2018.
If you only have one 3.Y.Z, it will probably also be available as pip3, which is convenient.
If you've got different names and are hopelessly confused, but you do know how to run your Python 3 itself, you can always use the -m flag to run pip.
Also, most Mac Python installs don't need sudo. If you don't know whether you do, try it without first. If you get a bunch of permissions errors, then you do need sudo after all, but otherwise, don't use it.
So, what you want is probably any of these:
pip3.6 install bottle
pip3 install bottle
python3 -m pip install bottle

Why would my twilio portion of the program work on my laptop but not my pi?

Currently using twilio sms library so that the the data collected from my house can be sent to my phone. When I ran it from my laptop it worked fine, but after pip importing it onto my Pi and trying to run it I still got the exception:
ImportError no module named 'twilio'
This seems so simple, but I have spent a long time reading through documentation and know I'm just missing something super basic.
from twilio.rest import Client
client = Client("***************", "**************")
client.messages.create(to="++*******",
from_="*******",
body="Pi says hi")
Thanks a ton for anyone who helps me out!
Note: I'm using python 3 for both and raspbian as the OS.
If you are using python3, then the problem is likely that you used pip. pip will install modules for python2. If you want to install to a python3 env, you need to use pip3.
pip3 install twillio
Note:
If you don't already have pip3 installed, you'll need to do that as well.
sudo apt-get install python-pip3

Python pip install gives “Command ”python setup.py egg_info“ failed with error code 1”

Edit: Yes I know this question already exists, except my question is a bit different and none of the solutions fixed it.
I do most of my Python stuff when I'm at work and not on my personal machine, but I decided to install it on my personal computer as well. I fresh installed python 3.6.1, and created a virtual environment with virtualenv. Then within the virtualenv I tried to pip install urllib (or any module) and I received the error:
(pdbot) C:\Users\user\Documents\pdbot>pip install urllib
Collecting urllib
Using cached urllib-1.21.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\setup.py", line 191
s.connect((base64.b64decode(rip), 017620))
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I read elsewhere that this error had something to do with setuptools not being properly installed. So I ran this to attempt to fix the issue:
easy_install -U setuptools
I ended up receiving an even weirder error next:
(pdbot) C:\Users\zeke\Documents\pdbot>easy_install -U setuptools
Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Downloading https://pypi.python.org/packages/a9/23/720c7558ba6ad3e0f5ad01e0d6ea2288b486da32f053c73e259f7c392042/setuptools-36.0.1.zip#md5=430eb106788183eefe9f444a300007f0
Best match: setuptools 36.0.1
Processing setuptools-36.0.1.zip
Writing C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\setup.cfg
Running setuptools-36.0.1\setup.py -q bdist_egg --dist-dir C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\egg-dist-tmp-8apak7kn
warning: no files found matching '*' under directory 'setuptools\_vendor'
Copying setuptools-36.0.1-py3.6.egg to c:\users\zeke\documents\pdbot\lib\site-packages
Adding setuptools 36.0.1 to easy-install.pth file
Installing easy_install-script.py script to c:\users\zeke\documents\pdbot\Scripts
Installing easy_install.exe script to c:\users\zeke\documents\pdbot\Scripts
error: [WinError 5] Access is denied: 'c:\\users\\zeke\\documents\\pdbot\\Scripts\\easy_install.exe'
This looks like a permissions error, but I ran these both in an administrator command prompt (Windows 10) and got the same result. I am the only user on this computer and I have all admin permissions. Is this virtualenv causing an issue? How do I remedy it?
EDIT: I was able to fix the permissions issue by leveraging the python executable like so:
python -m easy_install -U setuptools
But it didn't fix the python setup.py egg_info issue. I still get this error message when trying to pip install anything:
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I have tried both python -m pip install urllib and pip install urllib and neither work.
I had the same problem when trying to install urllib, but after doing a pip search urllib, I discovered that the problem was due to the version of urllib. From the search:
$ pip search urllib
...
> urllib5 (5.0.0) - Just increment the number and create a new lib. Never fix the original one.
At the end, a simple
pip install urllib5
within an elevated shell solved it.
Your problem has to do with permissions. The related/similar tools setup_tools, easy_install, and pip all tend to set a default set of permissions on files and folders they try to create in the package installation folder(s), rather than trying to match access permissions of the location they're installing in.
On Linux systems, where files and folders individually have permissions, this is frequently bypassed with the sudo command. On Windows, the equivalent is to run the installer as an Administrator. Since you're in the console, you have to open a console with Administrator privileges to run the pip command in.
Notable under Windows, the modules installed with pip from an Administrator console are still accessible to all users of the system that have the proper path in the PYTHONPATH system environment variable. Under Linux however, the problem is exacerbated by the fact that the files themselves may not be created with read and execute access for other users and may need to have their permissions manually modified after installation.
WARNING: urllib vs urllib2 vs urllibx
Both other answers claim that the problem is you're not specifying the correct "version" of the module in the call to pip. Neither is correct, as the error clearly indicates an installation folder access permissions violation causing the failure, but they also incorrectly recommended VERY unsafe behavior.
pip install urllib != pip install urllib5 these are two completely different packages.
The documentation for pip (https://packaging.python.org/tutorials/installing-packages/#id17) clearly says the way to specify a module version explicitly is pip install 'urllib==5'.
As part of how the package management engine implemented by pip works, running the command pip install urllib will always try to use the latest version of the urllib package, so you shouldn't need to specify the version unless you have some reason that you need a very specific version of the module.
There are two points to make in order to answer your question:
1. You are lucky you did not install that package!
The package you were trying to install was a maliciously created python package that was designed to look like a real package (in this case urllib3). If you had installed it, the package would have operated as normal except it would have sent some basic information about the system on which you installed the package to a URL (you can see more details on this here). You can read more about this fake package at either of the following links:
https://app.threatconnect.com/auth/incident/incident.xhtml?incident=5256822&owner=Common%20Community (you can sign up for a free account to view this one)
http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/index.html
Sending basic information about your systems to an unknown source isn't the worst thing you could do, but is certainly something you want to avoid when possible.
2. To properly install a package...
Specifically urllib:
To install urllib, you need to specify the version of the package you would like to install. For example, pip install urllib3.
Any package in general:
As #Elisabete Coelho suggested, you can use the pip search <package-name> feature to view the available packages. This is not perfect, however, as it may list malicious libraries like the one you were trying to install. A good guideline is that you should follow the installation instructions in a package's documentation closely to avoid any unforeseen issues. This is just an unfortunate necessity of living in a world where people make pretend python packages.

Installing AutoIt for Robot framework

I am trying to install the AutoIt library for Robot Framework, I've tried using the pip command command pip install robotframework-autoitlibrary but that didn't work. I then downloaded the AutoIt library and installed it but I can't open it.
Why can't I use the library?
There are two reasons that your install may not be working correctly:
1. You haven't installed ActivePython, which I don't think you have.
2. You need the 32bit version of Python installed or AutoIt won't actually work.
If these fixes don't work, comment and I will try to help further
Step1. Please make sure you have installed autoit-v3-setup.exe, pywin32-220.win-amd64-py2.7.exe.
Step2. You have to run "python setup.py install" in a Administrator cmd while installing AutoItLibrary-1.1.
Step.3 If you meet any porblem, please add the error message, that will be very useful.
Hope this will help you.
I had the same issue but resolved by following the below steps.
Download the file from below path "https://pypi.org/project/robotframework-autoitlibrary/#files"
Unzip and run the "setup.py" file from the command prompt as administrator by using the below command "python setup.py install".
Open your ride editor and import the library with the name "AutoItLibrary".
It worked for me with below versions
robotframework==3.1.2
robotframework-autoitlibrary==1.2.5
robotframework-seleniumlibrary==4.3.0
robotframework-ride==1.7.4.1
selenium 3.141.0
I had some troubles installing the lastest version 1.2.2 which supports python 3 on windows and it was due to blank spaces in the path as Program Files : https://code.google.com/archive/p/robotframework-autoitlibrary/issues/30 I hope it helps somebody, the fix is basically quotes around the path

Categories