gpt4 book ai didi

python - 如何指定用于创建虚拟环境的 python 版本?

转载 作者:IT老高 更新时间:2023-10-28 22:15:34 29 4
gpt4 key购买 nike

我的 Python 虚拟环境使用 python3.6当我使用 virtualenv 创建它们时

~ $ virtualenv my_env

但我需要使用 python3.5因为 3.6 是 not currently supported by Opencv3 .

我试过使用 --python=<py_version>创建虚拟环境时标记,但这不起作用。

如何使用 virtualenv 指定要安装的 python (3.x) 版本适用于 Mac 和/或 Linux?

最佳答案

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

$ 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 - 如何指定用于创建虚拟环境的 python 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45293436/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com