PSSH private key issue - python

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

Related

Xcode update broke gcloud and gsutil

A few hours ago I updated Xcode to the latest version, which caused gcloud and gsutil commands to stop working. For example, a minute before the update finished, the command gsutil -m rsync was working fine.
While writing this question, I noticed I no longer have git working.
Since I'm not a Python guy, can someone please explain to me what the hell happened now? I would love some help.
python -V output is Python 2.7.16.
python3 -V output is Python 3.9.0.
pip -V output is pip 20.2.3 from /Users/<MY_USER>/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)
pip3 -V output is pip 20.2.3 from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)
This is what I get for gcloud help:
Traceback (most recent call last):
File "/Users/<MY_USER>/gcloud/sdk/lib/gcloud.py", line 104, in <module>
main()
File "/Users/<MY_USER>/gcloud/sdk/lib/gcloud.py", line 62, in main
from googlecloudsdk.core.util import encoding
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 124, in <module>
import enum
File "/Users/<MY_USER>/gcloud/sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
And this is what I get for gsutil help:
Traceback (most recent call last):
File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/gsutil.py", line 13, in <module>
import bootstrapping
File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/bootstrapping.py", line 32, in <module>
import setup # pylint:disable=g-import-not-at-top
File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/setup.py", line 57, in <module>
from googlecloudsdk.core.util import platforms
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 124, in <module>
import enum
File "/Users/<MY_USER>/gcloud/sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
So after almost a day with nothing, I found a solution: what I needed to do was set an environment variable named CLOUDSDK_PYTHON to /usr/bin/python.
I edited my .zprofile and added:
export CLOUDSDK_PYTHON="/usr/bin/python"
I still have no idea what caused it, so I'll be glad for an explanation if anyone cares to take the time.

cannot import name 'etree' from 'lxml' in home brew installed package but fine in python shell

