Python3: AttributeError: module 'boto' has no attribute 'plugin' - google-cloud-platform

I am running some code on a Google Platform Compute Engine VM and I get an error when I imported Python boto library.
The first time if I run 'import boto', the error message would be:
ModuleNotFoundError: No module named 'urllib2'
Then I ran it again, a different error message came out:
AttributeError: module 'boto' has no attribute 'plugin'
I tried installing google-compute-engine but it didn't work. I also tried different versions of boto but failed as well.

As it is suggested by user10360186 in AttributeError: module 'boto' has no attribute 'plugin' answer. You have to execute
$ pip install google-compute-engine
and restart the VM.

Problem solved. Not sure why but when you try to use boto on a google platform engine. There will be a file /usr/share/google/boto/boto_plugins/compute_auth.py, you need to modify the line from 'import urllib2' to 'import urllib.request as urllib2' to fit Python3. Then it is all good.

Related

Facing an Error while trying to Import ModelStep

I am trying to import ModelStep using the code
from sagemaker.workflow.model_step import ModelStep
But it is throwing the error
ModuleNotFoundError: No module named 'sagemaker.workflow.model_step'
How can I resolve this issue?
This feature, in sagemaker-python-sdk, was introduced starting with release 2.90.0 (16 May 2022).
I suggest always keeping sagemaker updated, they come out with updates very frequently and quite important:
pip install -U sagemaker

ModuleNotFoundError: No module named 'weasyprint'

I have installed WeasyPrint==0.42.3, but when I try to import it in Django, it raises the following error:
ModuleNotFoundError: No module named 'weasyprint'
When I look at the requirements.txt, it actually shows that it is installed.
I am using Django==2.1.5, python==3.8.5. another issue I am encountering is, the version of Django I am using is not listed in the requirements.txt, but when I check the version from the terminal, it shows that I am using the above named version.

gcloud command suddenly doesn't work at all

All gcloud commands suddenly give this error:
ERROR: gcloud failed to load: No module named google.appengine.ext
This usually indicates corruption in your gcloud installation or
problems with your Python interpreter.
Please verify that the following is the path to a working Python 2.7
executable:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
If it is not, please set the CLOUDSDK_PYTHON environment variable to
point to a working Python 2.7 executable.
If you are still experiencing problems, please reinstall the Cloud SDK
using the instructions here:
https://cloud.google.com/sdk/
Here are some relevant details and things that I've tried:
Mac 10.11.6
Python 2.7.8 at /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python otherwise works fine
I completely removed google-cloud-sdk and redownloaded from https://cloud.google.com/sdk/
Tried rebooting
Tried "export CLOUDSDK_PYTHON=/Library/Frameworks/Python.framework/Versions/2.7/bin/python" but it didn't help. Also added this line to my .bash_profile
Anyone else having this problem or can suggest a fix?
I have a fix below, but I'll happily award the answer to anyone who can explain what is going on.
I had the same issue . I solved it by using the default python2.7 in Ubuntu
Type this in termimal
export CLOUDSDK_PYTHON=/usr/bin/python
Not sure if this will work the same on Windows
I followed the answer here, worked for me
https://stackoverflow.com/a/59816812/2210667
brew switch openssl 1.0.2q (or whatever latest version you have from ls /usr/local/Cellar/openssl)
I figured out what was causing the problem, though I don't understand what is going on... When reinstalling gcloud I skipped the install script (./google-cloud-sdk/install.sh) since it is an optional step and I already had the needed lines in my bash profile.
When running this script, however, I got this error:
$ ./google-cloud-sdk/install.sh
Welcome to the Google Cloud SDK!
Traceback (most recent call last):
File "/Users/.../google-cloud-sdk/bin/bootstrapping/install.py", line 8, in <module>
import bootstrapping
File "/Users/.../google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 17, in <module>
import oauth2client.contrib.gce as gce
File "/Users/.../google-cloud-sdk/lib/third_party/oauth2client/contrib/gce.py", line 23, in <module>
import httplib2
File "/Users/.../google-cloud-sdk/lib/third_party/httplib2/__init__.py", line 29, in <module>
import email
File "/Users/.../GIT/GAE_Project/email.py", line 1, in <module>
ImportError: No module named google.appengine.ext
A file I recently created in my GAE project named email.py broke gcloud!?! Renaming this file fixed gcloud.
This is my PYTHONPATH:
/Users/.../google-cloud-sdk/platform/google_appengine:/Users/.../GIT/GAE_Project
So even though the Google cloud libraries come before my GAE project in my PYTHONPATH, a file in my GAE project broke gcloud.

Python Django error related to urllib3

Error:
ImportError: No module named packages.urllib3.poolmanager
I have set requests module in requirements.txt like this:
requests>=2.5.1
requests contains another version of urllib3. What could be going wrong?
Can you add your error traceback message?
from requests.packages.urllib3.poolmanager import PoolManager
See if the above solves it
This was caused by not using virtualenv. It was resorting to the system python which was causing this error.

Import error web "no module named web"

I did an web application using web.py and after a while I realize that my python compiler was configure to use python2 instead of python3 (both are installed). With python2 my application was working but I got string in unicode so I try to execute my code using python3:
python3 mycode.py
But I get different kind of error, the lib urlparse was not found (this problem was cause by a new name in python3 which is urllib) but I got a problem with:
import web
The return error is:
ImportError: No module named 'web'
I can't figure out where the problem come from.
Web.py cannot work with python3, this is the linked to the gitub project.
https://github.com/webpy/webpy/issues/108
Maybe you have installed web in your python2 lib but you have none in python3 lib... Check it out