I'm trying to run a file path powershell command through python. `
import subprocess
subprocess.call('powershell.exe cd OneDrive\Desktop\OpenPose\openpose-1.7.0-binaries-win64-gpu-python3.7-flir-3d_recommended', shell=True)
` The error message displays: Cannot find path 'C:\Users\cubeow\OneDrive\Desktop\OpenPoseImplementation\OneDrive\Desktop\OpenPose\openpose-1.7.0-binarie s-win64-gpu-python3.7-flir-3d_recommended' because it does not exist.
The error message showed that they had added a root path in front of my command, in which "OpenPoseImplementation" was my Pycharm file path. How can I make it so that they don't add that extra file path in front of my command?
I tried to google other reddit and stackoverflow but I couldn't find any working solutions
CodePudding user response:
You're mistakenly using a relative path to target your OneDrive folder, which therefore depends on whatever happens to be the current folder you're running your Python script from.
Use an absolute path instead (~
represents your Windows profile directory, as also reflected in $HOME
):
import subprocess
subprocess.call('powershell.exe cd ~\OneDrive\Desktop\OpenPose\openpose-1.7.0-binaries-win64-gpu-python3.7-flir-3d_recommended', shell=True)
Note:
- As written, this command doesn't actually do anything (it changes the current location (working directory) and then exits). Additional PowerShell commands would have be to be appended, separated with
;