So I tried to convert a file named video.ts into video.mp4 in Python and am getting the error:
FileNotFoundError: [WinError 2] The system cannot find the file specified
Assuming video.ts is already loaded into the program and subprocess already imported.
This is due to the line:
>>> subprocess.run(['ffmpeg', '-i', 'video.ts', 'video.mp4']) but I don't know what's the problem.
I've opened the video.ts file and it seem to be working fine. Python version (3.8.2)
To anyone having this problem, download ffmpeg (will usually be in a zip), extract, go inside bin directory, and copy path (eg. location of folder\ffmpeg\bin). Then type in environment variables in start menu, add this path to the variable named PATH and save. DONE!
If there's still issues, restart your program, or further, your device
Related
I am attempting to use the package WhiteboxTools. I have installed it to my python environment and imported it to my Jupyter notebook script. The whitebox documentation suggests explicitly setting the path to the executable file if it is not in the same folder as the script being written with the following:
wbt.set_whitebox_dir('/local/path/to/whitebox/binary/')
Another reason I believe this to be the problem is that I set the path to this file in my first code chunk: wbt.set_whitebox_dir('C:\\Users\\maxduso.stu\\Anaconda3\\envs\\geo\\pkgs\\whitebox_tools-2.2.0-py39hf21820d_2\\Library\\bin\\whitebox_tools.exe'), but the error arises in the next code chunk which calls one of the tools:
wbt.breach_depressions_least_cost(
"C:\\Users\\maxduso.stu\\Desktop\\FCOR_599\\project_work\\data\\tif_folder\\full_pa.tif",
"C:\\Users\\maxduso.stu\\Desktop\\FCOR_599\\project_work\\data\\tif_folder\\sa_breached_dem.tif",
dist = 10, #maximum search distancefor breach paths in cells
max_cost=None,
min_dist=True,
flat_increment=None,
fill=True
)
[WinError 267] The directory name is invalid: 'C:\\Users\\maxduso.stu\\Anaconda3\\envs\\geo\\pkgs\\whitebox_tools-2.2.0-py39hf21820d_2\\Library\\bin\\whitebox_tools.exe'
whitebox_tools is one of two files I attempted, the other being whitebox_gui. These files were suggested to me when I searched for ".exe" in the whitebox tools folder within my environment folder. That said, they are type = Application and so that brings me to the question: why did windows autofill "whitebox_tools.exe" in the file search bar but find an application file? Also, considering I cannot find a file of type .exe, where do I go from here?
Note: the tools also don't run without the path set.
Thanks for reading. I hope the question was clear enough.
I am trying to run python on Ubuntu. ADDED: It's a double boot system with Windows.
If I type python on the shell, it opens python. But I want to run a python file.
I have my python (.py) file saved on windows Desktop.
On Windows when I run a .py file in my command prompt, I just have to change directory to Desktop then type python myfile.py and the code runs successfully.
When I try to do that same thing in Ubuntu, it does not work. I made a Desktop directory in Ubuntu using the mkdir function.
Now, when I type python myfile.py, I get the error:
python: can't open file 'myfile.py': [Errno 2] No such file or
directory
I tried typing python on the Ubuntu shell then dragging the myfile.py file (~$ python C:\Users\username\Desktop\myfile.py), it used to run and then close the answer right away, but now I would get the error
python: can't open file 'C:UsersusernameDesktopmyfile.py': [Errno 2]
No such file or directory
Can anyone tell me what are the exact steps I need to do to fix this?
EDIT:
Here is what I am writing from the answers below:
~$ python /home/username/Desktop/myfile.py
Yet, I am getting this error:
python: can't open file '/home/username/Desktop/myfile.py': [Errno 2] No such file or directory
EDIT 2**
So here is something new:
if I write
python /home/username/Desktop myfile.py
I get this error
/usr/bin/python: can't find 'main' module in '/home/username/Desktop
If I write
python /home/username/myfile.py
I do not get an error, but I do not get any output either. Ubuntu just goes to the next line $
Strange on Ubuntu your path starts with c:\...
On Ubuntu user folders are usually in /home, user folder can be referenced by ~, so IMHO python ~/Desktop/myfile.py should work in your environment.
EDIT: noted you made Desktop folder, not original Desktop, that way when you are in that folder type pwd it will show full path, then put it in python PATH/myfile.py (and just in case you may type ls to show list of files in current folder on Linux to check you are indeed in the right folder where your program is).
ADDED: after discussion it turned to be double boot system, mount showed mounted windows disk and file.py was found and run!
Backslash '\' is an escape character, in Unix it will not be used if you put it in a path. It results in your error of path not found.
Use slash '/', your code should run.
It is weird that you have a path for windows, in Unix you should not have this type of path...
Open a terminal, go to the folder with your python script. Use pwd in the terminal to know the exact location and then copy the path and use the following (I take an example here):
python PATHTOYOURPYTHONSCRIPT/mypythonscript.py
You're trying to use windows path representation in Linux. Windows and Linux has different path representations.
In windows, you can use C:\ but in Linux it's just a / which is used to denote the root directory.
In the terminal, type 'pwd' where your python file is present in Ubuntu and you'll see the output as '/home/username/Desktop' which is not like windows.
So you need to run like, 'python /home/username/Desktop/my file.py'.
If you need to access the file present in the windows partition, you need to mount the windows partition. This can be done using the Files app present in Ubuntu. After that, you can navigate to /mnt/media/ and find your file.
I am learning OpenCV python and I am watching this YouTube tutorial of "finding lanes for self-driving cars".
At 10:24 of the video, this person opens a command and types python lanes.py.
If I do the same thing,
the command says
"python: can't open file 'lanes.py': [Errno 2] No such file or
directory"
Does anyone know how to fix this? Please do not hesitate to answer.
You don't have a file named lanes.py in the current directory.
Either you never created it, or you created it with the wrong name, or you're in the wrong directory.
Assuming that you have downloaded the tutorial files, make sure that your terminal is in the same directory as the file you want to open.
e.g. If lanes.py is in the folder /Downloads/Python
Then run cd /Downloads/Python to change directory (cd) before you start.
Then you should be able to type your command as:
$: /Downloads/Python> python lanes.py
(or similar, depending on your os)
Ok, this is a little bit of a strange one. I had some Python code that needed to load data from another folder using scipy's loadmat (this bit is not really relevant, but explains the remainder of the code). Before, I added the path at the beginning of the file via
path_to_add = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data/unit_tests'))
if not path_to_add in sys.path:
sys.path.insert(1, path_to_add)
and would load the file via
mat_file = loadmat('test_kernel',squeeze_me=False)
This code ran fine in Ubuntu 12.04. However, when I try running it in 14.04, it gives the error:
IOError: [Errno 2] No such file or directory: 'test_kernel.mat'
I printed out sys.path using
print sys.path
and sure enough, the right absolute directory with '/data/unit_tests' is present. If I go over to this folder and try to load the file using loadmat, it loads fine. But for whatever reason, even though the path is present on sys.path, I still get that error when I execute the script in another folder. Anyone have any ideas why?
What version of scipy were you using and what version are you using now? You can check by running:
import scipy
print scipy.__version__
As far as I can tell in my version of scipy (0.14.0) it doesn't use the sys.path at all to find files when running loadmat. I've checked the source code and it looks like it simply passes in the filename to the builtin open function. Is there a chance on the Ubuntu 12.04 system you were running the script from the same directory as the mat file? As a sanity check try running the loadmat function with the full path to the mat file.
Edit
Here's a question with the same general problem: open() can't find file given path relative to PYTHONPATH
The usual way to do what you are doing is either have a global "data" directory so when you need to load a data file you prefix the filename with that directory. Another way is to specify things as absolute/relative paths to the python script. If you get a little fancier and create a python package there are ways to load data files relative to the python package itself.
i have a python script which keeps crashing on:
subprocess.call(["pdftotext", pdf_filename])
the error being:
OSError: [Errno 2] No such file or directory
the absolute path to the filename (which i am storing in a log file as i debug) is fine; on the command line, if i type pdftotext <pdf_filename_goes_here> it works for any of the alledgedly bad file names. but when called using subprocess in python i keep getting that error.
what is going on???
also, i tried on the python interpreter, and it worked!
>>> import subprocess
>>> subprocess.call(["pdftotext", "/path/to/file/test.pdf"])
0
>>>
update: just to make it known to everyone, i also tried:
subprocess.call(["/usr/bin/pdftotext", "/path/to/file/test.pdf"])
which also gave the same error. and ive used /usr/bin/pdftotext test.pdf directly and it worked so i know that's the correct path to the pdftotext executable. any other suggestions?
You'll also get that error if it can't find the executable on path...try using a full path to pdftotext as well, and look at how the $PATH for subprocess.call is set.