whatwhatwhat
whatwhatwhat

Reputation: 2256

Python: Can't find file even though file referenced exists

I'm getting this error when trying to run a Python script. Is it saying that it can't find subprocess.py? Because I found it in the location it's listing there, so I doubt that's the issue. What file can't it find?

Traceback (most recent call last):
  File "D:\Projects\PythonMathPlots\MandelbrotVideoGenerator.py", line 201, in <module>
    run( ['open', 'MandelbrotZoom.mp4'] )
  File "C:\Users\Aaron\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 472, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\Aaron\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Aaron\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Upvotes: 2

Views: 1473

Answers (3)

CypherX
CypherX

Reputation: 7353

You may also try with subprocess.Popen(args, shell=True). The use of shell=True may be useful.

Also, use a path defined as path = os.path.join(filepath, filename) and then before passing the path to Popen, assert if os.path.exists(path)==True.

But note that there are some downsides to using shell=True:

  1. Actual meaning of 'shell=True' in subprocess
  2. https://medium.com/python-pandemonium/a-trap-of-shell-true-in-the-subprocess-module-6db7fc66cdfd

Upvotes: 0

Dylon
Dylon

Reputation: 1750

Make sure the user you're running the script as has read permission for the file.

Upvotes: 0

lenik
lenik

Reputation: 23498

You may need to put the full path in the run(...) command, to the open file, and the path to the .mp4 file as well.

Most likely, open does not exist on your system and you have to use the name of the video player software instead.

Upvotes: 1

Related Questions