boto3 cannot import name copy - python

I installed boto3 few weeks ago and all worked fine until now
tried to reinstall pip, reinstall boto3,reinstall aws cli, update machine (yum update) but nothing helped
File "./get_reports.py", line 4, in <module>
import boto3
File "/usr/lib/python2.7/site-packages/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/usr/lib/python2.7/site-packages/boto3/session.py", line 17, in <module>
import botocore.session
File "/usr/lib/python2.7/site-packages/botocore/session.py", line 25, in <module>
import botocore.configloader
File "/usr/lib/python2.7/site-packages/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/usr/lib/python2.7/site-packages/botocore/compat.py", line 172, in <module>
import xml.etree.cElementTree
File "/usr/lib64/python2.7/xml/etree/cElementTree.py", line 3, in <module>
from _elementtree import *
File "<string>", line 1, in <module>
ImportError: cannot import name copy
aws --version
aws-cli/1.15.3 Python/2.7.5 Linux/3.10.0-693.17.1.el7.x86_64 botocore/1.10.3
Same error when using botocore
code:
#!/usr/bin/env python
import boto3
import json
import csv
client = boto3.client('iam')
response = client.get_account_authorization_details(
)

Your version of boto3 is probably not the same as botocore
try running
pip freeze| grep boto
If the versions are different run
pip install --upgrade botocore
pip install --upgrade boto3

By any chance do you have a copy.py file in your current directory ? Try renaming it, if that's the case

Related

ModuleNotFoundError: No module named 'psycopg2.extras'

