import boto3 error on Mac OS - python

I'm trying to install boto3 on my mac (high sierra 10.13.3) and tried to follow : https://github.com/boto/boto3. I had already installed python 3 using homebrew before, but when I tried to see pip --version, I get error.
So, I did
1) modify .bash_profile to add
alias pip=pip3
2) verify
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
3)
$ pip install boto3
Collecting boto3
Downloading boto3-1.5.36-py2.py3-none-any.whl (128kB)
100% |████████████████████████████████| 133kB 474kB/s
Collecting botocore<1.9.0,>=1.8.50 (from boto3)
Downloading botocore-1.8.50-py2.py3-none-any.whl (4.1MB)
100% |████████████████████████████████| 4.1MB 376kB/s
Requirement already satisfied: s3transfer<0.2.0,>=0.1.10 in ./Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in ./Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in ./Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: docutils>=0.10 in ./Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: six>=1.5 in ./Library/Python/3.6/lib/python/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.9.0,>=1.8.50->boto3)
Installing collected packages: botocore, boto3
Found existing installation: botocore 1.8.20
Uninstalling botocore-1.8.20:
Successfully uninstalled botocore-1.8.20
Successfully installed boto3-1.5.36 botocore-1.8.50
4) just to make sure this was fine, I ran
$ pip3 install boto3
Requirement already satisfied: boto3 in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: s3transfer<0.2.0,>=0.1.10 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from boto3)
Requirement already satisfied: botocore<1.9.0,>=1.8.50 in /usr/local/lib/python3.6/site-packages (from boto3)
Requirement already satisfied: docutils>=0.10 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from botocore<1.9.0,>=1.8.50->boto3)
Requirement already satisfied: six>=1.5 in /Users/ond983/Library/Python/3.6/lib/python/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.9.0,>=1.8.50->boto3)
5) but, now when I ran import boto3 in Idle, I get error
import boto3
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
I even tried to change path in .bash_profile, but it did not work.
Thoughts?

It worked for me to just copy all of packages with "bolo" in the name from the Python 3.7 folder to the Python 2.7 folder:
/usr/local/lib/python3.7/site-packages $ sudo cp -R boto* /Library/Python/2.7/site-packages/.

Related

Package updates from remote git repository are not reflected in site-packages

I have been trying to upgrade a package based off of the most recent changes on git but the changes aren't taking effect. I ran several variations of this command, such as also using python -m pip and the actual path to the pip version in anaconda, as well as adding --upgrade: pip install git+git://github.com/lmcinnes/umap#master
Here is the output each time:
Collecting git+git://github.com/lmcinnes/umap#master
Cloning git://github.com/lmcinnes/umap (to revision master) to /tmp/pip-req-build-bck1u0of
Running command git clone -q git://github.com/lmcinnes/umap /tmp/pip-req-build-bck1u0of
Requirement already satisfied: numpy>=1.17 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (1.19.2)
Requirement already satisfied: scikit-learn>=0.22 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (0.23.2)
Requirement already satisfied: scipy>=1.0 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (1.6.0)
Requirement already satisfied: numba>=0.49 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (0.51.2)
Requirement already satisfied: pynndescent>=0.5 in /home/himani/anaconda3/lib/python3.7/site-packages (from umap-learn==0.5.1) (0.5.2)
Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /home/himani/anaconda3/lib/python3.7/site-packages (from numba>=0.49->umap-learn==0.5.1) (0.34.0)
Requirement already satisfied: setuptools in /home/himani/anaconda3/lib/python3.7/site-packages (from numba>=0.49->umap-learn==0.5.1) (52.0.0.post20210125)
Requirement already satisfied: joblib>=0.11 in /home/himani/anaconda3/lib/python3.7/site-packages (from pynndescent>=0.5->umap-learn==0.5.1) (1.0.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/himani/anaconda3/lib/python3.7/site-packages (from scikit-learn>=0.22->umap-learn==0.5.1) (2.1.0)
And looking in the actual directory of where umap is in site-packages, I can see that none of the files are being changed to reflect the updates, so it seems that nothing is happening. I am tempted to just manually change the files myself but I know that wouldn't be smart for the long run.
try using the --update and --force-reinstall options of pip, or:
pip install --update --force-reinstall git+git://github.com/lcminnes/umap#master

Unable to list s3 buckets, getting error like "AttributeError: module 'boto3' has no attribute 'client'"

I'm getting the error like below:
AttributeError: module 'boto3' has no attribute 'client'
My python snippet is as like below
[ansible#ip-172-31-40-59 python]$ cat lists3buckets.py
#import boto3
#s3 = boto3.resource('s3')
#obj = s3.Object(bucketname, itemname)
#body = obj.get()['Body'].read()
#import boto3
#from botocore import ClientError
#s3 = boto3.client('s3')
#for bucket in s3.list_buckets():
# print(bucket)
import boto3
from botocore.exceptions import ClientError
s3=boto3.client('s3')
for i in s3.list_buckets():
print(i)
Note: I did try the commented code as well but had no luck.
My environment is Amazon Linux 2 machine and has boto3 and botocore already installed.
[ansible#ip-172-31-40-59 python]$ pip3 install boto3 --upgrade --user
Collecting boto3
Using cached https://files.pythonhosted.org/packages/85/c6/00e25614edf5ac025684bcc7af4c750187249ea7abbfc19dac05b95e83e8/boto3-1.14.22.tar.gz
Requirement already up-to-date: botocore<1.18.0,>=1.17.22 in /usr/local/lib/python3.7/site-packages (from boto3)
Requirement already up-to-date: jmespath<1.0.0,>=0.7.1 in /home/ansible/.local/lib/python3.7/site-packages (from boto3)
Requirement already up-to-date: s3transfer<0.4.0,>=0.3.0 in /home/ansible/.local/lib/python3.7/site-packages (from boto3)
Requirement already up-to-date: urllib3<1.26,>=1.20; python_version != "3.4" in /home/ansible/.local/lib/python3.7/site-packages (from botocore<1.18.0,>=1.17.22->boto3)
Requirement already up-to-date: python-dateutil<3.0.0,>=2.1 in /home/ansible/.local/lib/python3.7/site-packages (from botocore<1.18.0,>=1.17.22->boto3)
Requirement already up-to-date: docutils<0.16,>=0.10 in /home/ansible/.local/lib/python3.7/site-packages (from botocore<1.18.0,>=1.17.22->boto3)
Requirement already up-to-date: six>=1.5 in /home/ansible/.local/lib/python3.7/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.18.0,>=1.17.22->boto3)
Installing collected packages: boto3
Found existing installation: boto3 1.14.17
Uninstalling boto3-1.14.17:
Successfully uninstalled boto3-1.14.17
Running setup.py install for boto3 ... done
Successfully installed boto3-1.14.22
[ansible#ip-172-31-40-59 python]$ pip3 install botocore --upgrade --user
Requirement already up-to-date: botocore in /usr/local/lib/python3.7/site-packages
Requirement already up-to-date: jmespath<1.0.0,>=0.7.1 in /home/ansible/.local/lib/python3.7/site-packages (from botocore)
Requirement already up-to-date: urllib3<1.26,>=1.20; python_version != "3.4" in /home/ansible/.local/lib/python3.7/site-packages (from botocore)
Requirement already up-to-date: python-dateutil<3.0.0,>=2.1 in /home/ansible/.local/lib/python3.7/site-packages (from botocore)
Requirement already up-to-date: docutils<0.16,>=0.10 in /home/ansible/.local/lib/python3.7/site-packages (from botocore)
Requirement already up-to-date: six>=1.5 in /home/ansible/.local/lib/python3.7/site-packages (from python-dateutil<3.0.0,>=2.1->botocore)
I'm executing script as below:
[ansible#ip-172-31-40-59 python]$ !p
python3 lists3buckets.py
Traceback (most recent call last):
File "lists3buckets.py", line 14, in <module>
s3=boto3.client('s3')
AttributeError: module 'boto3' has no attribute 'client'
I fail to understand why a simple snippet should not work?

No able to import python modules . Installed pip3 and python 3.5 and python3.7

I want to use requests module on python3.7
But when in run
import requests
it throws error like this
ModuleNotFoundError: No module named 'requests'
However, it works fine with python3.5
When I run pip and pip3 install requests it says
root#helloasc:~# pip install requests
Requirement already satisfied: requests in /usr/local/lib/python3.5/dist-packages (2.23.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.5/dist-packages (from requests) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.5/dist-packages (from requests) (2020.4.5.1)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.5/dist-packages (from requests) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.5/dist-packages (from requests) (2.9)

Failed to import 'keystoneauth1' ... albeit installed?

I am using python3 via brew on MacOs.
When I do
> python3 -c "import keystoneauth1"
I get:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'keystoneauth1'
But then:
> pip3 install keystoneauth1
Requirement already satisfied: keystoneauth1 in /usr/local/lib/python3.7/site-packages (3.9.0)
Requirement already satisfied: iso8601>=0.1.11 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (0.1.12)
Requirement already satisfied: os-service-types>=1.2.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (1.2.0)
Requirement already satisfied: stevedore>=1.20.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (1.28.0)
Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (4.1.0)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (1.11.0)
Requirement already satisfied: requests>=2.14.2 in /usr/local/lib/python3.7/site-packages (from keystoneauth1) (2.19.1)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (2.7)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (2018.4.16)
Requirement already satisfied: urllib3<1.24,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (1.23)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests>=2.14.2->keystoneauth1) (3.0.4)
Nothing else shows up there. When I then verify the installation, things look good:
> pip3 show keystoneauth1
Name: keystoneauth1
Version: 3.9.0
Summary: Authentication Library for OpenStack Identity
Home-page: https://docs.openstack.org/keystoneauth/latest/
Author: OpenStack
Author-email: openstack-dev#lists.openstack.org
License: UNKNOWN
Location: /usr/local/lib/python3.7/site-packages
Requires: stevedore, requests, pbr, os-service-types, six, iso8601
Required-by: openstacksdk, keystoneauth
But as shown, already importing that module doesn't work.
For me, the problem manifested itself after upgrading brew python to the lastest version 3.7.6.
I explicitly upgraded brew, and pip3 as well, but no luck.
And sorry for the repeated typos. The module name is really keystoneauth1.
I really don't understand what exactly is going on here.
So this isn't really an answer that explains and solves the issue, but the workaround that worked for me:
First, I force removed python brew uninstall --ignore-dependencies python
Then, I only installed it again brew install python
And afterwards, my scripts (that in the end used that import) work again without any problems?!

Python cannot see module after installing via pip

I'm still trying to master the science of installing packages via pip. When I run pip to install geocoder, I get the following:
(base) C:\Users\MBSanders>python -m pip install geocoder
Requirement already satisfied: geocoder in c:\programdata\anaconda3\lib\site-packages (1.38.1)
Requirement already satisfied: requests in c:\programdata\anaconda3\lib\site-packages (from geocoder) (2.21.0)
Requirement already satisfied: future in c:\programdata\anaconda3\lib\site-packages (from geocoder) (0.17.1)
Requirement already satisfied: click in c:\programdata\anaconda3\lib\site-packages (from geocoder) (7.0)
Requirement already satisfied: six in c:\programdata\anaconda3\lib\site-packages (from geocoder) (1.12.0)
Requirement already satisfied: ratelim in c:\programdata\anaconda3\lib\site-packages (from geocoder) (0.1.6)
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (2019.3.9)
Requirement already satisfied: idna<2.9,>=2.5 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (2.8)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\programdata\anaconda3\lib\site-packages (from requests->geocoder) (3.0.4)
Requirement already satisfied: decorator in c:\programdata\anaconda3\lib\site-packages (from ratelim->geocoder) (4.4.0)
When I run
os.getcwd()
in spyder/python, I get
'C:\\Users\\MBSanders'
My question is, why do I get
ModuleNotFoundError: No module named 'geocoder'
When I run
import geocoder
I'm somewhat new to python. Please let me know if additional info is needed to trouble shoot. I'm within a federal agency so I do not have admin rights.
When I run sys.path in the console, I get
sys.path
Out[12]:
['F:\\Users\\MBSanders',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\python37.zip',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\DLLs',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3',
'',
'C:\\Users\\MBSanders\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\MBSanders\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\IPython\\extensions',
'F:\\Users\\MBSanders\\.ipython']
Assuming you're running python on the terminal, and python is the command you're using to run it, try doing python -m pip install geocoder. That'll install it for the python build you want to use. Or if you know the full path to the python build you're using, you can do something similar like /path/to/python -m pip install geocoder.
if you are using python 3.7 or 3.8 you may need to pip3.7 or pip3.8 install if you OS is recognizing a 2.x version as default

Categories

Resources