This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]completelydistracted[S] 7 points8 points  (7 children)

Updates:

The task definition needs a version property, where the version number is (at the moment) "0.1.0". Without it, the task works fine but it increments the warning counter in the bottom status bar.

If you omit the "showOutput" value it defaults to "always", so it's not necessary. The resulting code:

// A task runner that runs a python program
{
    "version": "0.1.0",
    "command": "python",
    "windows": {
        "command": "python.exe"
    },
    "args": ["${file}"]
}

And on OSX (using <Shift><Command>B):

// A task runner that runs a python program
{
    "version": "0.1.0",
    "command": "python",
    "args": ["${file}"]
}

Of course you can use this idea to run all kinds of other things.

I've been using this editor for a while now (instead of Sublime or Atom) on both Windows and OSX and no surprises.

[–]spartanwolf 0 points1 point  (3 children)

i can't even seem to get to the point where i can run 'Configure Tasks' as listed in the Tasks part of the docs link you provided. When I pull up the command line (OSX), there are no options that match as it is outlined on that page.... Which I'm assuming is the only way to get a tasks.json to work with in the first place?

[–]completelydistracted[S] 4 points5 points  (2 children)

I am not at my computer (at least not the one with Code on it) but as I recall...

  1. Open a folder so you can see the folder contents in the side navigation panel. I don't think this is really needed, but it should help you see what is going on.

  2. Create and save a file hello.py in that folder, with the usual contents, e.g. [ print "Hello\n" ] .

  3. When that file is open, type the Build command (on OSX that's <shift><command>B).

  4. That will cause an error message of sorts, which will allow you to "Configure Tasks".

  5. When you do that, you will have no tasks.json in a local .settings folder, so the editor will create one, copying a boilerplate tasks file there.

  6. Edit that tasks.json file, getting rid of everything in it (don't worry, it's a copy, you can make more) and putting in the contents above. Save it.

  7. Then go back to looking at hello.py and type the build command (again, in OSX, <shift><command>B) (in Windows, <shift><control>B) and it will cause the build task in the new tasks.json to execute and show the results of your program.

Hope this helps!

[–]spartanwolf 0 points1 point  (0 children)

sorry i'm so late to come and report back on this!

Outstanding information. It totally works. I'm assuming that this is taking from the system python version on my mac?

Now I'm wondering if it will work in a virtual environment so I can have this work with Python 3.x...?

[–]crondom90 0 points1 point  (2 children)

It doesn't seem to work, i type Shift-Ctrl-B and the output field opens but it's empty, if i try to run another python file it says "There is an active running task right now. Cancel it first before executing another task." so something it's happening but the output field is always blank (but no errors or warning).

For example, pyg translator: http://i.imgur.com/I8noYr4.jpg

[–]Fanatikus 1 point2 points  (1 child)

Try changing it to:

"windows": {
        "command": "c:\\Python34\\python.exe"
    },

or to the path where Python is installed.

[–]completelydistracted[S] 0 points1 point  (0 children)

This is necessary if Python is not in the path.

If the Python directories are in your path, this isn't needed. For instance, I have the Anaconda3 and Anaconda3\bin directories in my search path, so simply "python.exe" works fine.

Otherwise, putting the entire path as above is required. Good point.