如何使用python3创建虚拟环境

如何使用python3创建虚拟环境

问题描述:

我正在使用 python 2.7 + virtualenv版本1.10.1 来运行myproject项目。由于其他一些项目要求,我必须使用其他版本的python( Python 3.5 )和 Django 1.9 。为此,我在用户目录中安装了python。另外,我已将virtualenv( version-15.1.0 )下载并安装到我的用户目录中。
但是每当我尝试创建虚拟环境时,都会出现以下错误

I am using python 2.7 + virtualenv version 1.10.1 for running myproject projects. Due to some other projects requirement I have to work with other version of python(Python 3.5) and Django 1.9. For this I have installed python in my user directory. Also I have dowloaded 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

有人可以告诉我我在做什么错事

Can anybody tell what I am doing wrong with this

在Python 3.6及更高版本中,不建议使用pyvenv模块。改为使用以下单线:

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

python3 -m venv <myenvname>

这是推荐的方式由Python社区创建虚拟环境。

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