Import sequences in Python 3.7 - python-3.x

I want to organize a package with this structure:
/program.py
/__init__.py
/data/
/data/__init__.py
/data/method_1.py
/data/method_2.py
/data/classes.py
program imports method_1 and method_2, method_1 and method_2 import classes. But I get an error: ModuleNotFoundError: No module named 'method_1'. How should I organize this package and what should I write in init.py files?
program.py:
import __init__
from data import classes
from data import method_1
from data import method_2
...
__init__.py:
__all__ = ['data']
from data import *
/data/__init__.py:
__all__ = ['classes', 'method_1', 'method_2']
from method_1 import *
from method_2 import *
from classes import *
/data/method_1.py: (and also /data/method_2.py)
import classes
...

method_1, method_2, and classes are all in the data package, hence:
# data/__init__.py
from .method_1 import *
from .method_2 import *
from .classes import *
...
# data/method_1.py
from . import classes

Because the data package is in the same directory with program this should work:
#program.py
from .data import classes
from .data import method_1
from .data import method_2
# data/__init__.py
from .method_1 import *
from .method_2 import *
from .classes import *
#data/method_1.py
from . import classes
#data/method_2.py
from . import classes

Related

AWS --extra-py-files throwing ModuleNotFoundError: No module named 'pg8000'

I am trying to use pg8000 in my Glue Script, following are params in Glue Job
--extra-py-files s3://mybucket/pg8000libs.zip //NOTE: my zip contains __init__.py
Some Insights towards code
import sys
import os
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
import boto3
from pyspark.sql import Row
from datetime import datetime, date
zip_path = os.path.join('/tmp', 'pg8000libs.zip')
sys.path.insert(0, zip_path)
def dump_python_path():
print("python path:", sys.path)
for path in sys.path:
if os.path.isdir(path):
print(f"dir: {path}")
print("\t" + str(os.listdir(path)))
print(path)
print(os.listdir('/tmp'))
dump_python_path()
# Import the library
import pg8000
Dump in cloudwatch
python path: ['/tmp/pg8000libs.zip', '/opt/amazon/bin', '/tmp/pg8000libs.zip', '/opt/amazon/spark/jars/spark-core_2.12-3.1.1-amzn-0.jar', '/opt/amazon/spark/python/lib/pyspark.zip', '/opt/amazon/spark/python/lib/py4j-0.10.9-src.zip', '/opt/amazon/lib/python3.6/site-packages', '/usr/lib64/python37.zip', '/usr/lib64/python3.7', '/usr/lib64/python3.7/lib-dynload', '/home/spark/.local/lib/python3.7/site-packages', '/usr/lib64/python3.7/site-packages', '/usr/lib/python3.7/site-packages']

Importing sklearn module in pyscript

how to import modules which are in form of
"from sklearn.tree import DecisionTreeRegressor" in Pyscript?
The way you import modules works as follows:
Include the relevant package in the environment
<py-env>
- scikit-learn
</py-env>
Import the module as you would do it in any other python file
<py-script>
from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier()
...
</py-script>

Import Libraries in a Python Class Package

I have created a class inside a python package. The problem is that the class uses the numpy library which is not seen when imported.
'''
import numpy as np
class NN:'''
and in the init class I wrote
'''
from net.NN import NN
'''
but when I import the package in my jupyter notebook
'''
from net import NN
'''
and I initialize the class it just gives me an error "No module named np"

Problems with pyinstaller doesn´t show all things that I created

I've been working on an app to manage a little store with Python and SQLite. For GUI I used tkinter. I've written 13 Python scripts to make the app work. One of them call "principal.py" which imports most of the scripts and the other scripts import other modules like tkcalendar or xlwt (to write excel sheets), etc...
This is an example from "principal.py" first lines of code
#===========IMPORTAR PAQUETES=============
import sqlite3
from sqlite3 import Error
import os
import sys
import tkinter as tk
from tkinter import ttk
from tkinter import *
from tkinter import scrolledtext
from tkinter import Menu
from tkinter import messagebox as msg
import tkcalendar
from tkcalendar import *
import conexion as cnx
import proveedores
from proveedores import Proveedores
from proveedores import *
import productos
from productos import Categoria_Productos
from productos import *
import clientes
from clientes import Clientes
from clientes import *
import colaboradores
from colaboradores import Colaboradores
from colaboradores import *
import herramientas
from herramientas import Roles
from herramientas import Usuarios
from herramientas import *
import recepciondoc
from recepciondoc import Recepcion
from recepciondoc import *
import ventas
from ventas import Ventas
from ventas import *
import ingresos
from ingresos import *
import movimientos
from movimientos import *
import excel_ingresos
from excel_ingresos import *
import excel_venta
from excel_venta import *
This is how my files are structured and how it works when I run the script from vscode
But when I tried to make an exe from my little project using PyInstaller, it looks incomplete like this:
this is how it looks like when I run the exe file from the "dist" folder
I worked like this
Create the spec file with pyi-makespec principal.py
Re-write the principal.spec to save the database path
pyinstaller --windowed principal.spec

