Error when opening a terminal under Mac OS X Sierra

47 views
Skip to first unread message

moulin...@gmail.com

unread,
Jun 9, 2018, 11:34:21 AM6/9/18
to virtualenvwrapper
Hello,

I have installed virtualenv and virtualwrapper using "pip3 install virtualenv virtualenvwrapper" but get the following error when i source ~/.bash_profile (which includes "source /usr/local/bin/virtualenvwrapper.sh"):

-bash: /usr/local/bin/virtualenvwrapper.sh: line 126: syntax error near unexpected token `os.path.normpath'

-bash: /usr/local/bin/virtualenvwrapper.sh: line 126: `        "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')"'



I have also changed the "which python" command in virtualenvwrapper.sh into "which python3" to get a correct path (the "non-system-python" one).

Any idea about the syntax error?

Thank you for help,
Richard

Doug Hellmann

unread,
Jun 9, 2018, 11:53:37 AM6/9/18
to virtualenvwrapper
Excerpts from moulingruaux's message of 2018-06-09 08:34:21 -0700:
Rather than modifying the which command in the script, try setting
VIRTUALENVWRAPPER_PYTHON to point to the python3 executable you want to
use, before sourcing virtualenvwrapper.sh in your bash profile.

Doug

moulin...@gmail.com

unread,
Jun 9, 2018, 12:52:17 PM6/9/18
to virtualenvwrapper
Thank you Doug.

I have added VIRTUALENVWRAPPER_PYTHON='/usr/local/bin/python3' before the "source /usr/local/bin/virtualenvwrapper.sh" line and reset which python3 back to which python but still get the same syntax error lines.

Richard

Doug Hellmann

unread,
Jun 10, 2018, 11:54:45 AM6/10/18
to virtualenvwrapper
Excerpts from moulingruaux's message of 2018-06-09 09:52:16 -0700:
> Thank you Doug.
>
> I have added VIRTUALENVWRAPPER_PYTHON='/usr/local/bin/python3' before the
> "source /usr/local/bin/virtualenvwrapper.sh" line and reset which python3
> back to which python but still get the same syntax error lines.

OK, I'm going to need a little more information to help debug.

Which OS are you on?

Which version of bash?

bash --version

Which version of python?

$VIRTUALENVWRAPPER_PYTHON --version

Running the function that is reporting the error with debug tracing on
may also provide some useful information:

set -x
virtualenvwrapper_expandpath "$HOME/.virtualenvs"
set +x

Gruaux Moulin

unread,
Jun 10, 2018, 1:50:40 PM6/10/18
to virtuale...@googlegroups.com
Hello Doug,

I’m using MacOS X Sierra ver 10.12.6 on a Mac Book Pro (autumn 2011)

Bash version
pc38:~ Richard$ bash -version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

Python version
pc38:~ Richard$ $VIRTUALENVWRAPPER_PYTHON --version
Python 3.6.5


For the last lines do i have to type those 3 commands in the terminal?
I did that: see attachment

SetX.txt

Doug Hellmann

unread,
Jun 10, 2018, 3:41:51 PM6/10/18
to virtualenvwrapper
Excerpts from Gruaux Moulin's message of 2018-06-10 19:50:40 +0200:
Yes, although you also need to source virtualenvwrapper.sh first (sorry,
I didn't specify that).

What I'm trying to learn is what the shell is actually executing when it
runs that virtualenvwrapper_expandpath function, since that is what is
producing the error.

Another question just occurred to me. When you set
VIRTUALENVWRAPPER_PYTHON, did you use export, like this:

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3

Doug

Gruaux Moulin

unread,
Jun 10, 2018, 4:07:11 PM6/10/18
to virtuale...@googlegroups.com
No i left the virtualenvwrapper.sh file as it was
# 10. Run: workon temp
# 11. The virtual environment is activated.
#

# Locate the global Python where virtualenvwrapper is installed.
if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python) »
fi

# Set the name of the virtualenv app to use.
if [ "${VIRTUALENVWRAPPER_VIRTUALENV:-

….

Richard


-- 
You received this message because you are subscribed to the Google Groups "virtualenvwrapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to virtualenvwrap...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Doug Hellmann

unread,
Jun 10, 2018, 9:34:03 PM6/10/18
to virtualenvwrapper
Doug

Excerpts from Gruaux Moulin's message of 2018-06-10 22:07:07 +0200:
> > To unsubscribe from this group and stop receiving emails from it, send an email to virtualenvwrap...@googlegroups.com <mailto:virtualenvwrap...@googlegroups.com>.
> > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>

Gruaux Moulin

unread,
Jun 13, 2018, 8:53:28 AM6/13/18
to virtuale...@googlegroups.com
Hi Doug,

Do you expect something from me? I may have missed something..


Thanks,
Richard
> To unsubscribe from this group and stop receiving emails from it, send an email to virtualenvwrap...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Doug Hellmann

unread,
Jun 13, 2018, 10:21:11 AM6/13/18
to virtualenvwrapper
Apparently I had an issue composing or sending that last email. My
apologies.

Could you send the configuration in your .bash_profile that you have for
setting up virtualenvwrapper? Any variables you are setting and the line
you're using to source virtualenvwrapper.sh would be good.

I also need you to re-run these commands because the output you sent
before showed that the function was not defined (probably because you
had not sourced virtualenvwrapper.sh yet). If virtualenvwrapper.sh is
not in /usr/local/bin please replace that path with the path to
wherever it is installed.

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
set -x
virtualenvwrapper_expandpath "$HOME/.virtualenvs"
set +x

What I'm trying to learn is what the shell is actually executing when it
runs that virtualenvwrapper_expandpath function, since that is what is
producing the error.

Excerpts from Gruaux Moulin's message of 2018-06-13 14:53:26 +0200:

Gruaux Moulin

unread,
Jun 13, 2018, 12:01:03 PM6/13/18
to virtuale...@googlegroups.com
Hello Doug,

Here are some terminal results
pc88:~ Richard$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
pc88:~ Richard$ source /usr/local/bin/virtualenvwrapper.sh
-bash: /usr/local/bin/virtualenvwrapper.sh: line 126: syntax error near unexpected token `os.path.normpath'
-bash: /usr/local/bin/virtualenvwrapper.sh: line 126: `        "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')"'
pc88:~ Richard$ set -x
++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=
++ (( i = 0 ))
++ (( i < 14 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 14 ))
++ ch=U
++ [[ U =~ [/._~A-Za-z0-9-] ]]
++ url_path+=U
++ (( ++i ))
++ (( i < 14 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 14 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 14 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 14 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 14 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 14 ))
++ ch=R
++ [[ R =~ [/._~A-Za-z0-9-] ]]
++ url_path+=R
++ (( ++i ))
++ (( i < 14 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 14 ))
++ ch=c
++ [[ c =~ [/._~A-Za-z0-9-] ]]
++ url_path+=c
++ (( ++i ))
++ (( i < 14 ))
++ ch=h
++ [[ h =~ [/._~A-Za-z0-9-] ]]
++ url_path+=h
++ (( ++i ))
++ (( i < 14 ))
++ ch=a
++ [[ a =~ [/._~A-Za-z0-9-] ]]
++ url_path+=a
++ (( ++i ))
++ (( i < 14 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 14 ))
++ ch=d
++ [[ d =~ [/._~A-Za-z0-9-] ]]
++ url_path+=d
++ (( ++i ))
++ (( i < 14 ))
++ printf '\e]7;%s\a' file://pc88.home/Users/Richard
pc88:~ Richard$ virtualenvwrapper_expandpath "$HOME/.virtualenvs"
+ virtualenvwrapper_expandpath /Users/Richard/.virtualenvs
-bash: virtualenvwrapper_expandpath: command not found
++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=
++ (( i = 0 ))
++ (( i < 14 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 14 ))
++ ch=U
++ [[ U =~ [/._~A-Za-z0-9-] ]]
++ url_path+=U
++ (( ++i ))
++ (( i < 14 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 14 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 14 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 14 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 14 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 14 ))
++ ch=R
++ [[ R =~ [/._~A-Za-z0-9-] ]]
++ url_path+=R
++ (( ++i ))
++ (( i < 14 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 14 ))
++ ch=c
++ [[ c =~ [/._~A-Za-z0-9-] ]]
++ url_path+=c
++ (( ++i ))
++ (( i < 14 ))
++ ch=h
++ [[ h =~ [/._~A-Za-z0-9-] ]]
++ url_path+=h
++ (( ++i ))
++ (( i < 14 ))
++ ch=a
++ [[ a =~ [/._~A-Za-z0-9-] ]]
++ url_path+=a
++ (( ++i ))
++ (( i < 14 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 14 ))
++ ch=d
++ [[ d =~ [/._~A-Za-z0-9-] ]]
++ url_path+=d
++ (( ++i ))
++ (( i < 14 ))
++ printf '\e]7;%s\a' file://pc88.home/Users/Richard
pc88:~ Richard$ set +x
+ set +x
pc88:~ Richard$ 


My bash_profile

Bash-Profile
virtualenvwrapper.sh

Doug Hellmann

unread,
Jun 13, 2018, 12:22:18 PM6/13/18
to virtualenvwrapper
OK, the function isn't being defined at all because of whatever syntax
error is being encountered.

Can you paste lines 120-130 of your copy of virtualenvwrapper.sh here?

You mentioned before making changes to the script (like to set which
version of python you were using). Did you make any other changes?

Doug

Excerpts from Gruaux Moulin's message of 2018-06-13 18:00:58 +0200:
> Virtualenvwrapper.sh
>
>
>
> The error occurs in virtualenvwrapper_expandpath but the problem seems to be linked to os.path.normpath (unexpected token?).
>
> Richard
> > Le 13 juin 2018 à 16:21, Doug Hellmann <do...@doughellmann.com> a écrit :
> >
> > set +x
>

Gruaux Moulin

unread,
Jun 14, 2018, 7:14:41 AM6/14/18
to virtuale...@googlegroups.com
Hi Doug,

Sorry for this late answer, we have been without electricity this morning.

No except « which python3 » i din’t make other changes in virtualenvwrapper.sh.

Here the lines 120-130

function virtualenvwrapper_expandpath {
if [ "$1" = "" ]; then
return 1
else
"$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')"
return 0
fi
}

Richard

Doug Hellmann

unread,
Jun 14, 2018, 8:56:11 AM6/14/18
to virtualenvwrapper
OK, that all looks fine.

The error you're seeing doesn't make any sense to me, and I can't
reproduce it, unfortunately.

virtualenvwrapper relies heavily on the shell's configuration, and
sometimes those settings affect the way the commands are interpreted.
Since the error has to do with parsing a line as the script is
sourced, rather than when it is run, it might be caused by something
like that.

This is an especially common source of problems reported by only
one person, so is it possible that you have some "unusual" setting(s)
in your bash profile? It might be something obscure. For example,
someone once aliased "done" which is a keyword [1].

[1] https://bitbucket.org/virtualenvwrapper/virtualenvwrapper/issues/161/usr-bin-virtualenvwrappersh-461-parse


Excerpts from Gruaux Moulin's message of 2018-06-14 13:14:38 +0200:

Gruaux Moulin

unread,
Jun 15, 2018, 4:57:19 AM6/15/18
to virtuale...@googlegroups.com
Hi Doug,

I made a change in virtualenvwrapper.sh :

if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python3)"
fi

by replacing the » after python3) by a normal double-quote "

and « source virtualenvwrapper.sh » gives now
source virtualenvwrapper.sh
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/get_env_details
pc88:~ Richard$ 

The error has now disappeared when i open the terminal
Last login: Fri Jun 15 10:21:46 on ttys002
pc88:~ Richard$ export PATH=/Applications/MAMP/bin/php/php7.1.8/bin/:$PATH
pc88:~ Richard$ 


Creation of virtual environment is OK

pc88:~ Richard$ mkvirtualenv cv3 -p python3
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/Richard/.virtualenvs/cv3/bin/python3.6
Also creating executable in /Users/Richard/.virtualenvs/cv3/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/cv3/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/cv3/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/cv3/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/cv3/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/Richard/.virtualenvs/cv3/bin/get_env_details
(cv3) pc88:~ Richard$ workon cv3
(cv3) pc88:~ Richard$ deactivate
pc88:~ Richard$ 

Conclusion: bloody double-quote corrector!!

Thank you for your help!

Richard

Doug Hellmann

unread,
Jun 15, 2018, 9:12:53 AM6/15/18
to virtualenvwrapper
Excerpts from Gruaux Moulin's message of 2018-06-15 10:57:16 +0200:
I'm glad you figured it out, and thank you for reporting back to let us
know that you had.

Doug
Reply all
Reply to author
Forward
0 new messages