Python3 module pakaging files structure and init file - python-3.x

I have Python module with single file and single function inside the file. I've uploaded it to pypi, and I used following structure to package it, but when I called the function which it inside module file I received this error:
AttributeError: module 'effInput' has no attribute 'ask'
('ask' is name of function).
Module package structure :
|--effInput
|--__init__. py
|--effInput.py (module file)
|--setup.py
|--readme.txt
|--LICENSE
init.py file:
import effInput
name="EffInput"
What I did wrong?

When you do it that way you have to call effInput.effInput.ask instead of effInput.ask. If you did from effInput import * in your __init__.py it should work as intended.

Related

getting ModuleNotFoundError: No module named <user defined library>

I have the following folder structure and a user created file name paths.py that has functions to deal with path related operations
project_home:
-paths.py
project_1:
main.py
project_2:
main.py
etc
when I try to import paths in main.py in the subfolders it say, it works only if I call the file from the project home only ...
error :
import paths
ModuleNotFoundError: No module named 'paths'
any idea on what I could do to import files from home directory ... usually if the files are under subfolders we can call them using "Import subfolder.file" since its in main working directory the command Import paths is failing is what I am feeling ...

ModuleNotFoundError: No module named '__main__.MetricsWindow'; '__main__' is not a package

what is this error please help me iam getting it in python & iam new ? iam using the open source code of simso simulator
ModuleNotFoundError: No module named 'main.MetricsWindow'; 'main' is not a package
This error: ModuleNotFoundError: No module named '__main__.MetricsWindow'; '__main__' is not a package may also occur if you have named the main program file you created as __main__.py and try to run it as python __main__.py or another file has the name __main__.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.

How do I import a file to execute a function

I have a file with a function. I want to import the file and when doing that I get No module named ex25.
import ex25
I have checked some tutorials and the offial documentation.
import ex25
No module named ex25
First, check if the file is .py file and in the same folder with the file that you are currently working on, there shouldn't be any problem at all.
If not in the same folder, but in a different folder and make sure that your file is .py file, you need to make that folder (which contains the file) to a package by adding a file name __init__.py

ModuleNotFoundError: No module named 'app'

Whenever I run this script under the folder app/klarna_basic/klarna_basic_test.py, I always get the error:
ModuleNotFoundError: No module named 'app'.
The code used for importing is,
from app.Fortnox import Fortnox
Fortnox.py is located in app(app/Fortnox.py) folder.
See the image below.
What seems to be problem on this one?
it looks like Fortnox.py is inside the subfolder klarna_basic
from klarna_basic.Fortnox import Fortnox
orimport klarna_basic.Fortnox

AttributeError when packaging python library

I'm in the process of learning how to package a python library using the official guide. I've started cloning the minimal sample package suggested in the guide here. I've then added the file my_module.py inside the folder sampleproject storing a simple power function. Another function is also stored in /sampleproject/sampleproject/__init__.py. The resulting structure of the library is the following
Finally, I've used pip to successfully install the package in the interpreter. The only thing left is to make sure that I'm able to run the functions stored in the subfolder sampleproject.
import sampleproject
sampleproject.main()
# Output
"Call your main application code here"
This is great. The package is able to run the function in __init__.py. However, the package is not able to find module.py:
import sampleproject
sampleproject.module
# Output
AttributeError: module 'sampleproject' has no attribute 'module'
I've tried to add __init__.py in the main folder and to change the settings in entry_points in setup.py without success. What should I let sampleproject to be able to find the function in module.py?
Your sampleproject.module is a function you would like to execute?
In this case, do as for the sampleproject, add () to execute it:
sampleproject.module()
Otherwise, you can import your package like this:
import sampleproject.module
or:
from sampleproject import module
To be clearer, you would have to import module in your sampleproject __init__.py. Then, when you want to use the package, import it (is some py file at root):
import sampleproject # is enough as it's going to import everything you stated in __init__.py
After that, you can start to use what's in the package you imported with maybe module() if you have a function called module in your package.
init.py discussions
it seems,
you are in sampleproject->module.py
so you need to try,
from sampleproject import module

Resources