Homebrew + venv 虚拟环境安装SCIP
1、安装homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
会默认Downloading Command Line Tools for Xcode
但是最后会
fatal: unable to access 'https://github.com/Homebrew/brew/': Failed to connect to github.com port 443 after 75013 ms: Couldn't connect to server Warning: Trying again in 2 seconds: /usr/bin/git fetch --quiet --progress --force origin fatal: unable to access 'https://github.com/Homebrew/brew/': Failed to connect to github.com port 443 after 75007 ms: Couldn't connect to server
所以用镜像站安装 Homebrew(不依赖 GitHub),切换清华源,来安装brew
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git ~/homebrew echo 'eval "$(/Users/$(whoami)/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/Users/$(whoami)/homebrew/bin/brew shellenv)"
然后测试
brew --version
显示 Homebrew 4.6.0-16-g98384bb
2、创建虚拟环境
python3 -m venv pyomo_env
python本身 不会自动管理所有虚拟环境的列表,虚拟环境就是一个 独立目录:(1)就在当前目录下看有多少个;(2)pycharm能识别多个环境
没有指定路径时,虚拟环境目录就会被创建在你当时所在的“当前工作目录”中,我的是 /Users/didi
进入并激活虚拟环境
source pyomo_env/bin/activate
它会:
-
修改你的终端环境变量
-
把当前的 Python 和 pip 都切换成虚拟环境中的版本
此时你可以看到终端前缀会变成这样:
这表示你已经「激活」了名为 pyomo_env
的虚拟环境。
📌 激活后你才能做的事:
-
用
pip install
安装包时,只会装到pyomo_env
里 -
运行的
python
是虚拟环境里的,不是系统的 Python -
所有 Pyomo、SCIP、Matplotlib、Pandas……等包都能按需管理、随时删掉不影响全局
🚪退出虚拟环境
如果你以后不想用了,运行:
即可退出虚拟环境,回到系统默认 Python。
3、安装pyomo
pip install --upgrade pip pip install pyomo
还需要安装其他包
4、使用homebrew安装scip
brew install scip
一直会报错
curl: (28) Failed to connect to github.com port 443 after 75008 ms: Couldn't connect to server Warning: Problem : timeout. Will retry in 1 seconds. 3 retries left. curl: (28) Failed to connect to github.com port 443 after 75020 ms: Couldn't connect to server # # ## Warning: Problem : timeout. Will retry in 2 seconds. 2 retries left. curl: (28) Failed to connect to github.com port 443 after 75018 ms: Couldn't connect to server # # # Warning: Problem : timeout. Will retry in 4 seconds. 1 retries left. curl: (28) Failed to connect to github.com port 443 after 75013 ms: Couldn't connect to server Error: scip: Failed to download resource "9ac89e9936b826c13e90611cb9a81a7aa0508d20.patch?full_index=1" Download failed: https://github.com/boostorg/range/commit/9ac89e9936b826c13e90611cb9a81a7aa0508d20.patch?full_index=1 ==> No outdated dependents to upgrade!
主要原因是:当前网络环境无法连接 GitHub,而我通过chrome是能访问Github的。
主要原因是:浏览器和终端走的网络路径不一样,因此我们需要让终端的流量也走代理,即可正常安装(clashX都是如下IP)
export http_proxy=http://127.0.0.1:7890 export https_proxy=http://127.0.0.1:7890 brew install scip
确认安装路径
which scip
在当前虚拟环境中
scip --version 能看到版本
确认能运行:
你会进入交互模式(输入 quit
可退出)。