如何指定用于创建虚拟环境的python版本? [英] How to specify python version used to create Virtual Environment?

查看:146
本文介绍了如何指定用于创建虚拟环境的python版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 virtualenv

~ $ virtualenv my_env

但我需要使用 python3.5 作为 3.6 是 Opencv3 目前不支持.

but I need to use python3.5 as 3.6 is not currently supported by Opencv3.

我尝试在创建虚拟环境时使用 --python=<py_version> 标志,但这不起作用.

I've tried using the --python=<py_version> flag when creating a virtual environment but this doesn't work.

推荐答案

假设您已经安装了 python3 或任何所需的 Python 版本(2.6、2.7、3.5、3.6),现在在创建虚拟环境直接传递python可执行路径.因此这里有几个有效的例子

Assuming that you have installed python3 or any desired version of Python (2.6, 2.7, 3.5, 3.6), Now while creating the virtual environment directly pass the python executable path. Hence here are few valid example

$ virtualenv new_p2_env # Creates a new default python environment (usually python 2)

$ virtualenv -p python3 new_p3_env # Creates a new default python3 (python3 must be a valid command i.e found in the PATH) 

最后

# Directly point to any version of python binary, this can be even another virtualenv's bin/python. 
$ virtualenv -p /path/to/any/bin/python new_env 

这篇关于如何指定用于创建虚拟环境的python版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