简体   繁体   English

使用和不使用Python运行venv命令之间有什么区别?

[英]What is difference between using and not using Python to run the venv command?

I'm making a concerted effort to understand how Python packaging works and I keep seeing the following idiom being used over and over. 我正在共同努力,以了解Python打包的工作原理,并且不断看到以下习惯用法不断被使用。 For example, if you're using venv to create a virtual environment, you can do this... 例如,如果您使用venv创建虚拟环境,则可以执行此操作...

python3 -m venv tutorial_env

or you can do this 或者你可以这样做

pyvenv tutorial_env

Under the hood, what is the real difference between using python3 to create the virtual environment and using pyvenv to create it? 在后台,使用python3创建虚拟环境与使用pyvenv创建虚拟环境之间的真正区别是什么? Why would you use one command rather than the other? 为什么要使用一个命令而不是另一个命令?

According to python docs both are equivalent. 根据python docs两者是等效的。 Here is the pvenv script from python 3.4 source code : 这是python 3.4源代码中pvenv脚本

#!/usr/bin/env python3
if __name__ == '__main__':
    import sys
    rc = 1
    try:
        import venv
        venv.main()
        rc = 0
    except Exception as e:
        print('Error: %s' % e, file=sys.stderr)
    sys.exit(rc)

Note: 注意:

The pyvenv script shipped with Python 3 but has been deprecated in Python 3.6+ in favour of python3 -m venv . pyvenv脚本是Python 3附带的,但在Python 3.6+中已弃用,而推荐使用python3 -m venv This prevents confusion as to what Python interpreter pyvenv is connected to and thus what Python interpreter will be used by the virtual environment. 这样可以避免关于Python解释器pyvenv连接到哪个以及由此虚拟环境将使用哪个Python解释器的混淆。

Mayank Porwal's answer lead me to this question which says that pyvenv is a wrapper around venv that was deprecated in Python 3.6. Mayank Porwal的回答使我想到了这个问题 ,它说pyvenv是venv的包装,在Python 3.6中已弃用。

This What's New in Python 3.6 tells why pyvenv was deprecated. 《 Python 3.6的新增功能》说明了为什么不推荐使用pyvenv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM