ImportError: No module named botocore.session - python

I had already installed boto3 but still it gives error of no module named botocore.session
import botocore.session
ImportError: No module named botocore.session

I arrived here from Google. I was getting a similar error while updating AWS Lambda function code. The answer posted here helped in my case. Simply upgrade AWS CLI. Hope this helps someone drifting here from search engines.
pip install awscli --force-reinstall --upgrade

I was on version boto3-1.5.33 and botocore-1.8.47 and upgrading to boto3-1.9.75 and botocore-1.12.75 solved the issue for me.
pip install boto3 --upgrade

import boto3 alone is enough to connect with a bucket. botocore.session was used during for the previous boto 1.8 and is not accepted by boto3. you can refer the following boto3 documents http://boto3.readthedocs.io/en/latest/reference/services/s3.html#client . Here is boto 1.8 documents that mentions the use of botocore.session http://botocore.readthedocs.io/en/latest/tutorial/

try pip install boto3. If not then try pip install -U boto3

If you got conda environment also. Just use bellow command .
pip install --user awscli --upgrade
This works for me .

For anyone attempting to install AWS CLI on Mac AND running Python 3.6, use pip3.6 instead of pip in your command-line.
Example:
$ python --version
Python 3.6.4
$ sudo pip3.6 install --upgrade awscli
...
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
...
## IF YOU GET THE ABOVE MESSAGE YOU CAN UPGRADE PIP USING
$ sudo pip3.6 install --upgrade pip

Related

ImportError: No module named pip after trying to upgrade pip

I am using a MacOS 10.15 and Python version 3.7.7
I wanted to upgrade pip so I ran pip install --upgrade pip, but it turns out my pip was gone (it shows ImportError: No module named pip when I want to use pip install ...)
I tried several methods like python3 -m ensurepip, but it returns
Looking in links: /var/folders/sc/f0txnv0j71l2mvss7psclh_h0000gn/T/tmpchwk90o3
Requirement already satisfied: setuptools in ./anaconda3/lib/python3.7/site-packages (49.6.0.post20200814)
Requirement already satisfied: pip in ./anaconda3/lib/python3.7/site-packages (20.2.2)
and pip install still does not work and returns the same error message.
I also tried easy_install pip and other methods but pip still does not work.
Can anyone help me with this?
Update:
Using the method from #cshelly, it works on my computer!
Try the following:
python3 -m pip --upgrade pip
The -m flag will run a library module as a script.
The pip used by python3 is called pip3. Since you're using python3, you want to do pip3 install --upgrade pip.
Since it says no module named pip, thus pip is not installed in your system
So you may try
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
to download pip directly then you can use execute it using -
python3 get-pip.py
For details you may refer - https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
PS: You may need to use sudo to make use of administrative privileges.

How do I upgrade from pip 1.0?

I was trying to install a package which required an older version of pip and (stupidly) thought it would be a good idea to try installing the oldest version of pip possible (1.0).
To clarify, it is not pip 1.0.1 (which most guides I found on the internet refer to), but pip 1.0
When I attempt to run 'python -m pip install --upgrade pip', I get the following error:
C:\mydirectory\venv\Scripts\python.exe: No module named pip.__main__; 'pip' is a package and cannot be directly executed
When I run 'pip --version', I get the following info:
pip 1.0 from c:\mydirectory\venv\lib\site-packages (python 3.7)
Is there any way I can upgrade pip from this point?
python -m pip install -U pip should work. That is how I do it.
Try this:
python3 -m pip install pip

AttributeError: Module Pip has no attribute 'main'

I am trying to build the python api for an open source project called Zulip and I keep running into the same issue as indicated by the screenshot below.
I am running python3 and my pip version is 10.0.0. The file in question is setup.py and the code that is messing up is when the pip.main() attribute is accessed to install a package.
Now, I know this build should succeed because its an open source project, but I have been trying for hours to fix the dependency issue regarding pip.main().
Any help would be greatly appreciated.
python3 -m pip install --user --upgrade pip==9.0.3
pip issue: rollback
It appears that pip did a refactor and moved main to internal. There is a comprehensive discussion about it here: https://github.com/pypa/pip/issues/5240
A workaround for me was to change
import pip
pip.main(...)
to
from pip._internal import main
main(...)
I recommend reading through the discussion, I'm not sure this is the best approach, but it worked for my purposes.
First run
import pip
pip.__version__
If the result is '10.0.0', then it means that you installed pip successfully
since pip 10.0.0 doesn't support pip.main() any more, you may find this helpful
https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program
Use something like
import subprocess
subprocess.check_call(["python", '-m', 'pip', 'install', 'pkg']) # install pkg
subprocess.check_call(["python", '-m', 'pip', 'install',"--upgrade", 'pkg']) # upgrade pkg
pip 10.0.1 still doesn't support main
You can choose to DOWNGRADE your pip version via following command:
python -m pip install --upgrade pip==9.0.3
This helps me, https://pip.pypa.io/en/stable/installing/
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
If you are using python3 and not set it default. do this,
python3 get-pip.py
It works for me.
My solution is to check the version number of pip and use the import the correct main function correctly
import pip
if int(pip.__version__.split('.')[0])>9:
from pip._internal import main
else:
from pip import main
def install(package):
main(['install', package])
To verify whether is your pip installation problem, try using easy_install to install an earlier version of pip:
easy_install pip==9.0.1
If this succeed, pip should be working now. Then you can go ahead to install any other version of pip you want with:
pip install pip==10....
Or you can just stay with version 9.0.1, as your project requires version >= 9.0.
Try building your project again.
If python -m pip install --upgrade pip==9.0.3 doesn't work, and you're using Windows,
Navigate to this directory and move the pip folders elsewhere.
Close your IDE if you have it open.
Press 'Repair' on Python 3.
Your IDE should cease to detect pip packages and prompt you to install them. Install and keep the last stable pip version by blocking automatic updates.
Pip 10.0.* doesn't support main.
You have to downgrade to pip 9.0.3.
Try this command.
python -m pip install --user pip==9.0.1
It works well:
py -m pip install --user --upgrade pip==9.0.3
Edit file:
C:\Users\kpate\hw6\python-zulip-api\zulip_bots\setup.py in line 108
to
rcode = pip.main(['install', '-r', req_path, '--quiet'])
do
rcode = getattr(pip, '_main', pip.main)(['install', '-r', req_path, '--quiet'])ยด
Not sure about Windows. But for mac users, use this:
pip install --upgrade pip==9.0.3
I fixed this problem upgrading to latest version
sudo pip install --upgrade pip
My version:
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
I faced the same error while using pip on anaconda3 4.4.0 (python 3.6) on windows.
I fixed the problem by the following command:
easy_install pip==18.* ### installing the latest version pip
Or if lower version pip required, mention the same in the command.
Or you can try installing the lower version and then upgrading the same to latest version as follow:
easy_install pip==9.0.1
easy_install --upgrade pip
For me this issue occured when I was running python while within my site-packages folder. If I ran it anywhere else, it was no longer an issue.

ImportError: cannot import name pubsub_v1

I need to import Pubsub_v1 and bigquery from google.cloud module. I have installed it and pip freeze shows below :
gapic-google-cloud-pubsub-v1==0.15.4
google-cloud-bigquery==0.26.0
google-cloud-pubsub==0.27.0
proto-google-cloud-pubsub-v1==0.15.4
In my python script, i am importing the modules as below:
import os
from google.cloud import pubsub_v1
import time
import json
from google.cloud import bigquery
The script is throwing error as :
ImportError: cannot import name pubsub_v1
If i run $sudo pip install --upgrade google-cloud-pubsub then It is able to import pubsub but failing to import Bigquery. I need both modules. Can anybody please help ?
I had the same problem, it happened to me because I installed google-cloud-pubsub before google-cloud so here is my advise :
sudo pip uninstall google-cloud-pubsub
sudo pip uninstall google-cloud
sudo pip install google-cloud
sudo pip install google-cloud-pubsub
Upgraded the other google.cloud modules using
$sudo pip install --upgrade google-cloud-bigquery
$sudo pip install --upgrade google-cloud-storage
$sudo pip install --upgrade google-cloud-logging
It resolves the issue.
$sudo pip install googleapis-common-protos
It resolves the issue for me!
These were helpful to resolve the issue for python 3.x version: (I assumed the pip3 has been installed)
sudo pip3 install google-cloud-bigquery
sudo pip3 install google-cloud-pubsub
sudo apt-get upgrade
I had the same issue while trying the pubsub python library. I followed the below steps to resolve the issue:
Upgrade the pip library:
pip install --upgrade pip setuptools
pip3 install --ignore-installed PyYAML
pip3 install google-cloud-pubsub
just this one solved my issue
the others were not useful
sudo pip3 install google-cloud-pubsub

How do I install boto?

So that I am able to work with it within my python scripts?
If necessary, install pip:
sudo apt-get install python-pip
Then install boto:
pip install -U boto
Installing Boto depends on the Operating system.
For e.g in Ubuntu you can use the aptitude command:
sudo apt-get install python-boto
Or you can download the boto code from their site and move into the unzipped directory to run
python setup.py install
$ easy_install boto
Edit: pip is now by far the preferred way to install packages
switch to the boto-* directory and type python setup.py install.
install pip: https://pip.pypa.io/en/latest/installing.html
insatll boto: https://github.com/boto/boto
$ git clone git://github.com/boto/boto.git
$ cd boto
$ python setup.py install
Best way to install boto in my opinion is to use:
pip install boto-1.6
This ensures you'll have the boto glacier code.
If you already have boto installed in one python version and then install a higher python version, boto is not found by the new version of python.
For example, I had python2.7 and then installed python3.5 (keeping both). My script under python3.5 could not find boto. Doing "pip install boto" told me that boto was already installed in /usr/lib/python2.7/dist-packages.
So I did
pip install --target /usr/lib/python3.5/dist-packages boto
This allowed my script under python3.5 to find boto.
While trying out the
pip install boto
command, I encounter the error
ImportError: No module named pkg_resources
To resolve this, issue another command to handle the setuptools using curl
curl https://bootstrap.pypa.io/ez_setup.py | python
After doing that, the following command will work perfectly.
pip install boto
If you're on a mac, by far the simplest way to install is to use easy_install
sudo easy_install boto3

Categories

Resources