why does ffmpeg_extract_subclip error only happen in python exe - python

This piece of code works fine when run on the Spyder IDE, but crashes when I convert it to exe with auto-py-to-exe. I know it might be because I didn't explicetly include ffmpeg in my pytoexe config and so another user of my program that doesn't have ffmpeg installed might run intro problems, but it doesn't even work for me. When I comment out the try/except block, tt crashes and my way of debugging it has been with Windows events viewer, which doesn't give much details except this code 0xC0000409 (which I got some other time because I accessed indexes on an array that were not there) so I made the script print into a file, giving this error: 'NoneType' object has no attribute 'write'
try:
ffmpeg_extract_subclip(required_video_file, clipStart , clipEnd)
except Exception as e:
with open('DEBUGGING.txt', 'a+') as f:
f.writelines('\n EXCEPCION:\n'+str(e))
f.close()
Doesn't make sense because ffmpeg_extract_subclip doesn't even have a write method, and the error is only caused by this lines, cause all the other ones are printed fine into my txt file. As I said, the clips are made successfully when I do it through my IDE, but stops working for some reason when I run the exe.
Edit: placing ffmpeg and ffprobe in the folder didn't solve it. Python version: 3.11

I think I solved the problem, and the answer is related to this other post in stack overflow ffmpeg_extract_subclip function and moviepy string output error. The weird error that I got ('NoneType' object has no attribute 'write') was caused by ffmpeg, moviepy or any other library that writes to the console, and, as my app is windows based, it couldn't output the download procress so it crashed. I figured it out while using moviepy and cx freeze, as this method of converting py to exe also creates a console window and thus the text is shown there and it doesn't crash. I don't mind this console I guess but if you want the solution, it's mentioned in the previous question, either use ffmpeg directly, which didn't work for me, or redirect stdout momentarily, which I think it's the best solution but haven't tried it yet.
Edit: the solution that ultimately worked is this one Moviepy still prints a progress bar even after setting `verbose` to `False`, which is adding this parameters (verbose=False, logger=None) to the method write_videofile, and yes, it is using moviepy. I suspect you can do it using my original code, ffmpeg might have some similar settings, but I switched over to this one which brings the same functionality.

Related

Python in vscode terminal - executes program when file not saved, but throws syntaxError: invalid syntax when saved, pointing to /bin/python3

Installed extensions on vscodium:
autoDocstring, Python, isort, and several Jupyer extensions.
OS: Ubuntu 20
Process: Open VsCodium (not via ctrl+t, but via clicking), create a python file, write a program, run it - get weird terminal behavior, save it - get even more weird terminal behavior (as shown below).
The terminal works very weirdly overall. I don't understand how it's handling the execution steps, and when/if it's even asking me for input. Maybe I've got some wrong extensions installed?
On the pic, how u be, Jowey is before saving the file to documents. The /bin/python3 is after saving to documents.
enter image description here
Tried making new files, running without saving. Both described above.

Python script closes without even running

I wrote a python script to run some simple tasks and this issue has been happening randomly at times.
Upon clicking on .py file, a cmd prompt window appears for a some microseconds and closes immediately without showing any text.
I thought this issue was because the code finished running too fast at first but the code doesnt actually run. I know this because the code involves sending a text message on discord through the requests module and I can see post-running that no text has been sent.
If it was the prior assumed issue, I would've just added some input for the program to recieve but my program has an infinite while loop in it which should be already enough to keep the cmd window open. Hence I dont understand what's causing this.
The last time it happened I somehow found a solution which I followed step by step and was able to resolve it but its happening again now and I cant find that solution again unfortunately. From vague memory, I recall the solution involved running some commands on windows terminal.
Are you double clicking the .py file? If so, it may not work in some situations. What you should do is open up your cmd and type the following.
C:\Users\Admin> python filename.py
You can replace filename with your file's name.
If you are using Mac or any Apple devices, you will need to replace python with python3.

os.listdir() returns nothing, not even an empty list

During a presentation yesterday I had a colleague run one of my scripts on a fresh installation of Python 3.8.1. It was able to create and write to a csv file in his folder (proof that the csv library was working correctly), but everything else failed due to not being able to find the needed files. To try and isolate the problem and figure out why, we tried the below simple script, which also failed.
He had this test.py script in "D:/TEST", which also contained some folders and image files. Running this script printed nothing to the console. No empty list, no error message, no newline. Maybe the print() function was also not working, but I didn't get around to testing that.
import os
print(os.listdir())
This script works fine on my computer and my other colleagues computers (all Windows 10, similar hardware). I didn't have time to look into the issue more thoroughly and don't have access to his computer anymore. What could be the problem? What other things could I have him look into in order to fix this? In case this problem appears again during a future presentation, what steps could I take to figure out the cause of it?
My colleague uninstalled Python and reinstalled it. After doing this apparently the "python" command will no longer run his scripts, but using "py" instead will. Now that he is using "py" to run his scripts, it is working as expected.

Python code runs fine from command line, but won't work from IDLE

I've found a lot of people having the reverse issue, but haven't yet found a question that involves IDLE not being able to run something that runs fine from the command line. I'm using a new module that I haven't used before that uses one .pyd file and one .dll, and involves a device that connects through USB. I sadly can't post in-depth code snippets since this is copyrighted code, but if anyone knows where to start on a problem like this I would be very grateful.
IDLE swaps out the sys.stdout and sys.stderr objects at the Python level this causes issues with some pyd modules. Try using another debugger.

Issues with pyinstaller

I have created a working GUI program (using tkinter), but when I try to compile it using pyinstaller (py2exe only works for python 2.6 and I used 2.7 for the program), it doesn't work. I have 2 files: program.py, and data.xml. The program uses the xml document to retrieve information and display it to the window. I have looked all over, but no one seems to have had a similar problem, and the pyinstaller documentation is useless. the command I used was
python pyinstaller.py -w -mdata.xml -nProgram program.py
It appears to make the spec file fine, but generates an error with a large traceback upon build:
pyinstaller.utils.winmanifest.invalidManifestError: Invalid root element <items> - has to be one of <assembly>, <assemblyBinding>, <configuration>, <dependentAssembly>
and quits the build process. This is the first time I have tried to build an executable for a project, so I'm kind of shooting in the dark here. Did I forget to do something, or did I just find a bug in pyinstaller's program?
Normally I wouldn't answer my own question, but I have solved the issue and I think others should know about this. When creating your program and using an xml with it, you must have the root tag (the first one) as <assembly>. Not sure why, but it works when I do that. also, don't forget to use the --hidden-import=Module command if you imported anything into your program.

Categories

Resources