I was getting some error and I don't know how to handle that error. I have created a script that is used to generate a barcode. Everything is working fine. But when I convert that script into exe. And try to use it then I am getting an error.
Error Image
Here is my code
import barcode
from barcode.writer import ImageWriter
EAN = barcode.get_barcode_class('code128')
with open('somefile.jpeg', 'wb') as f:
EAN("12347859450", writer=ImageWriter()).write(f)
Please help me out from this situation.
looks like your freeze method when creating the executable(cx_freeze?) is failing to include the needed dependency - in this case, looks like the FreeType library. I would investigate in that direction.
Related
I've read a couple other answers on this, but I'm still stuck. I imagine I'm doing something stupid, but this doesn't work:
import pytesseract
from PIL import Image
def tryTesseract(u):
return(pytesseract.image_to_string(Image.open(u)))
loc = 'C:\\Python\\Lineups\\558.png'
print(pytesseract)
print(tryTesseract(loc))
The first line prints:
<module 'pytesseract' from 'C:\Python\lib\site-packages\pytesseract\init.py'>
But the second prints several lines of error and culminates in:
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
This seems weird if the first line works. I BELIEVE I have correctly added it to path though, and it is correctly installed, as in this screenshot:
Full error message:
Edited for exciting new error. I followed user3250052's advice and am now getting a new error (CMD window on top of Python window here:)
from PIL import Image
def tryTesseract(u):
return(pytesseract.image_to_string(Image.open(u)))
loc = os.path.join('C','Python','Lineups','558.png')
pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR'
print(pytesseract)
print(tryTesseract(loc))```
That is a file not fond error.
Try
loc = os.path.join('C','Python','Lineups','558.png')
you might also need
pytesseract.tesseract_cmdloc = r'<full_path_to_your_tesseract_executable>'
I have created a binary file of an image using the code:
f1=open('file_name.png','rb')
f2=open('newfile.txt ','wb')
byte=f1.read()
f2.write(byte)
I have got the binary file but now I want to load that image using that binary code. Now, I want to load that image (or maybe recreate) that image by the source code itself in other file. how do I do that?
please note: I'm a newbie at python.
I have looked over the Various and found programs that I didn't understand.
this code was present there most of the time I searched. It made a bit sense to me.
I have tried the code with base64:
import base64
with open("t.png", "rb") as imageFile:
str = base64.b64encode(imageFile.read())
print (str)
but this is not doing anything. not showing errors, not printing the string either.
if there is a simple way please I request you to explain by the code.
Thanks in advance!
So my research mates and I are trying to save a pretty big (47104,5) array into a TTree in a ROOT file. The array on the Python side works fine. We can access everything and run normal commands, but when we run the root_numpy.array2root() command, we get a weird error.
Object of type 'NoneType' has no len()
The code we are running for this portion is as follows:
import root_numpy as rnp
import numpy as np
import scipy
import logging
def save_array(outputArray, outputName):
outputString =str(outputName)
logging.info("Creating .Root file")
rnp.array2root(outputArray,outputString,treename="Training_Variables",mode="recreate")
We placed the outputString variable as a way to make sure we were putting the filename in as a string. ( In our python terminal, we add .root at the end of outputName to save it as a .root file.).
Here is a picture of the terminal.
Showing exact error location in root_numpy
Pretty much, we are confused about why array2root() is calling for the len() of an object, which we dont think should have a len? It should just have a shape. Any insight would be greatly appreciated.
The conversion routines from NumPy arrays to ROOT datatypes work with structured arrays. See the two following links. (Not tested, but this is very likely the problem as the routines use the arr.dtypes.names and arr.dtypes.fields attributes).
http://rootpy.github.io/root_numpy/reference/generated/root_numpy.array2tree.html#root_numpy.array2tree
http://rootpy.github.io/root_numpy/reference/generated/root_numpy.array2root.html#root_numpy.array2root
I'm trying to open Image file from PyFileSystem MemoryFS using PIL, I tried to do that like this example and i got the error below:
from PIL import Image
from fs.memoryfs import MemoryFS
fs=MemoryFS()
fs.makedir("test")
out=fs.open("test/file.jpg",'wb')
out.write(someimagefile.read())
out.close()
in=fs.open("test/file.jpg",'rb')
im=Image.open(in) #error: cannot identify image file <IO wrapper for <MemoryFile in <MemoryFS> test/file.jpg>>
however if I don't use a directory (ex. out=fs.open("file.jpg",'wb')) It does work as expected.
What am I doing wrong?
Thanks for your help.
I already get an error using the following line:
from fs.memoryfs import MemoryFS
Probably I don't have that library installed. Do you need this library? You can just open the image without opening it with MemoryFS:
im = Image.open("test/file.jpg")
Side note: I wouldn't use in as variable name, since it is also a Python keyword.
I've been trying to throw together a python program that will align, crop and create an RGB image from HST and VLA .fits data. Unfortunately I've run into a bit of a problem with it continually opening a past file that does not exist in the folder and neither is it opening in the code itself. I've googled and googled and haven't found anything like it, so perhaps it's just common sense to most, but I can't figure it out. Here's the error message:
You can see at the top that the program I'm running has the filename rgbhstvla.py. I'm not sure what the error message means. Here's the python program as well:
import pyfits
import numpy as np
import pylab as py
import img_scale
from pyraf import iraf as ir
fits.open('3c68.fits', readonly)
j_img = pyfits.getdata('230UVIS.fits')
h_img = pyfits.getdata('230IR.fits')
k_img = pyfits.getdata('5GHZ.fits')
jmin,jmax = j_img.mean()+0.75*j_img.std(),j_img.mean()+5*j_img.std()
hmin,hmax = h_img.mean()+0.75*h_img.std(),h_img.mean()+5*h_img.std()
kmin,kmax = k_img.mean()+0.75*k_img.std(),k_img.mean()+5*k_img.std()
img = numpy.zeros((1024,1024,3))
img[:,:,0] = img_scale.asinh(j_img,scale_min=jmin,scale_max=jmax)
img[:,:,1] = img_scale.asinh(h_img,scale_min=hmin,scale_max=hmax)
img[:,:,2] = img_scale.asinh(k_img,scale_min=kmin,scale_max=kmax)
pylab.clf()
pylab.imshow(img)
pylab.show()
(I'm still working on the program since I'm new to python, tips here would be nice as well but they're mostly unnecessary as I'm sure I'll figure it out eventually).
Python cannot find the file 3c68.fits, which is expected to be in the current working directory, C:\Users\Brandon\Desktop\Research. Either make sure the file is in that directory, or provide an absolute path in your code.