I am trying to run a python script which is saved on OneDrive. The name of OneDrive is set by my organisation and so I cannot change it.
My problem is when I try to run any script it fails because of the apostrophe. I click on the arrow in vscode to run the file, which results in this bash command: /usr/bin/python3 /Users/username/the organisation's name/Desktop/scripts/mycode.py
In the terminal it just says quote>
and it looks like it’s waiting for input. When I click run again then the second apostrophe closes the quote and I get the output
/Library/Developer/CommandLineTools/usr/bin/python3: can't open file '/Users/username/the organisations name/Desktop/scripts/mycode.py
/Users/username/theorganisationsname/Desktop/scripts/mycode.py': [Errno 2] No such file or directory
The only way it works is if I type in the terminal: /usr/bin/python3 [path]
and use the esc character for the apostrophy, but it’s not a sustainable solution. I could do an alias I guess, but I’d need to do that for all scripts I have on onedrive. I can also store files locally, not on OneDrive, but I don’t like the idea of being defeated by an apostrophe.
Weirdly when I tried to replicate the problem on my laptop (I created a path /Users/username/Desktop/Code/Julia's folder/test.py
) the code runs fine. The bash command is /usr/bin/python3 "/Users/username/Desktop/Code/Julia's folder/test.py"
– the path is in quotation marks. This doesn’t happen when I run the file saved on onedrive.
Added info:
- The example path should actually be:
/Users/username/CloudStorage/the organisation's name/Desktop/scripts/mycode.py
to be more precise. I notices that when I change the path in vscode so it doesn’t include "CloudStorage" then everything is working (see my answer below for detail). - I also created a matlab file
/Users/username/CloudStorage/the organisation's name/Desktop/scripts/test.m
it runs fine with the original path (not sure if that indicates anything).
2
Answers
Partial solution: I initially opened the file through the OneDrive I had added to finder (there was an option when logging into Onedrive to
add to finder
, so I just used the path(?) it created to access the contents including when I opened it in vscode).So in vscode the path at the top was
/Users/username/Library/CloudStorage/the organisation's name/Desktop/scripts/mycode.py
. I clicked on Library and manually chose the organisation's name (skipping the CloudStorage bit) and the rest. Then the code run fine. Leaving this here in case someone has a similar problem.did you try the solution with a backslash containing ‘?
python3 path/organization ‘ s/hello.py
in my bash console this works fine