Git克隆连接超时,执行依赖安装脚本遇问题求助
解决Git连接GitHub超时问题
错误信息
Installing https://raw.githubusercontent.com/torch/rocks/master/cwrap-scm-1.rockspec... Using https://raw.githubusercontent.com/torch/rocks/master/cwrap-scm-1.rockspec... switching to 'build' mode Cloning into 'cwrap'... fatal: unable to connect to github.com: github.com[0: 140.82.121.3]: errno=Connection timed out
可行解决方案
切换Git克隆协议
若脚本中使用SSH协议克隆仓库,手动替换为HTTPS格式(如将git@github.com:xxx/xxx.git改为https://github.com/xxx/xxx.git);反之,若用HTTPS超时,尝试换成SSH协议。配置Git代理(针对需代理的网络环境)
执行以下命令设置代理:# 设置HTTP代理 git config --global http.proxy http://你的代理地址:端口 # 设置HTTPS代理 git config --global https.proxy https://你的代理地址:端口无需代理时,取消配置:
git config --global --unset http.proxy git config --global --unset https.proxy手动绑定GitHub DNS解析
- 查询github.com的可用IP(通过DNS查询工具获取最新有效地址)
- 修改hosts文件:
- Linux/macOS:执行
sudo nano /etc/hosts - Windows:以管理员权限打开
C:\Windows\System32\drivers\etc\hosts
- Linux/macOS:执行
- 添加一行(替换为你查到的IP):
140.82.121.3 github.com - 刷新DNS缓存:
- Linux:
sudo systemctl restart nscd(不同发行版操作可能有差异) - macOS:
sudo dscacheutil -flushcache - Windows:
ipconfig /flushdns
- Linux:
手动克隆依赖后再运行脚本
先手动克隆所需的cwrap仓库到脚本预期的路径:git clone https://github.com/torch/cwrap.git完成后再重新执行安装脚本。
内容的提问来源于stack exchange,提问作者Oliver Robinson
相关产品推荐
相关产品推荐

