Applying patch to subprocess library - python

I am trying to apply patch to subprocess library. Using following script and get the error:
TypeError: unsupported operand type(s) for -: 'module' and 'module'
os.chdir("C:/Users/Downloads")
import patch
patch -subprocess < issue_28168_03.patch
I downloaded the patch from https://bugs.python.org/issue28168
Need help with the error.

I was actually trying to apply the patch to fix issues with Uninterruptible subprocess when opening an exe file. I fixed it using following script.
import subprocess
import time
binary_path = 'path/file.exe'
args = 'arguments' # arbitrary
call_str = '{} {}'.format(binary_path, args)
proc = subprocess.Popen(call_str)

Related

'str' object has no attribute 'exec_module'

I'm trying to import script code in a test.py file as a module using importlib in google colab.
Here's my code:
def load_module(file_name, module_name):
spec = importlib.util.spec_from_loader(module_name, file_name)
module = importlib.util.module_from_spec(spec)
print(spec.loader)
spec.loader.exec_module(module)
sys.modules[module_name] = module
return module
def get_file(path):
SCRIPT_FILE = open(path,'r')
return SCRIPT_FILE
I run above function for getting for getting lib from test.py
file =get_file('/content/gdrive/MyDrive/test/test.py')
module = load_module("from lib import *\n" + file.read(),'crawl')
And I got this error
AttributeError: 'str' object has no attribute 'exec_module'
Please help! Thanks
In line 2, you are passing in type string instead of type Loader for the second function argument. If you look at the documentation, it looks like the loader is not being generated based on your path:
spec = importlib.util.spec_from_loader(module_name, file_name)
Here is a sample implementation of using spec_from_loader, by generating a loader with ExtensionFileFinder.
However, for your use case, can you try using spec_from_file_location? This way, you can see if it can generate your spec based on the file path you passed in. Try passing the path into the location argument.

python 'AttributeError' with can.BLFReader

I am trying to import blf file using can.BLFReader module.
buf python shows 'AttributeError'.
this is the code.
import can
filename = "test.blf"
can_log = can.BLFReader(filename)
for msg in logging:
print(msg)
AttributeError: module 'can' has no attribute 'BLFReader'
and the file name is not 'can'
what is the reason?
It seems to be a problem with python3 version if you run as you can see in the attached image with python it will work

PythonShellError: TypeError: 'NoneType' object is not subscriptable in electron

I try to do ocr on an image. When I execute this in python shell , it's work fine.but When it is from electron with node module python-shell I go this message.
PythonShellError: TypeError: 'NoneType' object is not subscriptable
at PythonShell.parseError
' result = "-"+pytesseract.image_to_string(Unsplashinput_img[w:x,y:z]
sources python
import cv2
import math
from scipy import ndimage
import pytesseract
import sys
w=361
x=388
y=433
z=921
w1=17
x1=61
y2=316
z2=544
IMAGE_FILE_LOCATION = '/test1.png' #param1 file_name
Unsplashinput_img = cv2.imread(IMAGE_FILE_LOCATION)
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
result = "-"+pytesseract.image_to_string(Unsplashinput_img[w:x,y:z] )
result +="-"+pytesseract.image_to_string(Unsplashinput_img[w1:x1,y2:z2])
print(result)
sys.stdout.flush()
You file is not found, so your Unsplashinput_img is None.
The error tells you that you cannot index it (with [w:x,y:z] for example) since it is not an array.
You maybe missed a dot in '/test1.png' -> './test1.png'

AttributeError: 'module' object has no attribute 'vtkvmtkVesselEnhancingDiffusion3DImageFilter'

I get the following error when I try to run the script for the VEDm filter in vmtk:
[location] line 149, in ApplyVEDManniesing
vesselness = vtkvmtk.vtkvmtkVesselEnhancingDiffusion3DImageFilter()
AttributeError: 'module' object has no attribute 'vtkvmtkVesselEnhancingDiffusion3DImageFilter'
I tried to run the code in my Python 3.6 environment, instead of 2.7 where I currently work in. But it gave the same error.
The other filters (Sato, Frangi, VED) were completed successfully and are represented in the same python-file vmtkimagevesselenhancement.py.
Can someone help me to find the problem?
Edit: this is what the beginning of the code looks like:
from __future__ import absolute_import #NEEDS TO STAY AS TOP LEVEL MODULE FOR Py2-3 COMPATIBILITY
import vtk
import sys
import pypes
import vtkvmtk
The filename where the line 149 doesn't work is vmtkimagevesselenhancement.py and is imported with the vmtk download.

Python code has an error: 'module' object is not callable

I try to coonect to API of Autodesk Inventor with Python. I can create a new file but then an error aooears here:
import os
import win32com.client
from win32com.client import constants
from win32com.client import gencache
os.system(r'C://Programm Files/Autodesk/Inventor 2014/Bin/Inventor.exe')
invApp = win32com.client.Dispatch("Inventor.Application")
invApp.Visible = True
mod = gencache.EnsureModule('{D98A091D-3A0F-4C3E-B36E-61F62068D488}', 0, 1, 0)
**invApp = mod.Application(invApp)**
oAssemblyDoc=invApp.Documents.Add(constants.kAssemblyDocumentObject, "", True)
asd = invApp.Documents.Add(constants.kPartDocumentObject,"",True)
qwe=invApp.Documents.Item(asd)
oAss = oAssemblyDoc.Activate
There ir an error in the selected line:
TypeError: 'module' object is not callable
I am a novice in Python and I can't understand what is the error. Can anybody help me?
I see that the win32com gencache early binding produces some subfolders. This seems to work with:
invApp = mod.Application.Application(invApp)
I found that makepy.py had to be run with -i command option first time, then re-run to capture the full structure.

Categories