Vscode: New `code` shell command fails if `python` points to Python 3

Created on 8 Mar 2016  路  9Comments  路  Source: microsoft/vscode

Just installed 0.10.10 and installed the code shell command:

$ code --help
  File "<string>", line 1
    import os,sys; print os.path.realpath(sys.argv[1])
                          ^
SyntaxError: invalid syntax
/usr/local/bin/code: line 10: ./MacOS/Electron: No such file or directory

VS Code itself works fine if I launch it via Spotlight.

I believe the problem is that I had a Python virtual environment active, and python points to Python 3. If I try code outside of that virtualenv, where python means Python 2, everything works fine.

I guess the options are:

  1. Make the launch script Python 2/3 compatible. (Step one would probably be to add from __future__ import print_function and update the print statements accordingly.)
  2. Do some extra work to guarantee that you launch the system Python and not the user's configured Python, though this is probably not a viable long-term approach since distributions like Fedora now default to Python 3 and don't even install Python 2 by default.
bug verified

Most helpful comment

You could also call print with parentheses which is compatible with both python 2 and 3.

print(os.path.realpath(sys.argv[1]))

All 9 comments

Interesting. We only use Python on OS X btw, since there is no easy way to have realpath in there.

70ab81b should fix it

@joaomoreno - Wouldn't it be better to go with option 1, per my earlier comment?

https://github.com/Microsoft/vscode/commit/70ab81b95eebca26dd5465b3d0b8e094140b5a4b will still break on systems where the system Python is Python 3, like Fedora.

As I said 2 comments above, Python is only used in OS X.

Oh sorry, I misunderstood what you were saying. This should work. :+1:

... and looking at the file that is in question, resources/darwin/bin/code.sh, that should've been obvious to me from the start. Derp. :sheep:

No worries, thanks for keeping an eye out!

Workaround: open /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code and change python to /usr/bin/python.

You could also call print with parentheses which is compatible with both python 2 and 3.

print(os.path.realpath(sys.argv[1]))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

VitorLuizC picture VitorLuizC  路  3Comments

curtw picture curtw  路  3Comments

NikosEfthias picture NikosEfthias  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

biij5698 picture biij5698  路  3Comments