我可以确定 pip 在哪里安装软件包二进制文件/脚本pip3 install --user mypackage
using:
$(python3 -m site --user-base)/bin
是否有一种机制可以确定在哪里non-user安装二进制文件/脚本(例如pip3 install mypackage
)安装了吗?
请注意,我只对二进制文件/脚本的安装位置感兴趣,而不是库代码的安装位置感兴趣。
Update:
目标是确保 PATH 环境变量包含安装二进制文件/脚本的文件夹,因为这在过去给我带来了一些问题。
更新2:
$ python3 -c "import sysconfig; print(sysconfig.get_path('scripts'))"
/usr/local/Cellar/[email protected] /cdn-cgi/l/email-protection/3.8.5/Frameworks/Python.framework/Versions/3.8/bin
$ python3 -c "from pip._internal.locations import bin_py; print(bin_py)"
/usr/local/Cellar/[email protected] /cdn-cgi/l/email-protection/3.8.5/Frameworks/Python.framework/Versions/3.8/bin
但是,pip3 安装到/usr/local/bin
注意:
$ which pip3
/usr/local/bin/pip3
$ which python3
/usr/local/bin/python3
这已经在这里得到了回答(但我不能“关闭重复”,因为有赏金):
https://stackoverflow.com/a/62167797 https://stackoverflow.com/a/62167797
我相信规范的方法(前进)是使用sysconfig.get_path(...)
。根据具体需要,可以组合scheme and name。所以也许对于您的确切用例:
import sysconfig
scripts_path = sysconfig.get_path('scripts')
print(scripts_path)
As a 一行从外壳:
python -c "import sysconfig; print(sysconfig.get_path('scripts'))"
其他可能有助于识别正确目录的事情:
python -m site
python -m sysconfig
参考:
- https://docs.python.org/3.8/library/sysconfig.html#installation-paths https://docs.python.org/3.8/library/sysconfig.html#installation-paths
- https://docs.python.org/3.8/library/sysconfig.html#using-sysconfig-as-a-script https://docs.python.org/3.8/library/sysconfig.html#using-sysconfig-as-a-script
- https://docs.python.org/3.8/library/site.html#command-line-interface https://docs.python.org/3.8/library/site.html#command-line-interface
- https://discuss.python.org/t/proper-way-to-define-install-location-of-console-scripts/7188 https://discuss.python.org/t/proper-way-to-determine-install-location-of-console-scripts/7188
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)