如pip 文档中所述,用户可以使用pip install --user <pkg>.
如何以编程方式确定这样安装的脚本的用户安装位置?我说的是应该添加到 PATH 中的目录,以便可以从命令行调用已安装的包。
例如,在 Windows 中安装时pip install -U pylint --user我收到以下警告,因为我'C:\Users\myusername\AppData\Roaming\Python\Python37\Scripts'的 PATH 中没有:
...
Installing collected packages: wrapt, six, typed-ast, lazy-object-proxy, astroid, mccabe, isort, colorama, toml, pylint
Running setup.py install for wrapt ... done
WARNING: The script isort.exe is installed in 'C:\Users\myusername\AppData\Roaming\Python\Python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts epylint.exe, pylint.exe, pyreverse.exe and symilar.exe are installed in 'C:\Users\myusername\AppData\Roaming\Python\Python37\Scripts' which is not on PATH.
是否有一些 python 代码可以用来以编程方式确定该位置(适用于 Windows/Linux/Darwin/等)?就像是:
def get_user_install_scripts_dir():
...
# would return 'C:\Users\myusername\AppData\Roaming\Python\Python37\Scripts'
# on Windows with Python 3.7.x, '/home/myusername/.local/bin' in Linux, etc
return platform_scripts_dir
作为后备,我可以运行一些命令来获取这个位置吗?类似的东西(但脚本位置不是站点的基本目录):
PS C:\Users\myusername\> python -m site --user-base
C:\Users\myusername\AppData\Roaming\Python
$ python -m site --user-base
/home/myusername/.local
慕斯王
守着星空守着你
相关分类