Could not find QHash class in PyQt5 - pyqt

I'm trying to import QHash class from PyQt5.QtCore but no luck.
I got an error
AttributeError: module 'PyQt5.QtCore' has no attribute 'QHash'
Could anyone know how to do it?
Thanks a lot.

Related

getting error 'tensorflow.python.ops.rnn_cell_impl' has no attribute '_linear'

I tried the below line of code, but it is giving me the below error
y = rnn_cell_impl._linear(slot_inputs, attn_size, True)
AttributeError: module 'tensorflow.python.ops.rnn_cell_impl' has no attribute '_linear'
I am currently using Tensorflow version 2.10, I tried with all possible solutions by using
#from tensorflow.contrib.rnn.python.ops import core_rnn_cell
or
#from tensorflow.keras.layers import RNN
still no solution.
Can someone help me with the same?

Not able to find out the version of a module

I have imported norm as:
from scipy.stats import norm
I want to find out the version using:
print(scipy.__version__)
but it is raising an error called:
NameError: name 'scipy' is not defined
if i am using this:
print(norm.__version__)
but it is raising another error called:
AttributeError: 'norm_gen' object has no attribute '__version__'
Please help me to solve this issue.
Thanks
The line from scipy.stats import norm doesn't make the name scipy available in your current namespace. To use scipy.__version__, you must first import scipy.
In [57]: import scipy
In [58]: print(scipy.__version__)
1.4.1

Why does unittest.mock.patch work with testfixtures?

Why doesn't accessing unittest.mock.patch throw an attribute error when I import testfixtures in the below code?
I myself suspect that it is because testfixtures might be importing unittest.mock somewhere internally however, is there any way I could change this behavior if I want unittest.mock to always be imported explicitly and get an AttributeError otherwise?
import unittest
import sys
import os
import testfixtures
class Test(unittest.TestCase):
#unittest.mock.patch('sys.version_info', (2,7,0))
def test_version(self):
assert(sys.version_info < (3,0,0))
Accessing unitest.mock without importing it should throw an AttributeError but that's not the case when testfixtures is imported.

python confusion on importing modules

I saw this statement
from django import forms
the folder structure is
django\
__init__.py
forms\
__init__.py
..(continues)
My doubt is instead of the above statement why cant we imports forms like this.
import django.forms
when i tried this in pycharm. it says unused import statement.
the following is my code:
#from django import forms
import django.forms
from .models import Post
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ('title', 'text',)
it gives me error
class PostForm(forms.ModelForm):
NameError: name 'forms' is not defined
From python's docs,
... when using syntax like import item.subitem.subsubitem, each item
except for the last must be a package; the last item can be a module
or a package but can’t be a class or function or variable defined in
the previous item.
Then since its __init__.py designates forms as a package, you should be able to import it via import django.forms. Accessing its members will be different since where before you wrote forms.x now you would write django.forms.x.

unable to use Qt.OpenHandCursor attribute to set cursor shape

I have a python project that do the following import
from PyQt4 import QtGui, QtCore
I would like to change the cursor's shape at certain point, for example, I would create a new QCursor object
self.cursor_oh = QCursor()
self.cursor_oh.setShape()
most documentation and searches I did indicate to just set the shape using enum type such as:
Qt.OpenHandCursor
But, such enum is not recognized and it always results in the following error message:
AttributeError: 'module' object has no attribute 'OpenHandCursor'
So, what am I missing here?
Apparently, the Qt namespace is under QtCore, so by adding the QtCore qualifier, it found all of the Qt cursor types.
I haven't tried this in PyQt4 but in PyQt6 it has to be:
QtCore.Qt.CursorShape.OpenHandCursor

Resources