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'
Related
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
import numpy as np
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 57, in <module>
from numpy.testing import Tester
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 14, in <module>
from .utils import *
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
from tempfile import mkdtemp
File "/usr/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
File "/home/anirrudh/OMSCS/Courses/ML4T/ml4t/mc3_p2/random.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
import numpy.ma as ma
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/__init__.py", line 44, in <module>
from . import core
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/core.py", line 30, in <module>
import numpy.core.umath as umath
AttributeError: 'module' object has no attribute 'core'
I am working on Ubuntu 14.04. I tried reinstalling numpy, created a new virtualenv, but it isn't helping. I get the same error outside the virtualenv as well. It stopped working suddenly. It was fine until a little while ago.
(Answer posted on behalf of the OP).
Update: Resolved.
I had created a python file for one of my projects name random.py and when numpy is imported, it was calling this file instead of it's own library file hence resulting in the error. I had to delete/rename random.py which I created and that fixed the issue.
Try running it in Python 2 instead of Python 3 - you may have the older version of Spark
This happened to me in Windows with Anaconda. I fixed it by removing the python3 path from the environment variable PATH.
Another common problem here (which I had)...check to make sure you dont have a PYTHONPATH env var pointing to a different version of python site-packages (this happened because I updated my python version and didn't change this...it loads from PYTHONPATH first).
It happened to me in a specific ipynb, once I crated a copy of the notebook with a different name I was able to import numpy.
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.
With Windows, I am following this Flask tutorial when I came across the following error:
C:\Users\Gregory Gundersen\Documents\Research\flask-test>python run.py
Traceback (most recent call last):
File "run.py", line 2, in <module>
from app import app
File "C:\Users\Gregory Gundersen\Documents\Research\flask-test\app\__init__.py
", line 1, in <module>
from flask import Flask
File "C:\Python27\lib\site-packages\flask\__init__.py", line 21, in <module>
from .app import Flask, Request, Response
File "C:\Python27\lib\site-packages\flask\app.py", line 26, in <module>
from . import json
File "C:\Python27\lib\site-packages\flask\json.py", line 25, in <module>
from itsdangerous import json as _json
File "C:\Python27\lib\site-packages\itsdangerous.py", line 14, in <module>
import hmac
File "C:\Python27\lib\hmac.py", line 8, in <module>
from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest
There are SO questions and answers, but they are for OS X/Django. Has anyone see or resolved this issue for PC/Flask before?
You appear to have half the changes made for issue 21306 (backporting hmac.compare_digest to 2.7).
Your hmac module has the lines:
from operator import _compare_digest as compare_digest
at the top, but your sys.version_info shows you are running Python 2.7.6; quoting our quick chat session:
Me: Next simple check:
import sys
print(sys.version_info)
You: sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)
The hmac version you have is for Python 2.7.7 and up, however!
You'll want to reinstall your Python; download 2.7.8 and reinstall it to make sure you have the correct binary executable for your standard library files.
This can occur when you have updated python without rebuilding your virtualenv. In this case, just regenerate your virtualenv.
I love ipython, I am learning python now as a replacement of R for data analysis. However at promt I get the following message:
$ ipython --qtconsole
Traceback (most recent call last):
File "/Library/Frameworks/EPD64.framework/Versions/Current/bin/ipython", line 5, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/__init__.py", line 46, in <module>
from .frontend.terminal.embed import embed
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/frontend/terminal/embed.py", line 39, in <module>
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 33, in <module>
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 44, in <module>
from IPython.core import prefilter
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/core/prefilter.py", line 48, in <module>
from IPython.utils.traitlets import (
ImportError: cannot import name CRegExp
Ipython worked just fine a week ago and now I get this error. Can anybody suggest what might be causing this?
As #favoretti mentioned, this is an import issue in utils.traitlets.
I would recommend upgrading to EPD 7.3 and see if that fixes the issue. I feel bad suggesting a "brush it under the carpet" solution but if you're just starting out with python delving into the bowels of IPython might be a bit of a headache.