Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Syntax Error #1

Closed
wesbaker opened this issue Mar 24, 2010 · 9 comments
Closed

Syntax Error #1

wesbaker opened this issue Mar 24, 2010 · 9 comments

Comments

@wesbaker
Copy link

When I added vcprompt to my prompt, I keep seeing this error

File "/home/nomad/bin/vcprompt", line 541                                     
    from __future__ import with_statement
SyntaxError: from __future__ imports must occur at the beginning of the file
@djl
Copy link
Owner

djl commented Mar 24, 2010

I'm unable recreate this on any version of Python from 2.5.0 to the 2.7 alphas.

Which version of Python and vcprompt are you running?

@wesbaker
Copy link
Author

Python 2.6.4 and I'm using this version of vcprompt (http://github.com/xvzf/vcprompt/raw/master/bin/vcprompt); just downloaded it today.

@djl
Copy link
Owner

djl commented Mar 24, 2010

A few things to try:

  • Try to run it manually (i.e. python ~/bin/vcprompt)
  • Try adding the .py extension to the file and run it again

Failing those, how is your prompt configured?

@wesbaker
Copy link
Author

Here's my config file. I've commented out the prompt with vcprompt for the moment, but it's still there. As a heads up, I'm using zsh.

autoload -U colors
colors
setopt prompt_subst
PROMPT='%{$fg[yellow]%}%n%{$reset_color%}:%~ %{$fg[green]%}→ %{$reset_color%}'
# PROMPT='%{$fg[yellow]%}%n%{$reset_color%}:%~ %{$fg[green]%}$(vcprompt)→ %{$reset_color%}'

# Set RPROMPT to have info show up on the right, too.

#############################
# Other Options

# setopt PRINT_EXIT_VALUE

setopt CORRECT
setopt CORRECTALL

setopt hist_ignore_dups     # ignore duplication command history list
setopt share_history        # share command history data
setopt HIST_IGNORE_SPACE
setopt APPEND_HISTORY # write history only when closing
setopt EXTENDED_HISTORY # add more info

# Other tabbing options
# setopt NO_AUTO_MENU
# setopt BASH_AUTO_LIST

#############################
# Variables

# Quote pasted URLs
autoload url-quote-magic
zle -N self-insert url-quote-magic

HISTFILE=~/.zsh_history
SAVEHIST=10000
HISTSIZE=10000

REPORTTIME=10 # Show elapsed time if command took more than X seconds
LISTMAX=0 # ask to complete if top of list would scroll off screen

# Load completions for Ruby, Git, etc.
autoload compinit
compinit

# Make CTRL-W delete after other chars, not just spaces
WORDCHARS=${WORDCHARS//[&=\/;\!#%\{]}

bindkey -e

@djl
Copy link
Owner

djl commented Mar 24, 2010

Well, I'm stumped :(

I'm pretty sure it's not a problem with vcprompt. I've tested on OS X, Ubuntu and FreeBSD Python builds and it worked without issue.

Does Python still choke if you run a really simple script? Something like this should be enough:

#!/usr/bin/env python
from __future__ import with_statement
with open('/dev/null', 'w') as devnull:
    devnull.write('wtf is going on?')

If that doesn't work, then it may be a problem with your Python build but I have no idea what would cause it.

@wesbaker
Copy link
Author

I'm getting a pretty strange error:

from: can't read /var/mail/__future__
test: 3: Syntax error: "(" unexpected

I'm going to try tinkering with my copy of Python.

@djl
Copy link
Owner

djl commented Mar 24, 2010

Weird. It looks like vcprompt is being run as a shell script instead of a Python script.

If you run /usr/bin/env python does it drop you into a Python REPL?

@wesbaker
Copy link
Author

Yeah, it seems to.

@djl
Copy link
Owner

djl commented Mar 25, 2010

Crazy.

It's definitely not a syntax error in vcprompt (if it was, I'd also be seeing the error) but I'll leave this open for now.

The only thing I can think of now is that /usr/bin/env python isn't returning the correct Python interpreter.

Try hard-coding the path to your Python binary as the shebang line:

#!/path/to/bin/python

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants