In my case I get this similar error when running workon <foo>:
xb@dnxb:/tmp$ workon foo
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/xiaobai/.local/lib/python3.6/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
from stevedore import ExtensionManager
File "/home/xiaobai/.local/lib/python3.6/site-packages/stevedore/__init__.py", line 11, in <module>
from .extension import ExtensionManager
File "/home/xiaobai/.local/lib/python3.6/site-packages/stevedore/extension.py", line 19, in <module>
from . import _cache
File "/home/xiaobai/.local/lib/python3.6/site-packages/stevedore/_cache.py", line 31, in <module>
import importlib_metadata
File "/home/xiaobai/.local/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 9, in <module>
import zipp
File "/home/xiaobai/.local/lib/python3.6/site-packages/zipp.py", line 153
SyntaxError: Non-ASCII character '\xe2' in file /home/xiaobai/.local/lib/python3.6/site-packages/zipp.py on line 154, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
...
The error showing python2.7/runpy.py at the beginning but I expect to use python 3 in whole process.
Then I get same error when source /usr/share/virtualenvwrapper/virtualenvwrapper.sh too.
So I check the file and noticed it use python 2 based on result of which python command, which /usr/bin/python symlink to python2.7 in my system:
xb@dnxb:/tmp$ grep -n which /usr/share/virtualenvwrapper/virtualenvwrapper.sh
50: VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
316: typeset exe_path="$(command \which "$1" | (unset GREP_OPTIONS; command \grep -v "not found"))"
xb@dnxb:/tmp$ which python
/usr/bin/python
So simply edit this line to hard-coded path /usr/bin/python3 (my python3 path), no more error either of source or workon:
xb@dnxb:/tmp$ sudo sed -i 's/VIRTUALENVWRAPPER_PYTHON="$(command \\which python)"/VIRTUALENVWRAPPER_PYTHON=\/usr\/bin\/python3/g' /usr/share/virtualenvwrapper/virtualenvwrapper.sh
xb@dnxb:/tmp$ grep -n which /usr/share/virtualenvwrapper/virtualenvwrapper.sh
316: typeset exe_path="$(command \which "$1" | (unset GREP_OPTIONS; command \grep -v "not found"))"
xb@dnxb:/tmp$ grep -n python3 /usr/share/virtualenvwrapper/virtualenvwrapper.sh
50: VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
xb@dnxb:/tmp$ workon foo
(foo) xb@dnxb:/tmp$
And of course, you can set VIRTUALENVWRAPPER_PYTHON environment variable if you want to use python 2 or 3 dynamically without edit this script.