Mac配置虚拟环境Virtualenv virtualenvwrapper
参考链接:https://www.jianshu.com/p/51140800e8b4
根据文档进行操作 基本不会有太大的问题:
可能会出现的问题 是 在执行 以下命令时 失败 可以尝试执行一下 同级目录中的 virtualenvwrapper_lazy.sh(每个人的电脑上virtualenvwrapper.sh 文件的路径有可能不一样 自己可以查找一下 )
source /usr/local/bin/virtualenvwrapper.sh
但是上述教程 仅适用于 mac系统自带的shell 没有任何命令提示 切换到fish shell 无法使用
VirtualFish
VirtualFish is a Python virtual environment manager for the Fish shell.(VirtualFish是Fish shell 的Python虚拟环境管理器。)
官方文档:https://virtualfish.readthedocs.io/en/latest/index.html (英文的 不太好理解~)
安装配置步骤:
1.升级fish shell 为 3.1+
2.根据文档进行安装 :https://virtualfish.readthedocs.io/en/latest/install.html#installing
python -m pip install virtualfish
3.安装必要插件:
vf install compat_aliases projects environment
其中 compat_aliases 插件的作用 是可以使用virtualenvwrapper 中的命令 来进行管理 virtualenv
4.安装完成之后 根据提示 执行 exec fish 命令 让其在 fish shell中生效
执行到这里之后 就可以用 virtualenvwrapper 中的命令 来控制 virtualenv 了 可以先创建一个虚拟环境 并 进入你创建的虚拟环境中
mkvirtualenv demo
workon demo
但是会提示:
Virtual environment activated but not shown in shell prompt. To fix, see:
<https://virtualfish.readthedocs.io/en/latest/install.html#customizing-your-fish-prompt>
解决办法:
5. 定制 fish_prompt 让fish shell 提示更加友好 生成用户指令配置文件
- 输入命令
funcsave fish_prompt
,然后会看到多了一个文件:~/.config/fish/functions/fish_prompt.fish
- 使用
vim
打开上面的文件,结束的end
后面, (最后一个echo
语句前面), 加上下面代码(之前看博客说是在switch
语句结束的end
后面 但是实际操作时 并没有找到 switch语句 所以直接就放在了 最后一个echo语句的前面 注意: 一定不能放到文件的最后 放到最后是不会生效的):
-
if set -q VIRTUAL_ENV echo -n -s (set_color -b blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " " end
- 保存退出
OK 大功告成