AttributeError: module 'utils' has no attribute 'get_audio_path' - python

I am engaging a project now, and the library utils might be frequently used. However, I just cannot normally invoke functions from utils. See code below.
import IPython.display as ipd
import librosa
import librosa.display
import utils
filename = utils.get_audio_path(AUDIO_DIR, 2)#AUDIO_DIR is an audio path
print('File: {}'.format(filename))
x, sr = librosa.load(filename, sr=None, mono=True)
print('Duration: {:.2f}s, {} samples'.format(x.shape[-1] / sr, x.size))
start, end = 7, 17
ipd.Audio(data=x[start*sr:end*sr], rate=sr)
Plus, I had installed library python_utils either, but didn't work.

Related

ImageJ Python Scripting

So I want to make an ImageJ script in Pycharm using Python but I am unable to import the IJ module can anyone help me with the steps I need to take to be able to make a script in Pycharm using
so far I have made the script
from ij import IJ
from ij.io import FileSaver
from ij.io import OpenDialog
from ij.plugin import ImageCalculator
import os
IJ.run("Clear Results");
od = OpenDialog("Choose a File", None)
filename = od.getFileName()
directory = od.getDirectory()
path = od.getPath()
imp = IJ.openImage(path)
IJ.run(imp, "32-bit", "")
IJ.run(imp, "Despeckle", "")
IJ.run(imp, "Unsharp Mask...", "radius=2 mask=0.65")
imp.setRoi(486,588,342,1116)
IJ.run(imp, "Enhance Contrast", "saturated=0.35")
imp.setRoi(0,1,1179,1712)
IJ.run(imp, "ROF Denoise", "theta=6")
imp2 = IJ.run(imp, "Duplicate...","title=imp2")
IJ.run(imp2, "Invert LUT", "")
IJ.run(imp2, "Gaussian Blur...", "sigma=1")
ic = ImageCalculator()
imp3 = ic.run("Add", imp, imp2)
IJ.saveAs(imp3, "jpg", directory)
Currently, I have tried to go into the settings of pycharm and tried to download the imageJ package and tried using with import imagej ij = imagej.init()
But I get an error which is
import imagej
File "C:\Users\jorda\PycharmProjects\pythonProject\venv\lib\site-packages\imagej\__init__.py", line 1, in <module>
from .imagej import *
File "C:\Users\jorda\PycharmProjects\pythonProject\venv\lib\site-packages\imagej\imagej.py", line 10, in <module>
import jnius_config
ModuleNotFoundError: No module named 'jnius_config'```

package import is not importing its dependencies

I just wrote a small package containing a class to use on jupyter labs at work, however when I try to import and use the class which is dependent on numpy and matplotlib, it says that np is not defined.
Even though it is imported into the file I am importing the class into, and I imported it into the class file itself that I am importing, and the __init__.py file for the package. I just need the class to load some data into a np.array([]) via np.genfromtxt().
I have made one package before and didn't have any issues but I'm new so am obviously missing something.
Here's how I get the error:
pip install git+https://github.com/Elliot-Wadge/pl_class#egg=pl_class
import numpy as np
import matplotlib.pyplot as plt
import glob
from pl_data import pl_data as pl
PL_data = pl.PL_data
flist = glob.glob("data/*")
dictionary = PL_data(flist, skip_header = 4, unpack = True, delimiter = '\t')
error message
class file

ERROR PYTHON: name 'cairosvg' is not defined

I alredy have a problem.
Show cairosvg as undefined. I wish save Turtle object as png.
I already installed the canvasvg and cairosvg libraries, but even so I keep getting the error. I leave my code as a sample. Thank you
from turtle import *
import os
import shutil
import tempfile
import canvasvg
from canvasvg import *
screen=Screen()
setup (640,520,0,0)
title("T")
tracer(0,0)
encendido='#51D1F6'
apagado='#922B3E'
pant=Turtle(visible=False)
pant.hideturtle()
pant.pensize(4)
pant.penup()
pant.goto(110,0)
pant.pendown()
pant.pendown()
pant.fillcolor(encendido)
pant.begin_fill()
pant.goto(-400,-180)
pant.goto(-400,-190)
pant.goto(-110,-190)
pant.end_fill()
Y=7
gb=Y*4
agua=Turtle(visible=False)
agua.pensize(4)
agua.penup()
agua.goto(110,-200)
agua.pendown()
agua.fillcolor(encendido)
agua.begin_fill()
agua.goto(110,-200+gb)
agua.penup()
agua.goto(-110,-200+gb)
agua.pendown()
agua.goto(-110,-200)
agua.goto(110,-200)
agua.end_fill()
update()
ts=getscreen().getcanvas()
tmpdir=tempfile.mkdtemp()
tmpfile=os.path.join(tmpdir,'tmp.svg')
canvasvg.saveall(tmpfile,ts)
name="image4.png"
with open(tmpfile) as svg_input, open(name, 'wb')as png_output:
cairosvg.svg2png(bytestring=svg_input.read(),write_to=png_output)
shutil.rmtree(tmpdir)

Cannot import class from module (circular reference issue?)

I've seen countless issues here on stack about this but still can't figure out why I cant get mine to work. I have a 2 .ipynb files and I'm looking to import a class from one file to the other as follows:
CV_Screening_Interface:
from joblib import dump, load
import sys
import pandas as pd
import os
import import_ipynb
import docx
import readDocx ***(This is another ipynb file)***
from docx import Document
import string
model = load('model.joblib')
class CV:
def __init__(self,university,major,masters,company,certification,GPA):
self.university = university
self.major = major
self.masters = masters
self.company = company
self.certification = certification
self.GPA = GPA
#And a bunch of other functions
Now in FirstProgram
from tkinter import *
from tkinter import filedialog
from docx import Document
import io
import import_ipynb
import CV_Screening_Interface
#Till here works fine
When I try to import class CV I get an import error
from CV_Screening_Interface import CV
OR
test = CV_Screening_Interface.CV()
ImportError: cannot import name 'CV' from 'CV_Screening_Interface' (CV_Screening_Interface.ipynb)
I checked PYTHONPATH, I have an empty init.py in the directory already. What's weird is that importing the module works, but importing the class in the module doesn't.
Note in CV_Screening_Interface CV class works perfectly fine so I don't think there is any issue with it specifically. Probably need a if name="main" inside it?
Ok so this solved my problems:
I created a new ipynb called ClassFile.ipynb and it only contains the Class CV without importing any packages
Then i converted ClassFile.ipynb to ClassFile.py and imported it to FirstProgram and it worked.

how to call a module in a function in pp where that fuction has other functions in it?

I'm currently using parallel python ,and in the parameters of job_server.submit i added the library in modules but the problem is that even that library has other librairies in it .so what should i do ?
Here is the code i'm trying to run:
from tools.demo import detect_cn
import pp
job_server = pp.Server()
f1 = job_server.submit(detect_cn, (filename,),modules=('tools.demo',))
f2 = job_server.submit(detect_cn, (filename1,),modules=('tools.demo',))
cnis, preproc_time, roi_file_images=f1()
cnis1, preproc_time1, roi_file_images1=f2()
and this is part of code of demo.py
import _init_paths
from fast_rcnn.config import cfg
from fast_rcnn.test import im_detect
from fast_rcnn.nms_wrapper import nms
from utils.timer import Timer
from ocr.clstm import clstm_ocr
from ocr.clstm import clstm_ocr_calib
import matplotlib.pyplot as plt
import numpy as np
import scipy.io as sio
import caffe, os, sys, cv2
import argparse
import werkzeug
import datetime
import math
import pytesseract
from PIL import Image
def detect_cn(filename):
cfg.TEST.HAS_RPN = True # Use RPN for proposals
args = parse_args()
prototxt = os.path.join(cfg.MODELS_DIR, NETS[args.demo_net][0],
'faster_rcnn_alt_opt', 'faster_rcnn_test.pt')
caffemodel = os.path.join(cfg.DATA_DIR, 'faster_rcnn_models',
NETS[args.demo_net][1])
if not os.path.isfile(caffemodel):
raise IOError(('{:s} not found.\nDid you run ./data/script/'
'fetch_faster_rcnn_models.sh?').format(caffemodel))
if args.cpu_mode:
caffe.set_mode_cpu()
else:
caffe.set_mode_gpu()
caffe.set_device(args.gpu_id)
cfg.GPU_ID = args.gpu_id
net = caffe.Net(prototxt, caffemodel, caffe.TEST)
print '\n\nLoaded network {:s}'.format(caffemodel)
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
print 'Demo for CN image...'
return demo2(net, filename)
Do you think i should load all those librairies in modules of job server.submit?
I want to use the pp bacause detect_cn takes 2 minutes to give results
any ideas?
Yes, you should import all these modules when wou submit your function into the execution queue.
f1 = job_server.submit(detect_cn, (filename,),modules=("math","numpy", ...))

Categories