Can only run my copy_files.py from one directory - python

I can run my copy_files.py script from only one directory.
When I run it from other directories, I get the following errors:
Traceback (most recent call last):
File "./copy_py", line 36, in <module>
import paramiko
File "/usr/local/lib/python3.6/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 56, in <module>
from paramiko.dsskey import DSSKey
File "/usr/local/lib/python3.6/site-packages/paramiko/dsskey.py", line 27, in <module>
from cryptography.hazmat.primitives.asymmetric.utils import (
File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py", line 9, in <module>
from asn1crypto.algos import DSASignature
File "/usr/local/lib/python3.6/site-packages/asn1crypto/algos.py", line 26, in <module>
from .core import (
File "/usr/local/lib/python3.6/site-packages/asn1crypto/core.py", line 53, in <module>
import copy
File "/home/xjacrawf/work/pyth/copy.py", line 106, in <module>
cli = paramiko.client.SSHClient()
AttributeError: module 'paramiko' has no attribute 'client'
I have tried to remove all of the script's body, even renamed the script.
#!/usr/local/bin/python3.6
import sys
sys.path.insert(0, "/usr/local/lib/python3.6/site-packages")
import cx_Oracle
import glob
import os
import time
import paramiko
from scp import SCPClient
cli = paramiko.client.SSHClient()
cli.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
I expect the script to establish a connection, and it just errors.
I run the script from the first directory it ran from $MDS_SRC/ and it runs fine.
I can copy the entire script to my local directory , and it errors out.

Related

Import error: No module named 'secrets' - python manage.py not working after pull to Digital Ocean

I'm following along a course - Django development to deployment.
After pulling it to Digital Ocean everything else ran smoothly. Until
I tried running python manage.py help
(env) djangoadmin#ubuntu-1:~/pyapps/btre_project_4$ python manage.py help
and I get this error.
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/__init__.py", line 16, in setup
from django.urls import set_script_prefix
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/__init__.py", line 1, in <module>
from .base import (
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/base.py", line 9, in <module>
from .exceptions import NoReverseMatch, Resolver404
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/exceptions.py", line 1, in <module>
from django.http import Http404
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/__init__.py", line 2, in <module>
from django.http.request import (
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/request.py", line 10, in <module>
from django.core import signing
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/signing.py", line 45, in <module>
from django.utils.crypto import constant_time_compare, salted_hmac
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/utils/crypto.py", line 6, in <module>
import secrets
ImportError: No module named 'secrets'
I'm a newbie and have been stuck on this for a while. I just want to know what could possibly cause this.
The secrets module was added to Python in version 3.6. Your host is using Python 3.5, hence the secrets module is unavailable. You need a host with Python 3.6+, or a version of Django that doesn't depend on the secrets module
Had the same issue, solved it by specifying the python version I have installed. i.e
$ python3
>>> import secrets
>>> secrets.token_hex(16)

Issue with google library in python

I am running into an error when importing the below library
from google.cloud import vision
The error message I receive is :
Traceback (most recent call last):
File "d:/UnmatchedOTMProcess/ImageDetection_test.py", line 2, in <module>
from google.cloud import vision
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-packages\google\cloud\vision.py", line
17, in <module>
from google.cloud.vision_v1 import ImageAnnotatorClient
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\cloud\vision_v1\__init__.py", line 27, in <module>
from google.cloud.vision_v1.gapic import image_annotator_client as iac
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\cloud\vision_v1\gapic\image_annotator_client.py", line 24, in <module>
import google.api_core.gapic_v1.client_info
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\api_core\gapic_v1\__init__.py", line 16, in <module>
from google.api_core.gapic_v1 import config
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\api_core\gapic_v1\config.py", line 23, in <module>
import grpc
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-packages\grpc\__init__.py", line 23, in
<module>
from grpc._cython import cygrpc as _cygrpc
ImportError: cannot import name 'cygrpc' from 'grpc._cython'
(C:\Users\mhancock\AppData\Roaming\Python\Python38\site-packages\grpc\_cython\__init__.py)
The code works perfectly on my local machine, however trying to run this on a gcp virtual machine and the environment must be slightly different somehow.
Appreciate any assistance!
Thanks in advance,
Matt

ImportError: cannot import name 'winrandom'

I know that this question has already a ton of answers but unfortunately this hasn't fixed the issue for me. I want to run some code using PyCrytpo but winrandom doesn't want to get import.
All the other posts are for earlier releases of python. I am using Python 3.6.5 and renaming code within nt.py file to "from . import winrandom" doesn't do the trick for me.
Do you have any suggestions or is a rollback the only opportunity?
Windows 10
Python 3.6.5
Anaconda
from Crypto.PublicKey import RSA
Traceback (most recent call last):
File "<ipython-input-39-b6fe4d249eef>", line 1, in <module>
from Crypto.PublicKey import RSA
File "C:\Users\Markus\Anaconda3\lib\site-packages\Crypto\PublicKey\RSA.py", line 78, in <module>
from Crypto import Random
File "C:\Users\Markus\Anaconda3\lib\site-packages\Crypto\Random\__init__.py", line 28, in <module>
from Crypto.Random import OSRNG
File "C:\Users\Markus\Anaconda3\lib\site-packages\Crypto\Random\OSRNG\__init__.py", line 34, in <module>
from Crypto.Random.OSRNG.nt import new
File "C:\Users\Markus\Anaconda3\lib\site-packages\Crypto\Random\OSRNG\nt.py", line 28, in <module>
from . import winrandom
ImportError: cannot import name 'winrandom'

Run Python program as administrator from command line

I'm trying to run my program as an administrator from the command line. Seems quite easy but I'm struggling.
I started with this, which works fine launched from the Python IDLE:
import dropbox, pymysql, shlex, shutil, subprocess
import logging
import sshtunnel
from sshtunnel import SSHTunnelForwarder
# Main program starts here
print("Hello World!")
but that gave an error as follows:
pi#jsmd:~ $ sudo python /home/pi/Documents/iot_pm2/iot.py
Traceback (most recent call last):
File "/home/pi/Documents/iot_pm2/iot.py", line 3, in <module>
import dropbox, pymysql, shlex, shutil, subprocess
ImportError: No module named pymysql
After some Googling I added two lines at the start:
import sys
sys.path.append("/usr/local/lib/python3.4/dist-packages/")
This also works fine from the Python IDLE but gives a long error trace when run from the command line... and I'm not good enough at understanding how to read the trace and hence what I can do to fix it. (Plus I don't understand why it works from the IDLE as a non-admin but not from the command line as an admin.) Can anyone help?
pi#jsmd:~ $ sudo python /home/pi/Documents/iot_pm2/iot.py
Traceback (most recent call last):
File "/home/pi/Documents/iot_pm2/iot.py", line 5, in <module>
import sshtunnel
File "/usr/local/lib/python3.4/dist-packages/sshtunnel.py", line 25, in <module>
import paramiko
File "/usr/local/lib/python3.4/dist-packages/paramiko/__init__.py", line 30, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/local/lib/python3.4/dist-packages/paramiko/transport.py", line 50, in <module>
from paramiko.dsskey import DSSKey
File "/usr/local/lib/python3.4/dist-packages/paramiko/dsskey.py", line 26, in <module>
from Crypto.PublicKey import DSA
File "/usr/local/lib/python3.4/dist-packages/Crypto/PublicKey/DSA.py", line 89, in <module>
from Crypto import Random
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/__init__.py", line 29, in <module>
from Crypto.Random import _UserFriendlyRNG
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
from Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
from . import FortunaGenerator
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 35, in <module>
from Crypto.Util import Counter
File "/usr/local/lib/python3.4/dist-packages/Crypto/Util/Counter.py", line 59, in <module>
from Crypto.Util import _counter
ImportError: cannot import name _counter
Thanks.
is the default of python is 3 ? If not try to execute like this: sudo
python3 ... – #Koffee
Thanks to #Koffee we have an answer and this thread can be marked as solved and closed.

python files run fine when executed from different directory

I have a very wierd problem.
When i run the file from a different directory it runs fine.
but other wise i get this error
from textprocessor import *
File "/home/mohit/Documents/analysis/categorization/textprocessor.py", line 2, in <module>
import nltk
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 101, in <module>
import ccg
File "/usr/local/lib/python2.7/dist-packages/nltk/ccg/__init__.py", line 15, in <module>
from chart import *
File "/usr/local/lib/python2.7/dist-packages/nltk/ccg/chart.py", line 33, in <module>
from nltk.parse.api import *
File "/usr/local/lib/python2.7/dist-packages/nltk/parse/__init__.py", line 46, in <module>
from featurechart import *
File "/usr/local/lib/python2.7/dist-packages/nltk/parse/featurechart.py", line 24, in <module>
import nltk.data
File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 41, in <module>
import zipfile
File "/usr/lib/python2.7/zipfile.py", line 460, in <module>
class ZipExtFile(io.BufferedIOBase):
AttributeError: 'module' object has no attribute 'BufferedIOBase'
I am tryin to import nltk module
You've called a script in the same directory "io.py", and this is interfering with the io module in the stdlib. Rename it.
You must have a script in your folder named nltk.py, io.py, zipfile.py, or some such. When you run the file in the same directory, it is imported instead of the appropriate python or nltk module.
Where is nltk? Is it pure Python code? You may want to put that in site-wide modules folder or in your cwd.

Categories