ModuleNotFoundError using items.py - python-3.x

Trying to implement an Item Loader.
my class name in items.py:
SiemensLinkcontentItem
my import statements inside my spider:
import scrapy
from scrapy.loader import ItemLoader
from siemens_linkcontent.siemens_linkcontent.items import SiemensLinkcontentItem
I get the following error:
No module named 'siemens_linkcontent.siemens_linkcontent'
My path diagramm is the following:

Use This One
- from siemens_linkcontent.items import SiemensLinkcontentItem

Related

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"

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.

module 'subprocess' has no attribute '_subprocess'

I used python3.7 in windows7.
When I tried to run this line: suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
error occurs: module 'subprocess' has no attribute '_subprocess'
import os
import sqlite3
import subprocess
import time
import re
from django.core.mail import send_mail
from django.http import HttpResponse
suinfo = subprocess.STARTUPINFO()
suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
How to deal with that?
There is no such thing as subprocess._subprocess, the constant is straight under subprocess:
suinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
See the docs: https://docs.python.org/3/library/subprocess.html#subprocess.STARTF_USESHOWWINDOW

Python module not accessible to function inside class

Code below works as expected. It prints 5 random numbers.
import numpy as np
class test_class():
def __init__(self):
self.rand_nums = self.create_rand_num()
def create_rand_num(self):
numbers = np.random.rand(5)
return numbers
myclass = test_class()
myclass.rand_nums
However, the following does not work. NameError: name 'np' is not defined
import numpy as np
from test.calc import create_rand_num
class test_class():
def __init__(self):
self.rand_nums = create_rand_num()
myclass = test_class()
myclass.rand_nums
# contents of calc.py in test folder:
def create_rand_num():
print(np.random.rand(5))
But, this works:
from test.calc import create_rand_num
class test_class():
def __init__(self):
self.rand_nums = create_rand_num()
myclass = test_class()
myclass.rand_nums
# contents of calc.py in test folder:
import numpy as np
def create_rand_num():
print(np.random.rand(5))
Why must I have 'import numpy as np' inside calc.py? I already have this import before my class definition. I am sure I am misunderstanding something here, but I was trying to follow the general rule to have all the import statements at the top of the main code.
What I find confusing is that when I say "from test.calc import create_rand_num," how does Python know whether "import numpy as np" is included at the top of calc.py or not? It must know somehow, because when I include it, the code works, but when I leave it out, the code does not work.
EDIT: After reading the response from #DeepSpace, I want to ask the following:
Suppose I have the following file.py module with contents listed as shown:
import numpy as np
import pandas as pd
import x as y
def myfunc():
pass
So, if I have another file, file1.py, and in it, I say from file.py import myfunc, do I get access to np, pd, and y? This is exactly what seems to be happening in my third example above.
In my third example, notice that np is NOT defined anywhere in the main file, it is only defined in calc.py file, and I am not importing * from calc.py, I am only importing create_rand_num. Why do I not get the same NameError error?
Python is not like C. Importing a module does not copy-paste its source. It simply adds a reference to it to the locals() "namespace". import numpy as np in one file does not make it magically available in all other files.
You have to import numpy as np in every file you want to use np.
Perhaps a worthwhile reading: https://docs.python.org/3.7/reference/simple_stmts.html#the-import-statement

Resources