3

After a successful installation of virtualenv on centos7

pip install virtualenv

while creating new virtualenv it keeps showing below mentioned error even if I am checking

virtualenv --version

This also shows the same error.

Traceback (most recent call last):
  File "/usr/bin/virtualenv", line 7, in <module>
    from virtualenv.__main__ import run_with_catch
  File "/usr/lib/python2.7/site-packages/virtualenv/__init__.py", line 3, in <module>
    from .run import cli_run
  File "/usr/lib/python2.7/site-packages/virtualenv/run/__init__.py", line 12, in <module>
    from .plugin.activators import ActivationSelector
  File "/usr/lib/python2.7/site-packages/virtualenv/run/plugin/activators.py", line 6, in <module>
    from .base import ComponentBuilder
  File "/usr/lib/python2.7/site-packages/virtualenv/run/plugin/base.py", line 9, in <module>
    from importlib_metadata import entry_points
  File "/usr/lib/python2.7/site-packages/importlib_metadata/__init__.py", line 9, in <module>
    import zipp
  File "/usr/lib/python2.7/site-packages/zipp.py", line 153
SyntaxError: Non-ASCII character '\xe2' in file /usr/lib/python2.7/site-packages/zipp.py on line 154, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

I tried to uninstall and re-install it again but so far no luck.

2 Answers 2

4

You're using Python 2.7 (which is end-of-life) with a version of Virtualenv that doesn't support Python 2.7.

In order of preference,

  • stop using Python 2.7 and use Python 3.x (currently 3.8) instead
  • or install an older version of Virtualenv (e.g. pip install "virtualenv<20.0", or whatever major version of Virtualenv ends up working for you).
Sign up to request clarification or add additional context in comments.

7 Comments

Definitely I need to upgrade soon.
I encounter with an issue after virtualenv creation which is I am not able to upgrade pip or any other package as it keeps showing error of ssl/https any idea about that ?
That's a different question (ask it separately with your commands and resulting error), and not knowing the error it's hard to help. Probably a network or proxy problem.
stackoverflow says i can't post next question within 90mins. waiting
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.