I'm using Mac M1 and I'm having trouble opening Odoo. I try to run the command python3 odoo-bin --i base d db15 --limit-memory-hard 0 but it fails
File "/Users/simjiahong/odoo/odoo-bin", line 5, in <module>
import odoo
File "/Users/simjiahong/odoo/odoo/__init__.py", line 113, in <module>
from . import modules
File "/Users/simjiahong/odoo/odoo/modules/__init__.py", line 8, in <module>
from . import db, graph, loading, migration, module, registry
File "/Users/simjiahong/odoo/odoo/modules/graph.py", line 10, in <module>
import odoo.tools as tools
File "/Users/simjiahong/odoo/odoo/tools/__init__.py", line 21, in <module>
from .convert import *
File "/Users/simjiahong/odoo/odoo/tools/convert.py", line 33, in <module>
from odoo import SUPERUSER_ID, api
File "/Users/simjiahong/odoo/odoo/api.py", line 1024, in <module>
from odoo.modules.registry import Registry
File "/Users/simjiahong/odoo/odoo/modules/registry.py", line 21, in <module>
from odoo.sql_db import TestCursor
File "/Users/simjiahong/odoo/odoo/sql_db.py", line 21, in <module>
import psycopg2.extras
ModuleNotFoundError: No module named 'psycopg2.extras'```
Have you tried installing the psycopg2 python module?
I haven't used M1 Mac (or any Mac recently), but in general (Linux/Windows/Android) you can install python modules using the pip or pip3 command (whichever exists on your system). Like this:
pip3 install psycopg2
or:
pip install psycopg2
You might need root access to do this, or use the --user option, like:
pip3 install --user psycopg2
Also, you can use a similar command if you use a virtual environment inside that (venv, anaconda, etc.).

Importing pysftp issue

I am facing this error every time I try to import pysftp in my training.py in the ml.azure.com pipelines. I am using Conda to create the environment for the workspace.
Traceback (most recent call last):
File "start_training.py", line 18, in <module>
import pysftp
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/pysftp/__init__.py", line 12, in <module>
import paramiko
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/transport.py", line 89, in <module>
from paramiko.dsskey import DSSKey
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/dsskey.py", line 37, in <module>
from paramiko.pkey import PKey
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/pkey.py", line 31, in <module>
import bcrypt
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/bcrypt/__init__.py", line 25, in <module>
from . import _bcrypt # type: ignore
ImportError: libffi.so.7: cannot open shared object file: No such file or directory
What I tried and failed:
I also tried to import the older version of pysftp which doesn't have dependency on libffi.so,
I tried with several versions of pysftp.
I tried installing the dependencies of pysftp.
I tried installing paramiko separately with current and older version.
I tried installing the bcrypt with current and older version.
I tried installing libffi.so with current and older version.
I tried creating new environments.
I tried by updating conda and pip also.
I tried to create simlink between libffi.so.6 and libffi.so.7 also.
So far, nothing works.
Help needed on this.

No module named certifi

When executing python3 (Python 3.6.8) script on a local directory, it works well, but when running sbatch job in slurm, complains about certifi.
python3 -m pip install certifi
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: certifi in /usr/local/lib/python3.6/site-packages (2020.12.5)
After adding to the python code this:
import sys
import os
sys.path.append(os.getcwd())
or this:
import sys
import os
module_path = os.path.abspath(os.getcwd())
if module_path not in sys.path:
sys.path.append(module_path)
the same error occurs. It seems that certifi is installed.
pip show certifi
Name: certifi
Version: 2020.12.5
Summary: Python package for providing Mozilla's CA Bundle.
Home-page: https://certifiio.readthedocs.io/en/latest/
Author: Kenneth Reitz
Author-email: me#kennethreitz.com
License: MPL-2.0
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by: requests
The error after running python code (without having the line 'import certifi' in python code):
Traceback (most recent call last):
File "/home/username/test/test.py", line 19, in <module>
from textattack.augmentation import WordNetAugmenter, EmbeddingAugmenter, EasyDataAugmenter, CharSwapAugmenter
File "/home/username/.local/lib/python3.6/site-packages/textattack/__init__.py", line 12, in <module>
from . import (
File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/__init__.py", line 21, in <module>
from .attack_recipe import AttackRecipe
File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/attack_recipe.py", line 9, in <module>
from textattack.shared import Attack
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/__init__.py", line 11, in <module>
from . import utils
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/__init__.py", line 1, in <module>
from .install import *
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/install.py", line 9, in <module>
import requests
File "/home/username/.local/lib/python3.6/site-packages/requests/__init__.py", line 118, in <module>
from . import utils
File "/home/username/.local/lib/python3.6/site-packages/requests/utils.py", line 25, in <module>
from . import certs
File "/home/username/.local/lib/python3.6/site-packages/requests/certs.py", line 15, in <module>
from certifi import where
ModuleNotFoundError: No module named 'certifi'
The error (with having the line 'import certifi' in python code):
Traceback (most recent call last):
File "/home/username/projecttest_LR_attack/LR_attack.py", line 17, in <module>
import certifi
ModuleNotFoundError: No module named 'certifi'
What could be the solution to the issue?
for anyone on MacOS and already ran pip install certifi and still doesn't work
Go to your applications folder > find your python version folder -> double click on the file Install Certificates.command inside the python folder to install the certificate.
wait for it to complete the installation
After that, you can try running your code with requests package again
Are the same modules installed on the compute nodes as locally? You may need to check with the Slurm admins.
This could mean that /usr/local/lib/python3.6/site-packages/ is not your PYTHONPATH environment variable that sbatch job in slurm has access to. You can either add it or append it during runtime:
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
pip install certifi
Try this command on the CLI

PSSH private key issue

I'm new to PSSH. I followed the PSSH document to write the script. When I use Private key, it returns with the error "ImportError: No module named ecdsakey"
I tried downloading that module but there is no "ecdsakey" modul,the module available is "ecdsa" and it's already installed. Searched everywhere but couldn't find the relevant answer.I'm using ubuntu14.04 OS
from __future__ import print_function
from pprint import pprint
import paramiko
from pssh.pssh_client import ParallelSSHClient
from pssh.exceptions import AuthenticationException,UnknownHostException,ConnectionErrorException
client_key = paramiko.RSAKey.from_private_key_file('/home/ubuntu/Downloads/pssh.txt')
client=ParallelSSHClient(['ip1','ip2'],pkey=client_key)
try:
output=client.run_command('ls /',sudo=True)
except(AuthenticationException,UnknownHostException,ConnectionErrorException):
pass
Error:
Traceback (most recent call last):
File "pssh1.py", line 4, in <module>
from pssh.utils import load_private_key
File "/usr/local/lib/python2.7/dist-packages/pssh/__init__.py", line 33, in <module>
from .pssh_client import ParallelSSHClient
File "/usr/local/lib/python2.7/dist-packages/pssh/pssh_client.py", line 36, in <module>
from .ssh_client import SSHClient
File "/usr/local/lib/python2.7/dist-packages/gevent/builtins.py", line 93, in __import__
result = _import(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pssh/ssh_client.py", line 32, in <module>
from .utils import read_openssh_config
File "/usr/local/lib/python2.7/dist-packages/gevent/builtins.py", line 93, in __import__
result = _import(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pssh/utils.py", line 27, in <module>
from paramiko.ecdsakey import ECDSAKey
File "/usr/local/lib/python2.7/dist-packages/gevent/builtins.py", line 93, in __import__
result = _import(*args, **kwargs)
ImportError: No module named ecdsakey
Try these commands:
sudo pip install ecdsa
If you are on Python 3.x you might have to use pip3 instead of pip:
sudo pip3 install ecdsa

ImportError from python-fitbit

I'm trying to use the python-fitbit package with Python 3.4 to get information from Fitbit (https://github.com/orcasgit/python-fitbit).
Whenever I run it, I get the following error. Right now oauthlib is installed, and I've tried uninstalling and reinstalling it to no avail. Any thoughts would be appreciated.
File "/usr/local/lib/python3.4/dist-packages/fitbit/__init__.py", line 10, in <module>
from .api import Fitbit, FitbitOauth2Client
File "/usr/local/lib/python3.4/dist-packages/fitbit/api.py", line 12, in <module>
from requests_oauthlib import OAuth2, OAuth2Session
File "/usr/local/lib/python3.4/dist-packages/requests_oauthlib/__init__.py", line 1, in <module>
from .oauth1_auth import OAuth1
File "/usr/local/lib/python3.4/dist-packages/requests_oauthlib/oauth1_auth.py", line 6, in <module>
from oauthlib.common import extract_params
ImportError: No module named 'oauthlib'
Where in your file system did you install oauthlib?
Please make sure that oauthlib is in your python path.
In order to check your python path you can execute:
import sys; print sys.path

Categories

Resources