error importing module you created (Python) - python

I created module that have tree functions and when I am trying to import that module I have red line under the module name and the error says "No module named data" and the file is in the same path as the file I am trying to import to. but the functions are working but it's causing bugs in my program,
Someone know how do I fix that problem?.

Related

No module named "panel. pane'; 'panel' is not a package

Panel and other holoviz package was working fine. But since yesterday, it is not working and gives following error. I checked the site packages, tried creating cond and venv based virtual environments, but dint help me. Has anyone faced similar issue?
Code:
from panel.pane import PaneBase
Error message:
ModuleNotFoundError: No module named "panel.pane"
'panel' is not a package
This error:
ModuleNotFoundError: No module named 'panel.pane'; 'panel' is not a package
may also occur if you have named the main program file you created as panel.py and try to run it as python panel.py or another file has the name panel.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where Python is looking for modules, see sys.path.
In this case, rename your program file so that its name does not equal with the name of the imported module.

Attribute Error module 'turtle' has no attribute 'Turtle'

This problem occurred to me quite recently. I have no idea what i am doing wrong due to me being a beginner in python. If anyone is interested I am using a Raspberry pi 400 and I am using VSC but anyways here is my code:
import turtle
import random
pat=turtle.Turtle()
colours=["orange","blue","red","yellow", "cyan"]
turtle.Screen().bgcolor("black")
for i in range(200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000):
for i in range(2):
pat.forward(300)
pat.right(100)
pat.right(100)
pat.forward(300)
pat.right(100)
pat.left(5)
pat.color(random.choice(colours))
Could it be that you have a file named turtle.py in the same folder, or in any other folder contained in the PYTHONPATH environment variable? In that case import turtle might not load the turtle package, but instead the local Python file, which does not contain an executable object named Turtle and hence the AttributeError is raised when calling turtle.Turtle().

"ModuleNotFoundError: No module named x" for a custom module

I've writtern a script called "utilities.py" which contains some functions I'd like to call from another script. This second script is in the same directory of the module, and when I try to run:
import utilities
I get this error:
ModuleNotFoundError: No module named 'utilities'
I've read something on the internet but I'm not really understanding how to treat modules in python, It's the first time I'm trying to do this, some help?

opsgenie-sdk modeule import error

I am trying write a python program to use the Opsgenie API's to pull some reports.
I installed the https://github.com/opsgenie/opsgenie-python-sdk
When i run my program i get the error message
"from opsgenie.alert.requests import ListAlertsRequest
ImportError: No module named requests"
The module is present in the site packages folder and I also added the path to the folder to PYTHONPATH.
It happened for multople module I am not sure if the dependencies work on the opsgenie-sdk.
Has anyone had this issue?
Help appreciated.

How to check syntax errors of a Python module with unknown imports

I want to invoke the Python interpreter to check possible syntax errors of my module.
I can't do it because the interpreter generates an early error message of
ImportError: No module named Part
In my module I have imported a module that is needed in my code.
import Part
def draw_circle(radius):
myshape = Part.makeSphere(1)
Part.show(myshape)
return
The imported Part module belongs to FreeCAD in my case but my question is general. Let's assume that we don't know the module library directory path of the module Part.
When in FreeCAD I import my syntactically correct module everything runs without problems.
import sys
sys.path.append('/home/mypathtomymodule')
import mymodule
mymodule.draw_circle(1)
There is no problem as long as I write proper syntax code. Unfortunately I don't always do that. In those cases my problem is that I can not search for the syntax errors in my module with the Python interpreter. Also the FreeCAD is not very helpful here, When I try to run the program in FreeCAD it gives an uninformative error message like
NameError: name 'badcode' is not defined
You can use python -m py_compile mymodule.py. This produces a byte code file, but can be used to check for syntax errors in the process.

Categories

Resources