Questions about errors from Pylint - python

I'm trying to use pygame for the first time by following a tutorial on Youtube.
I realized that Pylint points out a lot of errors that I think are irrelevent, such as "C0114:missing-module-docstring". Is there a way to "customize" what Pylint displays ? I find myself with a lot of blue underlining in my whole code which is unpleasant, and I don't want to uninstall Pylint because it can be handy when I make a typo, for example.
There is also an error that I don't understand : "E0611:no-name-in-module". This is shown at the beginning of my code when I try to import a module from pygame :
from pygame.math import Vector2
This is strange because my game runs using this module without any problems. It also occurs when I call functions from pygame such as :
pygame.init()
Again, it works, but it's underlined in red and shows an error. Is there any way to fix this ?
I tried to go in the settings to see if I could modify something regarding Pylint errors, with no success.

You can control what checks pylint does with a separate .pylintrc configuration file, just add one to your project root and pylint should use it automatically. You can create one for yourself from scratch, use the builtin generator with pylint --generate-rcfile or try finding a ready template on the web such as:
https://www.codeac.io/documentation/pylint-configuration.html
https://gist.github.com/rpunkfu/3cd6f8b8b23e27adedbd

Related

Problem in PyCharm with import function/class from standard module

I am coding in PyCharm and to set up the environment I use poetry, python version 3.10
Everything was working ok, but starting from one moment of time I got problem with module imports.
But the problem does not relate to the import of the whole module but to the import of class or function from module.
You can see as an example that BaseSettings from pydantic is underlined with red wavy line and Pycharm says that BaseSettings is unresolved reference.
I tried
to invalidate cache in Pycharm
install, uninstall the module (poetry add/remove)
change the environment and return back
marked folder as a source root (assume it is irrelevant but anyway)
but unfortunately nothing helped
aiohttp.client.py
aiohttp.init.py
I found the out what was the reason for this strange behaviour. It was the problem of PyCharm IDE. PyCharm stopped recognising init.py as python files that produced import errors. Actually I do not know why this happened since I did not changed any settings or updated PyCharm.
The solution was to manually add pattern "init.py" to python files mask in Settings -> Editor ->File types -> Python (please see screenshot in the attachment)

jupyter crashes without error message when using tkinter and sklearn KMeans

I have a simple user interface with tkinter that works perfectly fine. However, when I import another python module, whenever I use the button that calls this specific line of code (the second one):
from tkinter.filedialog import *
files = askopenfilenames()
(which works fine normally and even gets the files etc...) Jupyter notebook crashes without any error message, making it hard to understand what the problem is. After investigating, I discovered that this error happens because in the other module that I import in this interface file, there is this import:
from sklearn.cluster import KMeans
When I comment out this import in the other module and try again, the button event works fine and allows me to select files. However, when I uncomment that import line again, the same problem happen.
Since there is no error message, it is hard to understand the problem and I searched but couldn't find any known problem between KMeans and this Tkinter function. Any help would be really appreciated.
Due to the lack of error message, it was impossible to find the exact cause of the problem. Suspecting a conflict in libraries, I created a new environment and installed libraries again. If anyone faces a similar issue, I suggest using conda to install libraries instead of pip as much as possible, and only use pip when no other choice is present.

No module named 'pygame.base'

I've been having a lot of trouble converting one of my python projects into an executable with the use of pyinstaller. Upon launching the .exe, it gives this rather simple error that I just can't get my head around. The script works as intended in the editor (pycharm in this case).
In pyinstaller there is a single warning message displayed, "Hidden import "pygame._view" not found!"
I've tried using 32 and 64 bit versions of pygame, reinstalled several times and purged pip cache history.
I'm aware images aren't liked around here, but the .exe only remains open for one frame, I simply don't have enough time to copy the actual text.
Full error message
If the code works fine in pycharm, then it might just be an issue with importing the module in the script. At least that's what the error emssage seems to be saying. Do you specifically import pygame.base or the like in the __init__.py script?

Can't Install Vect2D

I'm following a pygame tutorial, and in it, you need to use multiple different modules. I was able to download all of them, except this one called Vec2D. When I try to run it in command prompt, it gives me this:
This is really weird because it gives no output - the module isn't set up and I don't get an error. When I try to test it later, it doesn't work. Does anyone know how to help me?
The instructor has written his own module, called vec2d_jdm.py containing a class called Vec2D.
You don't need to install it, just make sure that the file vec2d_jdm.py is in the same folder as the code you're running and from vec2d_jdm import Vec2D at the top of your code where you import everything else (such as pygame I imagine).

PyCharm autocomplete does not work with pygame

I've just installed PyCharm Community Edition 3.4.1 and tried to make a simple pygame project in it. I found that code completion runs in a weird way. In this case:
from pygame import event
event.
when I type event. a completion popup with event methods shows immediately. But in the second case:
import pygame
pygame.event.
a popup contains only object methods.
How can I learn the autocomplete tool to look deeper into the library?
Other than creating your own skeletons, you can't. You can make pycharm a little better a code completion if you enable the following:
But other than that, you're out of luck. Python is hard to make code completion for because its a dynamic language, and stubs (skeletons) don't exist for everything.
I tried Daid's answer (removing the try/except in init.py) and it didn't work, but it was very close! Here is how you can fix it specifically for pygame:
Go to your pygame folder and open init.py in a text editor
Navigate to the import section with the try/except clauses (around line 109)
Change the format from import pygame.module to from pygame import module for the modules you want
For example, change
try: import pygame.event
to
try: from pygame import event
Restart PyCharm and it should work :)
It has to do with how pygame is constructed.
The:
python\Lib\site-packages\pygame\__init__.py
File contains the following construction:
try: import pygame.cdrom
except (ImportError,IOError):cdrom=MissingModule("cdrom", geterror(), 1)
Which allows missing imports. However, this confuses pycharm. Removing the try+except will fix the pycharm auto completion.

Categories

Resources