in Education by
I'm trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ Core.py __init__.py tests/ Core_test.py __init__.py In core_test.py I have the following import statement from ..components.core import GameLoopEvents However, when I run, I get the following error: tests$ python core_test.py Traceback (most recent call last): File "core_test.py", line 3, in from ..components.core import GameLoopEvents ValueError: Attempted relative import in non-package Is there anything I'm missing here? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You need to use the following command like a package which you are not doing while you are running in your CLI:- pkg/ __init__.py components/ core.py __init__.py tests/ core_test.py __init__.py To get the desired output as you want you to need to use it as a package. And when you are running the command make sure you are outside of directory pkg at the time when you call the package from CLI. If you want to use import components.core you can use it directly by appending the current directory to sys.path: if __name__ == '__main__' and __package__ is None: from os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) If You want to learn python for data science visit this python course by Intellipaat.

Related questions

0 votes
    I'm new to Python and I want to install some packages with pip. But pip install unroll gives me: Command " ... How to solve this? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    How can I import the functions from file.py to another Python file which is in: app/app1/Folder1/xyz. ... folder1.xyz import func_name Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Python's easy_install makes installing new packages extremely convenient. However, as far as I can tell, it doesn't ... or similar)? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I work on Mac OSX and want to install a RJSONIO package in my R, I am a beginner currently and I have no ... someone explain it to me? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    The install.packages() function in R is the automatic unzipping utility that gets and install packages in R. ... accesses packages? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am a learner and just want to know the basic concept of super(). Here in the given code I want to know ... () ChildOne() ChildTwo() Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I've recently seen quite a bit of the following pattern in Python: class Foo: pass class Bar: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm learning the Python programming language and I've come across something I don't fully understand. In a method ... know very much. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Can anyone please explain, what is setup.py and how can it be configured or used? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    So for a HW assignment, we're making a Yahtzee game. At least part of it. For preparation, our ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    How can I load a Python module given its full path? Note that the file can be anywhere in the filesystem, ... a configuration option. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How do I import other files in Python? How exactly can I import a specific python file like import file.py? How ... gap from extra.py? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
...