创建Flask虚拟环境时报错

前提:创建Flask虚拟环境,需要使用Python2版本,pip默认的就是python2,但是执行mkvirtualenv Flask_py会报错。

报错内容:OSError: Command /home/python/.virtua...Flask_py/bin/python2 - setuptools pkg_resources pip wheel failed with error code 2

pip版本:

python@ubuntu:~/.virtualenvs$ pip -V
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
python@ubuntu:~/.virtualenvs$ 

如果你试过网上说的升级pip版本的方法,但是没成功。

可以试着指定Python的版本

python@ubuntu:~/.virtualenvs$ mkvirtualenv -p /usr/bin/python2.7 Flask_py
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /home/python/.virtualenvs/Flask_py/bin/python2.7
Also creating executable in /home/python/.virtualenvs/Flask_py/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/python/.virtualenvs/Flask_py/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/python/.virtualenvs/Flask_py/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/python/.virtualenvs/Flask_py/bin/preactivate
virtualenvwrapper.user_scripts creating /home/python/.virtualenvs/Flask_py/bin/postactivate
virtualenvwrapper.user_scripts creating /home/python/.virtualenvs/Flask_py/bin/get_env_details

PS:先进虚拟环境目录查看是否已存在,因为就算之前执行失败,这个目录也有可能已经被创建,指定Python版本执行前,先进目录把已经存在的虚拟环境删除!

python@ubuntu:~/.virtualenvs$ ls
django_py2       initialize      postmkvirtualenv  premkproject     py3         tornado_py2
django_py3       postactivate    postrmvirtualenv  premkvirtualenv  py3_django
Flask_py         postdeactivate  preactivate       prermvirtualenv  py_django
get_env_details  postmkproject   predeactivate     py2              spider_py2

最后,如果还是不行!!!重启电脑!!!

你可能感兴趣的:(Flask)