ODI selective Reverse Engineering through groovy script

I try to use ODI-SDK with groovy scripting to automate selective reverse-engineering datastores to model. To do this, i used following script doStandardReverse() method, but getting error. I am trying to execute below script.
I have used API mentioned in below documentation
https://docs.oracle.com/middleware/12211/odi/reference-java-api/oracle/odi/core/service/reverse/ReverseService.html
import oracle.odi.domain.project.finder.IOdiProjectFinder
import oracle.odi.domain.model.finder.IOdiDataStoreFinder
import oracle.odi.domain.model.finder.IOdiModelFinder
import oracle.odi.domain.model.OdiModel
import oracle.odi.domain.model.OdiModelFolder
import oracle.odi.domain.model.OdiModel.ReverseObjectType
import oracle.odi.domain.project.finder.IOdiFolderFinder
import oracle.odi.domain.project.finder.IOdiUserProcedureFinder
import oracle.odi.domain.project.finder.IOdiKMFinder
import oracle.odi.domain.mapping.finder.IMappingFinder
import oracle.odi.domain.adapter.project.IKnowledgeModule.ProcessingType
import oracle.odi.domain.topology.finder.IOdiContextFinder
import oracle.odi.domain.topology.finder.IOdiLogicalSchemaFinder
import oracle.odi.domain.topology.finder.IOdiTechnologyFinder
import oracle.odi.domain.topology.OdiContext
import oracle.odi.domain.topology.OdiTechnology
import oracle.odi.domain.topology.OdiLogicalSchema
import oracle.odi.domain.model.OdiDataStore
import oracle.odi.domain.xrefs.expression.Expression
import oracle.odi.domain.xrefs.expression.Expression.SqlGroupType
import oracle.odi.domain.project.OdiProcedureLine.LogCounter
import oracle.odi.domain.project.OdiProcedureLineCmd
import oracle.odi.domain.project.OdiUserProcedure
import oracle.odi.domain.project.OdiUserProcedureLine
import oracle.odi.domain.project.OdiPackage
import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition
import oracle.odi.core.service.reverse.ReverseService
import oracle.odi.domain.project.StepModel.ReverseModel
txnDef = new DefaultTransactionDefinition()
tm = odiInstance.getTransactionManager()
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef)
def myList = ["SNP_CHECK_TAB","SRC_CITY"]
OdiModel srcModel = ((IOdiModelFinder)tme.getFinder(OdiModel.class)).findByCode("TEST_MOD");
//call reverse engeneering
rs = new ReverseService();
rm = rs.doStandardReverse(odiInstance, srcModel.getModelId(), ReverseService.DataStoreSelection.SELECTED, myList);
println('Data Store/s created.');
tm.commit(txnStatus)
I am getting error below
java.lang.String cannot be cast to oracle.odi.core.service.reverse.OdiDataStoreNameAndType
(Subtract 18 from the error line number to account for the standard imports)
java.lang.ClassCastException: java.lang.String cannot be cast to oracle.odi.core.service.reverse.OdiDataStoreNameAndType
at oracle.odi.core.service.reverse.ReverseService.convertDataStoreListToSnpsStringPair(ReverseService.java:452)
at oracle.odi.core.service.reverse.ReverseService.doStandardReverse(ReverseService.java:169)
at oracle.odi.core.service.reverse.ReverseService$doStandardReverse.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
at di.run(di.groovy:61)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:497)
at groovy.lang.GroovyShell.run(GroovyShell.java:170)
at oracle.di.studio.groovy.GroovyScriptRunInstance.run(GroovyScriptRunInstance.java:222)
Script exited.
Your list contains Strings where it should contain OdiDataStore objects.
findByName method of interface IOdiDataStoreFinder can be used to find a specific OdiDataStore object.

Resources