我试图找出文件在Python虚拟环境中的位置。我正在关注this answer至How to retrieve a module's path?
我使用ipython
运行以下代码来测试内置模块的位置:
In [1]: import logging
In [2]: logging.__file__
Out[2]: '/Users/some_user/.pyenv/versions/3.6.5/lib/python3.6/logging/__init__.py'
为什么__file__
属性指向.pyenv
目录中的文件而不是虚拟环境中的文件?
背景/版本
我有以下版本:
python==3.6.5 (inside venv)
python==3.7.6 (outside venv)
ipython==7.14.0 (inside venv)
ipython==7.13.0 (outside venv)
我这样调用ipython
:/path/to/venv/bin/python -m IPython
Python 3.6.5 (default, Mar 10 2020, 12:09:24)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.14.0 -- An enhanced Interactive Python. Type '?' for help.