Python executable cannot read file - python

Given below is the code that I am using to read values form a file
import linecache
line_number=line_number+1
linecache.getline("write.txt", line_number)
I am using py2exe to convert the file into an executable. The problem is after conversion to exe it cannot read the file.
The error message is:
Could not convert string to a float
As suggested in the comment the full error trace is:
Traceback (most recent call last):
File "logic.py", line 437, in <module>
File "logic.py", line 224, in readdata
ValueError: could not convert string to float:
Where am I going wrong?

Related

Trying to create XML file and got "TypeError: SubElement() got multiple values for argument 'tag'"

While the following code snippet of a python program generates a nice xml file:
from proc import create_SRXML
create_SRXML.create_xml()
This following does not generate the xml file (the line "import pumoni.visu.renders as visua" is spoiling the job)
from proc import create_SRXML
import pumoni.visu.renders as visua
create_SRXML.create_xml()
and getting error log as follows:
Traceback (most recent call last):
File "processor/analyze_all.py", line 26, in <module>
create_SRXML.create_xml()
File "/datas/repo/work/pul/process/create_SRXML.py", line 13, in
create_xml
b1 = pulvii.SubElement(m1, "element",len="4",
name="FileMetaInformationGroupLength", tag="0002,0000", vm="1",
vr="UL")
TypeError: SubElement() got multiple values for argument 'tag'
May I know what the problem here is?

Unexpected error with pdf2image while using a python loop

I'm using the pd2image module to convert a list of .ai files into .png files in a python loop. When I use the module in a loop it will successful convert the first .ai file into a .png file per page in the .ai file, but it seems to break on the second .ai file.
Here's the code
import os
from pdf2image import convert_from_path
directory = '/Users/jacobpatty/vscode_projects/badger_colors/test_ai_work_orders'
def ai_to_png(ai_file):
convert_from_path(
ai_file,
dpi=200,
output_folder='/Users/jacobpatty/vscode_projects/badger_colors/ai_to_ping_temp_storage',
fmt='png'
)
def end_loop(database):
for filename in os.scandir(database):
ai_to_png(filename)
print(filename)
end_loop(directory)
and here's the error
<DirEntry '8904_Heather_B_12-6-17.ai'>
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 479, in pdfinfo_from_path
raise ValueError
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jacobpatty/vscode_projects/badger_colors/TS_pdf2image.py", line 21, in <module>
end_loop(directory)
File "/Users/jacobpatty/vscode_projects/badger_colors/TS_pdf2image.py", line 17, in end_loop
ai_to_png(filename)
File "/Users/jacobpatty/vscode_projects/badger_colors/TS_pdf2image.py", line 7, in ai_to_png
convert_from_path(
File "/opt/homebrew/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 98, in convert_from_path
page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
File "/opt/homebrew/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 488, in pdfinfo_from_path
raise PDFPageCountError(
pdf2image.exceptions.PDFPageCountError: Unable to get page count.
Syntax Warning: May not be a PDF file (continuing anyway)
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't read xref table
I am very new to programming, but it seems odd to me that a line of code would work for one iteration but not the next. To fix it I tried using different ai files, but nothing changed and the same error occurred. I tried uninstalling and reinstalling pdf2image but that also didn't help.
Any ideas?

Transform docx to html raises python MemoryError

I have a function that converts a docx to html and a large docx file to be converted.
The problem is this function is part of a bigger program and the converted html is parsed afterwards so I cannot afford to use another converter without impacting the rest of the code (which is not wanted). Running on python 2.7.13 installed on 32-bit, but changing to 64-bit is also not desired.
This is the function:
import logging
from ooxml import serialize
def trasnformDocxtoHtml(inputFile, outputFile):
logging.basicConfig(filename='ooxml.log', level=logging.INFO)
dfile = ooxml.read_from_file(inputFile)
with open(outputFile,'w') as htmlFile:
htmlFile.write( serialize.serialize(dfile.document))
and here's the error:
>>> import library
>>> library.trasnformDocxtoHtml(r'large_file.docx', 'output.html')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "library.py", line 9, in trasnformDocxtoHtml
dfile = ooxml.read_from_file(inputFile)
File "C:\Python27\lib\site-packages\ooxml\__init__.py", line 52, in read_from_file
dfile.parse()
File "C:\Python27\lib\site-packages\ooxml\docxfile.py", line 46, in parse
self._doc = parse_from_file(self)
File "C:\Python27\lib\site-packages\ooxml\parse.py", line 655, in parse_from_file
document = parse_document(doc_content)
File "C:\Python27\lib\site-packages\ooxml\parse.py", line 463, in parse_document
document.elements.append(parse_table(document, elem))
File "C:\Python27\lib\site-packages\ooxml\parse.py", line 436, in parse_table
for p in tc.xpath('./w:p', namespaces=NAMESPACES):
File "src\lxml\etree.pyx", line 1583, in lxml.etree._Element.xpath
MemoryError
no mem for new parser
MemoryError
Could I somehow increase the buffer memory in python? Or fix the function without impacting the html output format?

Uncompyle2 issue: array indices must be integers

I have an issue when I am trying to decompile a .pyc file.
The traceback is the following:
Traceback (most recent call last):
File "my.py", line 4, in <module>
uncompyle2.uncompyle_file("/home/user/Downloads/asd.pyc", fileobj)
File "/home/user/Desktop/uncompyle2/uncompyle2/__init__.py", line 130, in uncompyle_file
uncompyle(version, co, outstream, showasm, showast, deob)
File "/home/user/Desktop/uncompyle2/uncompyle2/__init__.py", line 93, in uncompyle
tokens, customize = scanner.disassemble(co, deob=deob)
File "/home/user/Desktop/uncompyle2/uncompyle2/Scanner.py", line 214, in disassemble
cf = self.find_jump_targets(code)
File "/home/user/Desktop/uncompyle2/uncompyle2/Scanner.py", line 926, in find_jump_targets
self.detect_structure(i, op)
File "/home/user/Desktop/uncompyle2/uncompyle2/Scanner.py", line 737, in detect_structure
if int(self.code[jmp]) == RETURN_VALUE:
**TypeError: array indices must be integers**
Any ideas about this ?
I'm using Python 2.7.6 on a Ubuntu machine.
The command that I'm running to have this work is the following:
uncompyle2 asd.pyc
//EDIT: As far as I can tell, this happens only on a specific file(asd.py). It works on other files.
Any workaround ?
The .pyc file that you're trying to decompile is probably obfuscated. It's not uncompyle2s job to also deofuscate the file.
Try something else like pyc2py. Maybe it will work.

Cannot determine type of file

Hi i have just started learning image processing using python.
When i tried to open an image that i downloaded from the net, I keep getting this error and I have no idea about how to resolve it. Can anyone please help me with this?
>>> dna=mahotas.imread('dna.jpeg')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 773, in imread
img = read(filename)
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 444, in read
bitmap = _read_bitmap(filename, flags)
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 490, in _read_bitmap
'mahotas.freeimage: cannot determine type of file %s' % filename)
ValueError: mahotas.freeimage: cannot determine type of file dna.jpeg
Hello this looks like a pretty old thread but I found it recently because I had the same problem.
I think that the error message is misleading because it implies that the type of file is incorrect.
I fixed the problem by including the full path to the image file. For example, it could look something like:
dna = mahotas.imread('C:\Documents\dna.jpeg')

Categories