{"id":7013,"date":"2019-04-16T10:23:23","date_gmt":"2019-04-16T02:23:23","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=7013"},"modified":"2019-04-16T10:24:53","modified_gmt":"2019-04-16T02:24:53","slug":"%e8%a7%a3%e5%86%b3pyenv-virtualenv%e5%9c%a8su%e8%bf%9b%e5%85%a5root%e5%90%8e%e6%8a%a5%e9%94%99%ef%bc%9a_pyenv_virtualenv_hook-command-not-found","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/7013.html","title":{"rendered":"\u89e3\u51b3pyenv-virtualenv\u5728su\u8fdb\u5165root\u540e\u62a5\u9519\uff1a_pyenv_virtualenv_hook command not found"},"content":{"rendered":"<p>\u539f\u56e0\u5728\u4e8e\uff0cpyenv-virtualenv \u4fee\u6539\u4e86\u00a0PROMPT_COMMAND \u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nPROMPT_COMMAND=_pyenv_virtualenv_hook;history -a; \r\n{ z=$(history 1 | { read x y; echo $y; }); \r\necho -n &#x5B; $(date &quot;+%c&quot;) ]; echo -n &#x5B; $(who am i) ] ; \r\necho &#x5B; $z ]; } &gt;&gt; \/data\/.my_history\r\n<\/pre>\n<p>\u800c _pyenv_virtualenv_hook \u8fd9\u4e2a\u51fd\u6570\uff0c\u662f\u5728 ~\/.pyenv\/plugins\/pyenv-virtualenv\/bin\/pyenv-virtualenv-init \u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\uff0c\u901a\u8fc7 su \u547d\u4ee4\u5207\u6362\u5230 root \u7528\u6237\u65f6\uff0c\u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\u5e26\u8fc7\u53bb\u4e86\uff0c\u4f46\u662f _pyenv_virtualenv_hook \u5b9a\u4e49\u5374\u4e0d\u5728 root \u7528\u6237\u76ee\u5f55\u4e0b\u9762\u4e2d\uff0c\u6240\u4ee5\u627e\u4e0d\u5230\u8fd9\u4e2a\u51fd\u6570\u5b9a\u4e49\u3002<\/p>\n<p>PROMPT_COMMAND \u662f bash \u7684\u73af\u5883\u53d8\u91cf\uff0c\u8fd9\u4e2a\u53d8\u91cf\u7684\u4e2d\u5185\u5bb9\u662f\u4f5c\u4e3a\u4e00\u4e2a\u666e\u901a\u7684 bash \u547d\u4ee4\u6267\u884c\u7684\uff0c\u800c\u4e14\u6267\u884c\u65f6\u95f4\u662f\u5728 bash \u663e\u793a prompt \u4e4b\u524d\u3002 \u8fd9\u4e2a\u597d\u7406\u89e3\uff0c\u5c31\u662f\u8bf4\u6bcf\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u524d\uff0cPROMPT_COMMAND \u91cc\u9762\u5148\u6267\u884c\uff0c\u7136\u540e\u662f prompt\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5728 su \u8fdb\u5165 root \u540e\uff0c\u6bcf\u4e2a\u547d\u4ee4\u6267\u884c\u5b8c\uff0c\u90fd\u4f1a\u62a5\u9519\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nbash: _pyenv_virtualenv_hook: \u672a\u627e\u5230\u547d\u4ee4\r\n<\/pre>\n<p>\u89e3\u51b3\u529e\u6cd5\uff0c\u7f16\u8f91 ~\/.pyenv\/plugins\/pyenv-virtualenv\/bin\/pyenv-virtualenv-init \u6587\u4ef6\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n142 #if ! &#x5B;&#x5B; &quot;\\$PROMPT_COMMAND&quot; =~ _pyenv_virtualenv_hook ]]; then\r\n143 # PROMPT_COMMAND=&quot;_pyenv_virtualenv_hook;\\$PROMPT_COMMAND&quot;;\r\n144 #fi\r\n145 EOS\r\n146 ;;\r\n147 zsh )\r\n148 cat &lt;&lt; EOS\r\n149 typeset -g -a precmd_functions\r\n150 #if &#x5B;&#x5B; -z \\$precmd_functions&#x5B;(r)_pyenv_virtualenv_hook] ]]; then\r\n151 # precmd_functions=(_pyenv_virtualenv_hook \\$precmd_functions);\r\n152 #fi\r\n153 EOS\r\n<\/pre>\n<p>\u52a0\u4e0a\u4ee5\u4e0a\u6ce8\u91ca\uff0c\u5982\u56fe\uff1a<\/p>\n<p><a href=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2019\/04\/1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7014\" src=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2019\/04\/1.png\" alt=\"\" width=\"1270\" height=\"524\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u56e0\u5728\u4e8e\uff0cpyenv-virtualenv \u4fee\u6539\u4e86\u00a0PROMPT_COMMAND \u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\uff1a PROMPT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-7013","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/7013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=7013"}],"version-history":[{"count":3,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/7013\/revisions"}],"predecessor-version":[{"id":7017,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/7013\/revisions\/7017"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=7013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=7013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=7013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}