Python -v 打印出垃圾信息

12

看起来 Python 运行得非常完美...

$ python
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

但是python -v命令会输出各种杂乱无章的内容:

$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py
import site # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py
import os # precompiled from /u


<..................>

   /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.pyc
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_osx_support.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_osx_support.py
import _osx_support # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_osx_support.pyc
# zipimport: found 135 names in /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-5.4.2-py2.7.egg
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sitecustomize.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sitecustomize.py
import sitecustomize # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sitecustomize.pyc
# zipimport: found 135 names in /usr/local/lib/python2.7/site-packages/setuptools-5.4.2-py2.7.egg
import encodings # directory /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/__init__.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/__init__.pyc
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py
import codecs # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/aliases.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/aliases.pyc
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.pyc
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so

我使用brew安装了所有东西。这是一台新的MacBook Pro,更新了Mavericks系统。


3
你认为这不是预期的输出,是什么让你这样想? - Ismail Badawi
可能是如何检查正在运行脚本的Python版本?的重复问题。 - martijnn2008
我不明白为什么这个问题被标记为“无法重现或由打字错误引起”。这个问题显然是由错误的假设引起的,即“-v”参数应该打印版本。 - freedev
3个回答

11
如果您想查看版本信息,请使用 python -V(大写字母 V)或 python --version 命令。

8

这并不是垃圾信息,你正在以详细模式加载默认的Python解释器,这些依赖项是它加载所需的。

无论在任何操作系统上,您都会从任何解释器中获得类似的堆栈信息。

从运行-h命令提供的帮助菜单中:

v:详细模式(跟踪导入语句);还可以多次提供PYTHONVERBOSE=x以增加详细程度


手册的输出更有帮助: -v 每次初始化模块时打印一条消息,显示加载它的位置(文件名或内置模块)。当给定两次时,在搜索模块时检查每个文件时都会打印一条消息。还提供有关退出时模块清理的信息。 - Anuj Biyani

1

只需输入python --version,你是看不到它的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接