mac下使用HomeBrew更改python版本

早上突然发现自己mac环境下的python3.6创建的虚拟环境无法使用了,报下面的错误

/Users/icsoc/.virtualenvs/ctirandomdatatest/bin/python /Users/icsoc/work/code/bi-python/alert_check/check.py
dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/icsoc/.virtualenvs/ctirandomdatatest/bin/python
  Reason: image not found

查询python的版本为如下:

 >brew info python
python: stable 3.7.3 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.3 (8,466 files, 118.7MB) *
  Built from source on 2019-04-23 at 09:29:01
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✔, openssl ✔, readline ✔, sqlite ✔, xz ✔

发现可能是昨天使用HomeBrew时,误升级了python,HomeBrew默认都是安装python的最新版本的.
那么由于之前使用python3.6创建的虚拟环境比较多,如果要升级没一个虚拟环境的Lib包,还是比较麻烦的,所以网上查找资料发现先,mac可以实现多个python版本相互切换的,具体操作如下:
1.解除python3.7的绑定

brew unlink python

2.安装python3.6.5

brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
  1. 使用 brew switch 在不同版本的 python 间切换
brew switch python 3.7.2
brew switch python 3.6.5

你可能感兴趣的:(Python)