在 Windows 10 上的 Python 2.7 中创建 virtualenv,而其他 virtualenv 在 Python 3.8 中工作 [英] Create virtualenv in Python 2.7 on windows 10 while other virtualenv are working in Python 3.8
问题描述
我无法在 Python 2.7 中安装虚拟环境.每当我尝试此命令时py -m pip install --user virtualenv
或者py -m pip install --user venv
它表明要求已经在 3.8 中得到满足.虽然我已经激活了 Python 2.7 并且在 cmd py 中简单地输入 python
它显示了Python 2.7.12rc1 (v2.7.12rc1:13912cd1e7e8, Jun 12 2016, 05:51:33) [MSC v.1500 32 位 (Intel)] on win32
I'm unable to install a virtual environment in Python 2.7. Whenever I try this command
py -m pip install --user virtualenv
or
py -m pip install --user venv
it shows requirements are already satisfied in 3.8. Although I've activated the Python 2.7 and in cmd py simply typing python
it shows the
Python 2.7.12rc1 (v2.7.12rc1:13912cd1e7e8, Jun 12 2016, 05:51:33) [MSC v.1500 32 bit (Intel)] on win32
请指导我如何在 Python 2.7 中安装虚拟环境,而我不想卸载/删除 Python3.8 如果您需要进一步解释,请让我知道.非常感谢*
推荐答案
当您在 Windows PC 上安装了多个 Python 版本时,您可以使用特定的 Python.exe 文件来控制哪个版本你正在合作
When you have multiple version of Python installed on a Windows PC, you can use the specific Python.exe files to control which version you're working with
PS C:\> .\Python27\python.exe --version
Python 2.7.9
PS C:\> .\Python37\python.exe --version
Python 3.7.7
同样的规则适用于 pip
PS C:\> .\Python27\Scripts\pip.exe --version
pip 20.2.4 from C:\Python27\lib\site-packages\pip (python 2.7)
PS C:\> .\Python37\Scripts\pip.exe --version
pip 20.2.4 from c:\python37\lib\site-packages\pip (python 3.7)
您需要确保您已经使用 Python 2.7 版本的 pip 安装了 virtualenv,并通过检查路径来验证它使用的是正确的 Python 版本
You need to ensure that you've installed virtualenv using the Python 2.7 version of pip, and verify it's using the correct python version by checking the path
PS C:\> .\Python27\Scripts\pip.exe install virtualenv
PS C:\> .\Python27\Scripts\virtualenv.exe --version
virtualenv 20.1.0 from c:\python27\lib\site-packages\virtualenv\__init__.pyc
我也为这个演示安装了 Python 3.7 版本
I have a Python 3.7 version installed as well for this demonstration
PS C:\> .\Python37\Scripts\virtualenv.exe --version
virtualenv 20.1.0 from c:\python37\lib\site-packages\virtualenv\__init__.py
然后使用你想要的版本创建你的虚拟环境,激活它,它应该是你想要的 Python 版本
Then create your virtual environment using the version that you want, activate it and it should be the version of Python you want
PS C:\> .\Python27\Scripts\virtualenv.exe py2env
PS C:\> .\py2env\Scripts\activate
(py2env) PS C:\> python
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
最后,Python 3.7 示例
And finally, the Python 3.7 example
PS C:\> .\Python37\Scripts\virtualenv.exe py3env
PS C:\> .\py3env\Scripts\activate
(py3env) PS C:\> python
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
这篇关于在 Windows 10 上的 Python 2.7 中创建 virtualenv,而其他 virtualenv 在 Python 3.8 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!