我最近更新了我的全局pyenv,以使用较新版本的python并启用一些其他功能。问题是这破坏了我的powerline (我在bash上使用的状态线插件)设置。之前我跟随他们的instructions,他们提到使用repository-root是从pip show powerline-status获得的。
问题是除了路径本身之外,该命令还提供了许多其他信息。有没有办法让我的.bash_profile引用站点包路径,而不只是硬编码的绝对路径?
发布于 2020-01-12 08:51:35
一种方法是使用像python -c "import powerline as _; print(_.__path__[0])"这样的命令的输出,该命令将打印出包目录。使用它作为基本路径,然后就可以调用powerline.sh了。下面是我的.bash_profile中的内容:
#Powerline shell invoke
## Note: if you've upgrade pyenv and have with old powerline installed,
## make sure you 'pyenv shell' to the older release and
## uninstall powerline first. Otherwise you'll get 'command not found' errors.
## 1. start daemon - done in 'quiet' mode for speed optimization
powerline-daemon -q
## 2. start powerline shell
export POWERLINE_SITE_PACKAGE_PATH=`python -c "import powerline as _; print(_.__path__[0])"`
. $POWERLINE_SITE_PACKAGE_PATH/bindings/bash/powerline.sh警告:如果你经常使用pyenv本地环境,你可能需要比这更复杂的东西。
注意:你可以缓存这个值,这样我就不必每次都调用python了吗?理论上是这样的,但是在检查何时发生变化方面就变得复杂了。你也可以把绝对路径粘贴进去。您需要将路径保存到文件中,然后将其清除。现在让它保持简单。仅仅测试变量(通过执行诸如if [ -z ${POWERLINE_SITE_PACKAGE_PATH+x} ] ; then .....; fi之类的操作)不会在bash会话中持久存在。
答案受How do I find the location of my Python site-packages directory?启发
https://stackoverflow.com/questions/59700042
复制相似问题