Upgrading pyopenssl with pip was not working as none of the commands related to to pip was working for me. By upgrading pyopenssl with easy_install, above problem can be solved.
sudo python -m easy_install --upgrade pyOpenSSL
credit @delimiter (Answer)
Answer from Muhammad Hassan on Stack OverflowAttributeError: module 'lib' has no attribute 'ERR_load_RAND_strings'
installation error
Error installing Django package django-tenants - Stack Overflow
python - random.randint error: "AttributeError: 'module' object has no attribute 'randint'" - Stack Overflow
Upgrading pyopenssl with pip was not working as none of the commands related to to pip was working for me. By upgrading pyopenssl with easy_install, above problem can be solved.
sudo python -m easy_install --upgrade pyOpenSSL
credit @delimiter (Answer)
Turned out the problem was with my installation of pyOpenSSL, pyOpenSSL-0.15.1 .
I did:
pip uninstall pyopenssl
and then
pip install pyopenssl
...and my Python script worked again!
You have mutual top-level imports, which is almost always a bad idea.
If you really must have mutual imports in Python, the way to do it is to import them within a function:
# In b.py:
def cause_a_to_do_something():
import a
a.do_something()
Now a.py can safely do import b without causing problems.
(At first glance it might appear that cause_a_to_do_something() would be hugely inefficient because it does an import every time you call it, but in fact the import work only gets done the first time. The second and subsequent times you import a module, it's a quick operation.)
I have also seen this error when inadvertently naming a module with the same name as one of the standard Python modules. E.g. I had a module called commands which is also a Python library module. This proved to be difficult to track down as it worked correctly on my local development environment but failed with the specified error when running on Google App Engine.
Upgrade the latest version of PyOpenSSL.
python3 -m pip install pip --upgrade
pip install pyopenssl --upgrade
As all the previous answers failed for me, I used the trick in module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK':
sudo apt remove python3-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
And then after a reboot (Starting a new shell may be enough, see comments):
pip install pyopenssl --upgrade
I'm supposed to be making a code that lets you play Rock-Paper-Scissors with the computer as part of my beginner exercises. Obviously this is gonna require me to import the random module to make the computer throw out different moves. So I first tested importing the module by making this simple code:
import random
print(random.randint(1,100))
But when I test it, the error written in the title shows up. My file is not named random.py to avoid conflicts with the imported module. Is there a workaround for this?
The problem is submodules are not automatically imported. You have to explicitly import the api module:
import myproject.mymodule.api
print myproject.mymodule.api.MyClass
If you really insist on api being available when importing myproject.mymodule you can put this in myproject/mymodule/__init__.py:
import myproject.mymodule.api
Then this will work as expected:
from myproject import mymodule
print mymodule.api.MyClass
Also check whether you didn't name your python file the same as the module you are trying to import.