简体   繁体   English

创建虚拟环境时是否有某种方法可以安装特定的 Python 版本

[英]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.

相关问题 创建虚拟环境后,在 virtualenv (virtualenvwrapper) 中使用特定的 python 版本 - use specific python version in virtualenv (virtualenvwrapper) after creating the virtual environment 创建特定版本的 Python 虚拟环境 - Create Python Virtual Environment with Specific Version 有没有办法用早期版本的python创建虚拟环境? - Is there a way to create a virtual environment with an earlier version of python? Python-创建虚拟环境时不设点 - Python - No pip when creating a virtual environment 虚拟环境安装python 3.9.x M1版本 - Install the python 3.9.x M1 version in a virtual environment 如何使用特定的 python 版本配置 python 虚拟环境? - How to config python virtual environment with a specific python version? 创建与Windows上安装版本不同的Python虚拟环境 - Creating Python virtual environment in different version than installed on Windows 无法使用 virtualenv 在 ubuntu 中创建具有特定版本 Python 的虚拟环境 - Cannot create a virtual environment with a specific version of Python in ubuntu with virtualenv 当 python 2.7 存在时,使用 python 3.8 创建虚拟环境 - Creating Virtual environment using python 3.8 when python 2.7 is present 在虚拟环境中降级Python版本 - Downgrade Python version in virtual environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM