[英]Is there some way to install a specific Python version when creating a virtual environment
I need to downgrade from python 3.8 to python 3.6 for Tensorflow in a virtual environment我需要在虚拟环境中为 Tensorflow 从 python 3.8 降级到 python 3.6
I usually create environment with python -m tempenv /path/to/venv
我通常使用
python -m tempenv /path/to/venv
创建环境
I noted from this article that you can specify the interpreter when creating a virtual environment我从这篇文章中注意到,您可以在创建虚拟环境时指定解释器
https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/ https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/
But this requires downloading the interpreter separately但这需要单独下载解释器
Is there a way to automatically do this in an elegant command or set of commands?有没有办法在一个优雅的命令或一组命令中自动执行此操作? So that it would download the needed version of Python (3.6) and the appropriate pip installation in the virtual environment folder?
这样它就可以在虚拟环境文件夹中下载所需版本的 Python (3.6) 和适当的 pip 安装?
You can only create a virtual environment for the version of Python you're using to create it with.您只能为用于创建它的 Python 版本创建虚拟环境。
Having said that, if you need virtual environments for different version of Python (eg 3.8.x and 2.7.x), you can simply install both version of Python and use the appropriate one to create new virtual environments with that version of Python in it.话虽如此,如果您需要不同版本的 Python(例如 3.8.x 和 2.7.x)的虚拟环境,您可以简单地安装两个版本的 Python 并使用适当的一个来创建包含该版本 Python 的新虚拟环境.
As suggested by @flakes, you can also package managers to further automate the process and avoid having to manually pick and install versions of Python to use - to your preference.正如@flakes 所建议的那样,您还可以包管理器来进一步自动化该过程,并避免手动选择和安装要使用的 Python 版本 - 根据您的喜好。 Tools like
pyenv
can then make your life easier switching between versions of Python.像
pyenv
这样的工具可以让你的生活更轻松地在 Python 版本之间切换。 However, then we're getting into opinions on what's better or easier - you can make it work with stock Python as suggested.但是,然后我们正在讨论什么更好或更容易 - 您可以按照建议使其与股票 Python 一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.