I'm trying to run ocrmypdf which was installed via homebrew but am having issues with my local version of lxml (version 4.2.4):
Traceback (most recent call last):
File "/usr/local/bin/ocrmypdf", line 5, in <module>
from ocrmypdf.__main__ import run
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/ocrmypdf/__init__.py", line 18, in <module>
from . import helpers, hocrtransform, leptonica, pdfa, pdfinfo
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/ocrmypdf/pdfa.py", line 38, in <module>
import pikepdf
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/__init__.py", line 54, in <module>
from .models import (
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/models/__init__.py", line 13, in <module>
from .metadata import PdfMetadata
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/models/metadata.py", line 17, in <module>
from lxml import etree
ImportError: cannot import name 'etree' from 'lxml' ($HOME/anaconda3/lib/python3.7/site-packages/lxml/__init__.py)
If I open up a python shell, I'm able to import just fine:
>>> from lxml import etree
>>> etree.__file__
'$HOME/anaconda3/lib/python3.7/site-packages/lxml/etree.cpython-37m-darwin.so'
My pythonpath:
$HOME/anaconda3/lib/python3.7/site-packages:$HOME/Code_Repos/invoice2data//src:$HOME/Code_Repos/invoice2data//src/invoice2data:$HOME/anaconda3/lib/python3.7/site-packages:$HOME/Code_Repos/invoice2data
I'm not sure why the homebrewed package is not picking up the module file even though it says it's pointing to the same site-packages folder.

functools has no attribute lru_cache

I'm using Python 3.7 on my Windows
This error occurs while running every code:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import nltk
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\__init__.py", line 99, in <module>
from nltk.internals import config_java
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\internals.py", line 11, in <module>
import subprocess
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 50, in <module>
import signal
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\signal.py", line 3, in <module>
from functools import wraps as _wraps
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\functools.py", line 21, in <module>
from collections import namedtuple
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\collections\__init__.py", line 22, in <module>
from keyword import iskeyword as _iskeyword
File "C:\Users\HP\Desktop\tweepy\keyword.py", line 1, in <module>
import re
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\re.py", line 297, in <module>
#functools.lru_cache(_MAXCACHE)
AttributeError: module 'functools' has no attribute 'lru_cache'
How to fix it?
It looks like someone published a functools package on pypi, so if you had run:
# don't run this!
pip install functools
You may have accidentally installed that package. If you encounter this error, I would:
pip uninstall functools
To make sure that the functools you are using are the base package functools.
(I ended up here because I attempted to use functools.cache, which seems to only be present in Python 3.8, not earlier.)
I had the same error recently and it was because I had a file called functools.py in my project. Renaming it fixed the issue.

ImportError: cannot import name 'binary_type'

I've installed BSON library to convert strings to MongoDB ObjectIds, but when I try using the library, this comes up:
Traceback (most recent call last):
File "search.py", line 7, in <module>
from pymongo.mongo_client import MongoClient
File "/home/user/anaconda3/lib/python3.6/site-packages/pymongo/__init__.py", line 90, in <module>
from pymongo.common import (MIN_SUPPORTED_WIRE_VERSION,
File "/home/user/anaconda3/lib/python3.6/site-packages/pymongo/common.py", line 21, in <module>
from pymongo.auth import MECHANISMS
File "/home/user/anaconda3/lib/python3.6/site-packages/pymongo/auth.py", line 33, in <module>
from bson.binary import Binary
File "/home/user/anaconda3/lib/python3.6/site-packages/bson/binary.py", line 21, in <module>
from bson.py3compat import PY3, binary_type
ImportError: cannot import name 'binary_type'
Also pip installs py3compat, but there's no 'binary_type' in there.
Any idea how to fix this?
I saw this error and got it fixed by installing the newest version of pymongo.
(at the time of writing)
pip install pymongo==3.5.1

Can't import module ANTLR MyGrammarLexer and MyGrammarParser

I'm trying to start with ANTLR . When I import module antlr it's working just fine , but if I try to import MyGrammarLexer and MyGrammarParser , it's shows that MyGrammarLexer and Parser aren't in lib. I Using PyCharm , I installed ANTLR with : pip3 install antlr4-python3-runtime my code is :
import sys
from antlr4 import *
import MyGrammarLexer
import MyGrammarParser
def main(argv):
input = FileStream(argv[1])
lexer = MyGrammarLexer(input)
stream = CommonTokenStream(lexer)
parser = MyGrammarParser(stream)
tree = parser.startRule()
if __name__ == '__main__':
main(sys.argv)
Maybe whom know why i can't import MyGrammarLexer and MyGrammarParser?
Please suggest!
Tackback:
/usr/bin/python3.6 /home/andrejka/PycharmProjects/Parser/parser.py
Traceback (most recent call last):
File "/home/andrejka/PycharmProjects/Parser/parser.py", line 2, in <module>
from antlr4 import *
File "/usr/lib/python3/dist-packages/antlr4/__init__.py", line 5, in <module>
from antlr4.BufferedTokenStream import TokenStream
File "/usr/lib/python3/dist-packages/antlr4/BufferedTokenStream.py", line 19, in <module>
from antlr4.error.Errors import IllegalStateException
File "/usr/lib/python3/dist-packages/antlr4/error/Errors.py", line 5, in <module>
from antlr4.atn.Transition import PredicateTransition
File "/usr/lib/python3/dist-packages/antlr4/atn/Transition.py", line 19, in <module>
from __builtin__ import unicode
ModuleNotFoundError: No module named '__builtin__'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "/home/andrejka/PycharmProjects/Parser/parser.py", line 2, in <module>
from antlr4 import *
File "/usr/lib/python3/dist-packages/antlr4/__init__.py", line 5, in <module>
from antlr4.BufferedTokenStream import TokenStream
File "/usr/lib/python3/dist-packages/antlr4/BufferedTokenStream.py", line 19, in <module>
from antlr4.error.Errors import IllegalStateException
File "/usr/lib/python3/dist-packages/antlr4/error/Errors.py", line 5, in <module>
from antlr4.atn.Transition import PredicateTransition
File "/usr/lib/python3/dist-packages/antlr4/atn/Transition.py", line 19, in <module>
from __builtin__ import unicode
ModuleNotFoundError: No module named '__builtin__'
I ran into this problem recently when getting the same error using the pddlpy python library. I was able to fix it by doing the following:
pip3 install antlr4-python3-runtime==4.9
The version 4.9 at the end is very important.
I found out that content of the package:
https://pypi.python.org/packages/0b/6b/30c5b84d203b62e1412d14622e3bae6273399d79d20f3a24c8145213f610/antlr4-python3-runtime-4.7.tar.gz#md5=190245a0fb4abf43568489a4b6e33aba
is different from the package installed by pip3.
I have replaced content of:
~/anaconda3/envs/py3/lib/python3.6/site-packages/antlr4
with content from the package I have downloaded and extracted manually:
~/Downloads/antlr4-python3-runtime-4.7/src/antlr4
It seems to be working now - in particular the following error:
ModuleNotFoundError: No module named '__builtin__'
does not occur.
After posting your traceback I can see the error is:
ModuleNotFoundError: No module named '__builtin__'
That means the package you try to import is using python2 syntax, but you're using python3.
You should use python2 if you need to run this package, but keep in mind that you probably want to search for a different one if this is a new project.
More about why it's not working here
EDIT
They released a package with python3 support, but it seems you installed/used something different. You should verify it.

Categories

Resources