Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PyCharm Importing Module Question I'm having an issue importing the Point.py module into MyKmeans.py and Ultility.py files. When I run the files I get the

PyCharm Importing Module Question

I'm having an issue importing the Point.py module into MyKmeans.py and Ultility.py files. When I run the files I get the error message below.

' from .Point import * ImportError: attempted relative import with no known parent package'

View the images.

Can anyone assist?

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Project 0 7 0 - main.py _init_.py X MyKmeans.py X Point.py X [ Utility.py pythonProject C:\\Users\\cchar\\PycharmProjects\\ pythonProject\\pythonProject from . Point import * mid_kmeat- -.a.IFA from . MyKmeans import * data 3 Gfrom .Utility import * v libs _init_py MyKmeans.py Point.py Utility.py output _init_.py main.py Il mid _kmean_.. IIlli External Libraries Scratches and Consoles Run: _init_ C:\\Users\\cchar \\anaconda3\\python. exe c:/Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean_w/libs/__init__.py Traceback (most recent call last) : File "C:/Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean a/libs/__init__py", line 1, in from . Point import * ImportError: attempted relative import with no known parent package Process finished with exit code 1Project 0 = * * - main.py X _init_.py X MyKmeans.py X Point.py X Utility.py> pythonProject C:\\Users\\cchar\\PycharmProjects\\ pythonProject\\ pythonProject import random v D mid_kmean from . Point import * data 3 v D libs _init_py 5 def check_same_coordinate (pt1, pt2) : MyKmeans.py 6 Point.py if (pt1.x == pt2.x) and (pt1.y == pt2.y) and (pt1.z == pt2.z) : Utility.py return True > output 18 else: _init_.py return False main.py 10 Il mid_kmean 11 lilli External Libraries 12 def generate_points (num_point=10, dimension=2, lower_bound=(0, 0), upper_bound=(10, Scratches and Consoles 13 14 Function to generate random points 15 :param num_point: a number of points to generate (integer) 16 :param dimension: a number of dimension (integer) 17 : param lower_bound: a lower bound coordinate (tuple) 18 : param upper_bound: an upper bound coordinate (tuple) 19 :return: a list of random points 20 21 # random . seed (0) 22 points = 23 for i in range (num_point) : 24 x = random . uniform (lower_bound[0], upper_bound [0]) 25 y = random. uniform (lower_bound [1], upper_bound [1]) generate_points0 Run: Utility C: \\Users\\cchar \\anaconda3\\python . exe C:/Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean Libs/Utility . py Traceback (most recent call last) : File "C: /Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean /libs/Utility. py", line 2, in from . Point import * ImportError: attempted relative import with no known parent package Process finished with exit code 1Project 01 0 - main.py X _init_.py X MyKmeans.py X Point.py X Utility.py X pythonProject C:\\Users\\cchar\\PycharmProjects\\pythonProject\\pythonProject 1 from . Point import * v Dl mid_kmeans 2 from . Utility import * data 3 import matplotlib . pyplot as pit v bl libs import numpy as np _init_.py 5 import random MyKmeans.py 6 Point.py Gimport sys 7 Utility.py output 18 class MyKmeans: _init_.py main.py 10 MyKmeans Class Il mid_kmean 11 lilli External Libraries 12 Scratches and Consoles 13 def _init_(self, k, num_points=100, dimension=2, lower_bound=(0, 14 15 MyKmeans class constructor 16 : param k: the number of clusters, k in K-Means Clustering 17 : param num_points: the number of points 18 :param dimension: the dimension of a point 19 : param bound lower: 20 : param bound_upper: 21 22 self . k = k 23 self . num_points = num_points 24 self . dimension = dimension 25 self . lower_bound = lower_bound MyKmeans > _init_0 Run: Utility x C: \\Users\\cchar \\anaconda3\\python . exe C:/Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean /libs/Utili Traceback (most recent call last) : File "C: /Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean libs/Utility.py", line 2, in from . Point import * L ImportError: attempted relative import with no known parent package Process finished with exit code 1Project 01 7 0 - main.py X _init_py X MyKmeans.py X Point.py X Utility.py X pythonProject CA\\Users\\cchar\\PycharmProjects\\pythonProject\\pythonProject 1 Jimport sys v D mid_kmear 2 Aimport math data 3 v D libs 4 _init_.py 5 class Point: MyKmeans.py Point.py 7 Utility.py Point Class > output _init_py main.py 10 def _init_(self, x, y, z=0, clust_id=-1) : Il mid_kmean 11 IIll External Libraries 12 Point class constructor Scratches and Consoles 13 :param x: x coordinate value (numeric) 14 :param y: y coordinate value (numeric) 15 :param z: z coordinate value (numeric) 16 :param clust_id: cluster ID 17 18 self . x = x 19 self . y = y 20 self . Z = Z 21 self . clust_id = clust_id 22 23 if Z == 0: 24 self . dimension = 2 25 else : Point > _init_0 Run: Utility C: \\Users\\cchar \\anaconda3\\python . exe C:/Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean /libs/Utility . py Traceback (most recent call last) : File "C: /Users/cchar/PycharmProjects/pythonProject/pythonProject/mid_kmean Libs/Utility . py", line 2, in from . Point import * ImportError: attempted relative import with no known parent package Process finished with exit code 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions