首页 > 解决方案 > 如何自动激活python虚拟环境?

问题描述

您好,我的电脑上安装了两个 python,python2.7.6 和 python2.7.11,我使用 python2.7.11 作为虚拟环境版本。如何在重新启动设备时自动将终端设置为 python2.7.11。

标签: pythonubuntu-14.04

解决方案


echo $PATH

这将打印出您当前配置的 PATH。其中之一将包含python2.7.6.

激活虚拟环境后使用export PATH="new path here without the python folder"
Run将其删除。which python将此路径添加到$PATH

例子:

export PATH="$PATH:/usr/local/bin/python"

将您所做的更改添加到~/.profile~/.bash_profile中。否则,您运行的命令将仅计入当前 SSH 会话。profile在每个新的 SSH 会话中运行。


推荐阅读