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

  • Use:

    python3 -m venv ./path-to-new-venv
    

    This is the recommended way to create virtual environments.

    Historically, a wrapper command pyvenv was provided for this. However, the wrapper was deprecated in Python 3.6, and removed in 3.8.