Python 3:在 cd-ing 到目录时自动执行 `source env/bin/activate` [英] Python 3: Automating `source env/bin/activate` upon cd-ing to a directory
问题描述
以前我在
> port select --list python
..
python27 (active)
..
现在,即使之后
> sudo port select --set python python36
和
> pip install autoenv==1.0.0
我还是发现activate.sh
> which activate.sh
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/activate.sh
指向 2.7.
现在我想替换之前的调用
Now I'd like to replace the previous call
> echo "source `which activate.sh`" >> ~/.bash_profile
新的 Python 3(.6).
with a fresh one for Python 3(.6).
如何为 Python 3.6 正确使用 autoenv
和 activate.sh
?我猜 /opt/local/Library/Frameworks/Python.framework/Versions/2.7
的存在应该是不必要的.
How do I properly engage autoenv
and activate.sh
for Python 3.6? I am guessing that the existence of /opt/local/Library/Frameworks/Python.framework/Versions/2.7
should be unnecessary.
推荐答案
activate.sh
from autoenv
是用 shell 编写的,并没有以任何方式提及 Python.它应该适用于任何具有 .env
的目录.所以你实际上不需要重新安装它.但是如果你仍然想要 - pip install
通常为 Python 2 安装.使用
activate.sh
from autoenv
is written in shell and doesn't mention Python in any way. It should work with any directory that has .env
. So you actually don't need to reinstall it. But if you still want — pip install
usually installs for Python 2. Use
pip uninstall autoenv
pip3 install autoenv
卸载 Python 2 的 autoenv
并安装 Python 3.
to uninstall autoenv
for Python 2 and install it for Python 3.
这篇关于Python 3:在 cd-ing 到目录时自动执行 `source env/bin/activate`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!