pythonpython-3.xvirtualenv

How to create virtual env with Python 3?


I am using Python 2.7 + virtualenv version 1.10.1 for running myproject project. Due to some other projects requirement I have to work with another version of Python (3.5). For this I have installed Python in my user directory. Also I have downloaded and installed virtualenv (version 15.1.0) into my user directory.

But whenever I am trying to create virtual env I am getting the below error

python virtualenv/virtualenv.py myproject

Using base prefix '/home/myuser/python3'
New python executable in /home/mount/myuser/project_python3/myproject/bin/python
ERROR: The executable /home/mount/myuser/project_python3/myproject/bin/python is not functioning
ERROR: It thinks sys.prefix is '/home/myuser/python3' (should be '/home/mount/myuser/project_python3/myproject')
ERROR: virtualenv is not compatible with this system or executable

What am I doing wrong here and how do I solve it?


Solution

  • In Python 3.6+, the pyvenv module is deprecated. Use the following one-liner instead:

    python3 -m venv <myenvpath>
    

    This is the recommended way to create virtual environments by the Python community.