我如何了解一个给定的Python模块的源文件安装在哪里?Windows上的方法和Linux上的方法不同吗?

我特别试图寻找datetime模块的源代码,但我对更一般的答案也感兴趣。


当前回答

sys。Path list包含在运行时搜索模块的目录列表:

python -v
>>> import sys
>>> sys.path
['', '/usr/local/lib/python25.zip', '/usr/local/lib/python2.5', ... ]

其他回答

看看这个漂亮的"cdp"命令,cd到包含指定Python模块源代码的目录:

cdp () {
  cd "$(python -c "import os.path as _, ${1}; \
    print _.dirname(_.realpath(${1}.__file__[:-1]))"
  )"
}

sys。Path list包含在运行时搜索模块的目录列表:

python -v
>>> import sys
>>> sys.path
['', '/usr/local/lib/python25.zip', '/usr/local/lib/python2.5', ... ]

另一种从终端检查是否安装了多个python版本的方法。

$ python3 -m PIP show pyperclip

地点:/图书馆/框架/ Python.framework /版本/ 3.7 / lib / python3.7 /网站

$ python -m PIP show pyperclip

地点:/用户/ umeshvuyyuru /图书馆/ Python / 2.7 / lib / Python /网站

在python解释器中,您可以导入特定的模块,然后键入help(module)。这将提供诸如名称、文件、模块文档、描述等详细信息。

Ex:

import os

help(os)


Help on module os:

NAME

os - OS routines for Mac, NT, or Posix depending on what system we're on.

FILE

/usr/lib/python2.6/os.py

MODULE DOCS

http://docs.python.org/library/os

DESCRIPTION

This exports:

- all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc.

- os.path is one of the modules posixpath, or ntpath

- os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos'

等人

Python 3.2中的新功能,你现在可以使用dis模块中的code_info(): http://docs.python.org/dev/whatsnew/3.2.html#dis