Python 3:在 cd-ing 到目录时自动执行 `source env/bin/activate` [英] Python 3: Automating `source env/bin/activate` upon cd-ing to a directory

查看:74
本文介绍了Python 3:在 cd-ing 到目录时自动执行 `source env/bin/activate`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前我在

> 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 正确使用 autoenvactivate.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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