def setPixData(self,data):
print(data) #this print the image file name correctly e.g asdfghj.jpg
img=QtGui.QImage(QtCore.QCoreApplication.applicationDirPath ()+"/temp/"+data)
pix=QtGui.QPixmap.fromImage(img)
self.driver_ui.pix.setPixmap(pix)
This loads the image correctly when I run it from the development code.
Once I freeze it with cx_freeze and install it in final destination directory, it does not load the image. Even though the image is in the specified path.
I have tried hardcoding the full path into the frozen version, still no luck.
I've placed a f.write() at every other line of the above code, and they all ran with no error.
I figured the problem is from QImage since it returns true on isNull()
What could be the problem, If QImage is not being added by cx_freeze, it will sure throw and exception and wont run the f.write() on next line.
I am lost here.
NOTE: it's a windows GUI app in python.
You are likely giving it an incorrect file path. The fact that the file exists somewhere doesn't help QImage, if you don't give it a correct file path.
Related
When I run a .py file, it just opens and closes immediately. It doesn't give any output. I turned it into an .exe file but still the same result. I ran it from cmd, the result is the same. I checked the program that runs the code and found it to be Python.
HERE IS THE CODE.
from tkinter import *
app = Tk()
app.geometry("250x250")
app.title("Tkinter!")
mainloop()
I suggest you to kindly share the code(as there may be some codes that does not have an output. For example, if the code simply involves assigning values to a variable(say x=2+4) will not result in printing an output, unless specifically mentioned otherwise(print(x)). Also, ensure that you add the Python's installed location to PATH(Environment Variables). I am assuming that you are using Windows OS(as you mentioned cmd).
For some reason, my python program will not open my file in a directory called imgs in which I have a png file that I wish it to display when it runs.
The imgs directory is in the same location as my python program on my C drive. I have made sure that I am entering the correct names and that there is no / before imgs
It always pops up with the message
pygame.error: Couldn't open imgs/tileGrass1
tileGrass1 being the png
Any suggestions on how to fix this??
Few checks to ensure a pygame program is running well
Ensure You Initialize the pygame library at the beginning of your code
pygame.init()
Ensure Path to your image is correct and that the image exists. Check that the extension is correct (png, jpg, jpeg, etc)
It would also be useful if you share the code to your program so that the exact error is easily noted
I have written code in a New file window in IDLE.
When I run the code there is no output.
Instead a dialog box appears showing a window accessing Python Folder 37-32.
When i closed the dialog box and the file I tried to create a new simple code below but I when I ran the code I got the same Dialog box.
What is wrong?
sum = 2+3 print(sum)
I have attached a screenshot showing the code and the dialog box that appears when the Module is run
Before you can execute your code, your first need to save the file. Thats the dialog box that popped up.
You should have seen a popup box like below. Did you? Is is unclear?
Save Before Run or Check
? Source Must Be Saved
OK to Save?
[OK] [Cancel]
One reason to require saving is that exception tracebacks refer to the file and line of lines that lead to the exception.
If you had saved, sum = 2+3 print(sum) would be a SyntaxError.
You can run single statements in Shell without saving.
The RESTART lines says that the shell re-initialized the environment for executing your code.
You should normally not save your code buried in the installation Scripts directory. Better to make a directory in your user directory, for instance, C:/Users/yourname/py/.
Yes, one should usually open a new question for unrelated questions. But without access to your machine, it is hard to know what happened with 'new'. It may be that IDLE could create a file under .../appdate/.../Scripts/, but your code cannot. If the open call did not raise and exception, it was likely created somewhere. Until you are more experienced, better to use absolute paths, such as C:/Users/yourname/py/new.txt.
I am saving matplotlib figures savefig(filename) from my python script using an absolute path, which is very long.
I had problems with max path length limitation on windows Errno2 no such file or directory, so I started appending \\?\ to the beginning of the path and it seemed to work.
However, some of my saved figures seem to be corrupted, as I try to open them with windows default image viewer and it just closes without showing the image. Some other figures saved by the exactly same procedure worked fine though.
I have noticed that the figures that do not open have the \\?\ appended to the location property in the windows explorer file property dialog:
The ones working does not have it:
EDIT:
I found new information: When the whole absolute path + filename has 260 characters or more (without the \\?\ in the beginning), then I get this corrupted behavior and can't open my file.
EDIT 2:
I tried creating a text file (with open(filename,'wb') instead of saving a matplotlib figure. I get the same \\?\ in the location propert and when I try to open it this is what I get:
So basically the \\?\ allows me to create a figure or textfile, but I cannot open it anyway.
EDIT 3 - well it turns out the files are not corrupted, as I can move them to a folder closer to root and they can be opened with no problems.
Any ideas how to solve this?
I'm new to the turtle module and I'm having a problem while setting a background pic for my turtle project.
when running this code:
import turtle as tr
import os
os.chdir(pathname)
tr.setup(400,400)
tr.bgpic("diamond.gif")
I get an error message for the 5th line ending with:
_tkinter.TclError: image "pyimage4" doesn't exist
Sometimes it's pyimage2 doesn't exist or pyimage36. At each execution it changes.
I didn't find a real solution in other posts. Any help will be much appreciated.
You're not showing us your actual minimal code that fails as your example doesn't get past this line:
os.chdir(pathname)
since pathname isn't defined. I downloaded this GIF, renamed it diamond.gif, and ran the following subset of your code:
import turtle as tr
tr.setup(400, 400)
tr.bgpic("diamond.gif")
tr.done()
This displays the GIF in a window:
If you repeat what I did, and it works, then this may be a problem with your GIF file. (Download the GIF from this link, don't use my PNG illustration above.) If you repeat what I did and it doesn't work, then it may be a problem with your environment. This error message:
_tkinter.TclError: image "pyimage4" doesn't exist
is often associated with independently initializing both the turtle and the tkinter modules. If you aren't doing such, perhaps you're running in a specially tweaked environment that is. There may be a workaround, but you first need to determine what's really happening.