PyQt and PyQtGraph library. qtgui.QGraphicsObject vs pyqtgraph.GraphicsObject - pyqt

I'm not sure I understand how these work (I'm not even sure if I should talk about these or this). I was reading pyqtgraph examples and found a call to a "GraphicsObject". Looked it up in pyqtgraph's documentation and it seems like they have their own QGraphicsObject class. Is that correct?
I can't manage to import the correct GraphicsObject (amongst others, like GraphicsItem and such; just using that class as an attempt to explain myself better). I've reinstalled the library so it has nothing to do with it, so... what I'm missing? I apologize in advance if the question is silly.
Example:
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
g = pg.GraphItem()
Error displayed about GraphItem in PyCharm:
Cannot find reference 'GraphItem' in 'init.py'
The inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.
*I found what was causing me the trouble. It looks like scipy didn't install correctly although it didn't give me back an error, so I just had to install it in a different way.

Related

The file is in the same directory but cannot be imported

The python version I am using is 3.8.2
I searched a lot and most of the solutions are to use sys.path.append()
But it didn't solve the problem for me, if I use from . import players
it will say
ImportError: attempted relative import with no known parent package
if i use import players it will say
ModuleNotFoundError: No module named 'players'
The code I used to fix this:
sys.path.append(".")
sys.path.append(os.getcwd() + "\\players.py")
sys.path.append(os.getcwd())
still can't fix this,It's worth mentioning that at some point sys.path.append(os.getcwd() + "\\players.py") can run
Make sure that the name of the file is actually players.py.
And not for example players.py, players .py (note the spaces).
Also check for all other "invisible" Unicode characters that would not necessarily show up.
And make sure that there is no directory players as well.
I deleted the file completely so I couldn't test it, but I ran into this problem again, it's an import order problem, I tried to import attributes.py first and then content.py, there was a problem Check, can't find attributes.py , the problem is solved when their import order is swapped, I can't understand why, but if you encounter such problems please try once (other files are not imported)
I've had similar issues and I've created a new, experimental import library for Python to solve this kind of import error: ultraimport
Instead of from . import players it allows you to write
import ultraimport
players = ultraimport('__dir__/players.py')
This will always work, no matter how you run your code, no matter what is your current working directory and no matter if there's another directory somewhere called 'players'.

how to fix "Module 'cv2' has no ---- member pylint(no-member?

I am trying to start a project to learn how to use opencv and the first problem I encountered is this : "Module 'cv2' has no ---- member pylint(no-member) as posted in the picture.
I have found some information here in Stack Overflow but I'm afraid, I might not be proficient enough to understand what is going on. Could someone point me in the right direction to solve my problem?
Thanks!
One possible reason is that you might have a file named cv2.py somewhere on your machine other than the original cv2 module and now python is importing that file rather than the cv2 module.
Or perhaps you could've downloaded a wrong cv2 module, other than that i don't see anything that could've gone wrong as you don't have a complex code. Try reinstalling the module and/or removing a file named cv2.py (if you've accidentaly created one).
You can check the module by importing the module in the terminal and check for dir, on python console type import cv2 and then dir(cv2), now you should see all the classes contained in the cv2 module.
If the program runs correctly then I guess you are facing linting issue which is answer in this [https://stackoverflow.com/questions/26657265/hide-some-maybe-no-member-pylint-errors] question.
Solution is to turn off no-member linting error using below command
pylint disable=maybe-no-member
OR
pylint --disable=E1101

importing custom module , don't load other import from the module

I'm trying to build some custom Python modules.
Even though I was able to use all modules. When I try to import a module other modules are being imported.
For example:
mod1.py
import os
import sys
def f(x):
return (x**2)
main.py
import mod1
dir(mod1.os)
how can I avoid this behaviour? The user should not be able to access the other modules from mod1. In this example os and sys.
Should I put the import statements inside the function? Are there other ways to prevent such thing?
The behavior you are seeing is perfectly normal.
Python does not hide elements quite so strongly as some other languages.
We're all adults here, and are expected to behave responsibly, without strong enforcement from the language.
Should I put the import statements inside the function?
No, your code is just fine the way it is.
If you plan to write a bunch of python code, you should follow the usual conventions that everyone else does, as shown in your example code. In main.py, if you want to access an os function, you should certainly import it there, rather than borrowing a reference from mod1.os.

seeing source code of objects in a python module

I came up with this question when I was trying to use pygame. I wrote the following line
pygame.time.
but pyCharm didn't give me a list of methods to choose. I wanted to use pygame.time.Clock() but when this happened I tried to see the source code of time but I couldn't. I was just able to see the source code of pygame module and in that, there was just the following line on 'time':
try:
import pygame.time
except (ImportError, IOError):
time = MissingModule("time", geterror(), 1)
So my question is that, what is 'time' object and where is it? is it just a compiled python file that came with pygame when I installed it? Can I see the methods inside it or is there a way to let pyCharm suggest the methods inside of it?
So my question is that, what is 'time' object and where is it?
time is not an object it is a module.
Pygame is well documented. A complete documentation of the pygame.time module can be found at pygame.time.
It is not necessary to import the module. Via pygame.time you can access all objects of the module. However, you can import all objects form the module with:
from pygame.time import *

Weird way of importing Python turtle works but I don't know why

I hope you will understand my question.
I noticed that I get the same results when I import turtle module in following two ways.
from turtle import Turtle
t=Turtle()
t.screen.bgcolor("black")
and also
import turtle
turtle.bgcolor("black")
I am confused about this, “from turtle import Turtle”.
According to what I know, it means “to import Turtle.py from turtle (folder / package)”. I may be wrong, you can help me out to understand better.
But I can’t find any Turtle.py module. It is only turtle.py I saw.
What's weird about it is that it works.
Can anyone tell me why?
I am using Python version 3.6
Python's turtle.py is unusual in that it presents both a function-based interface and an object-oriented interface. Depending on how you import it, you can work with one, or the other, or both.
Here, we are using the object-oriented interface to invoke the screen method bgcolor():
from turtle import Turtle
t = Turtle()
t.screen.bgcolor("black")
I usually write this as:
from turtle import Turtle, Screen
screen = Screen()
screen.bgcolor("black")
t = Turtle()
as having direct access to the Screen object simplifies things. Using this style import, you cannot access the function-based interface.
When we do this simpler import, we have access to both the function-based interface and the object-oriented interface. Here, we're using the function bgcolor() to set the background color:
import turtle
turtle.bgcolor("black")
Using either the function-based or object-oriented interface to turtle.py is fine, but you can get yourself seriously confused when mixing the two.

Resources