how to import module in emr notebook - python

I want to import module in another direcotory.
But when i import it, this error occurs.
how can i import file in another directory in emr notebook?
I tried below code.
import utils.mysql_util
Traceback (most recent call last):
ModuleNotFoundError: No module named 'utils'
the file that i execute location is batch_pipeline/logdata.
module that i want to import is in batch_pipeline/utils.

Related

How can I import functions from other folders in Python project?

I cannot import the functions from other packages in my Python project.
As suggested, I added
sys.path.append(os.path.abspath('../ExportExcel'))
from ExportExcel.export_excel import export_excel
at the beginning of the clip_finder.py.
I also put
sys.path.append(os.path.dirname(__file__)
inside the export_excel.py.
Inside ExportExcel.init.py I put
from .export_excel import export_excel
However I still get this error:
C:\Main\SupportScripts\ClipFinder>python clip_finder.py -h
Traceback (most recent call last):
File "C:\Main\SupportScripts\ClipFinder\clip_finder.py", line 12, in <module>
from ExportExcel.export_excel import export_excel
ModuleNotFoundError: No module named 'ExportExcel'
How can I make it work?

Can't find a module saved in another subdirectory

I have a Python file that I'm trying to import into a session. The file structure looks like the following
-object_detection
--__init__.py
--export_inference_graphy.py
--protos
---__init__.py
---pipeline_pb2.py
From the export_inference_graph file, I'm trying to import pipeline_pb2.
However, I get the following error.
from object_detection.protos import pipeline_pb2
Traceback (most recent call last):
File "<ipython-input-60-76f12fdd6acf>", line 1, in <module>
from object_detection.protos import pipeline_pb2
ModuleNotFoundError: No module named 'object_detection.protos'; 'object_detection' is not a package
I've also tried the following and each has resulted in the same error.
import sys
sys.path.append('/protos')
import pipeline_pb2
from ..protos import pipeline_pb2

Import Error:No module named app.management.commands

when I run the command to import my python file, i am getting import error saying no modue named app.management.commands.
>>> from app.management.commands import scripty
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named app.management.commands
Can anyone please help me.
Is app.management.commands in your sys path?
Looks like you have to import it using <project_name>.app.management.commands.

How to add python library to Spyder

I am trying to add an external python library from a third party software into Spyder so I can work with it. I have already tried the following:
Adding library path containing .py files to Tools>PYTHONPATH manager
Synchronizing the path
Updating module names list through Tools>Update Module names list
However, when I try to import modules from this library I get two types of errors:
import easy
Traceback (most recent call last):
File "<ipython-input-2-685519d35f15>", line 1, in <module>
import easy
File "C:\Program Files (x86)\Plaxis\PLAXIS 2D\plxscripting\easy.py", line 24, in <module>
from .server import Server, InputProcessor
ValueError: Attempted relative import in non-package
The second type of error as follows:
from plxscripting.easy import *
Traceback (most recent call last):
File "<ipython-input-1-a40c101d3bb0>", line 1, in <module>
from plxscripting.easy import *
ImportError: No module named plxscripting.easy
I don't understand why Spyder is not recognizing these libraries. The path has been added and shows up on the manager. What constitutes a python module? Is it not just the .py file with module name prefix? Is not the path sufficient to work with the library through the IDE?

ModuleNotFoundError in Using 3rd party module in external .py file

I installed third party module and its egg file was created in following path
D:\Utkarsh\Lib\site-packages
I am not getting error while importing module in IDLE in following way
import snakebite
When i am importing the same in HDFS.py file having following lines
import snakebite
from snakebite.client import Client
client = Client('localhost', 9000)
it causes following stack error:
============ RESTART: D:/Utkarsh/Python Projects/HDFS.py ============
Traceback (most recent call last):
File "D:/Utkarsh/Python Projects/HDFS.py", line 1, in <module>
import snakebite
ModuleNotFoundError: No module named 'snakebite'
sys.path had following values:
D:/Utkarsh/Python Projects
D:\Utkarsh\Installation\Lib\idlelib
D:\Utkarsh\Installation\python36.zip
D:\Utkarsh\Installation\DLLs
D:\Utkarsh\Installation\lib
D:\Utkarsh\Installation
D:\Utkarsh\Installation\lib\site-packages
Being newbie,can anybody help me in knowing exact cause of it.

Categories