BigSur 安装nut记录

2022-09-19 14:52:55 浏览数 (1)

Nut 是Tinfoil用于USB连接和网络连接至服务器的应用程序,Windows可以直接下载exe程序,但是对于Mac或Linux,需要对源码编译,虽然官方给出了步骤和教程,但是过程中充满了“艰辛”,这里坐下相关记录和踩坑手册。

Pyenv和 virtualenv

这一步虽然不是必须的,但是创建一个虚拟的python环境,可以有效避免了不同Python程序间的互相影响。

这里安装官方的建议,使用 pyenv pyenv-virtualenv 。

安装Pyenv

代码语言:javascript复制
brew install pyenv pyenv-virtualenv

这里遇到的第一个问题是,brew update的时候报错,报错信息如下:

代码语言:javascript复制
Error: 
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
These commands may take a few minutes to run due to the large size of the repositories.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!

解决时本来很简单,只需按上述提示执行相应命令即可:

代码语言:javascript复制
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow

但是默认关联 git 仓库是国外的,速度慢,还经常被墙,导致 early EOF 之类的错误

因此,这里换源,临时将该仓库临时源设置为国内的镜像。一般使用中科大的:

代码语言:javascript复制
## 更新 homebrew-cask
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask

# 更换源
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

# 更新,由于已经 cd 到相应文件夹了,因此不需要通过 -C 指定路径了
git fetch --unshallow 

## 更新 homebrew-core
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-core

# 更换源
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 更新
git fetch --unshallow 

如果有问题,可以通过如下命令查看远端 repo 是不是设置错了。

代码语言:javascript复制
git remote -v 

如果错了,可以重新设置远端,然后强制更新:

代码语言:javascript复制
git fetch --all
git reset --hard origin/master 
git pull

最后 brew update 即可。

创建虚拟环境

官方文档中只用简单的一句话创建和启用(pyenv virtualenv nut && source activate nut),但是我在创建这一步,就遇到了问题。因为我mac中的python有2.73.8两个版本,且默认是2.7,所以当直接用pyenv创建虚拟环境,用的是2.7版本的,nut要求3.6 , 因此需要先安装使用pyenv install安装3.8的python。

但是当执行pyenv install 3.8时,又会报错:

代码语言:javascript复制
BUILD FAILED (OS X 10.16 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/sl/5j1zvmtj0gb8qpgkklkf38dh0000gr/T/python-build.20200626170507.14625
Results logged to /var/folders/sl/5j1zvmtj0gb8qpgkklkf38dh0000gr/T/python-build.20200626170507.14625.log

Last 10 log lines:
./Modules/posixmodule.c:9141:12: note: forward declaration of 'struct sf_hdtr'
    struct sf_hdtr sf;
           ^
./Modules/posixmodule.c:9221:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
              ^
2 errors generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.

为了解决这个问题,找了很多资料,都没能成功,最终使用以下方法成功安装,感谢@PritamDutt

代码语言:javascript复制
% CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" 
pyenv install --patch 3.8.0 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch?full_index=1)

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Installing Python-3.8.0...
patching file Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst
patching file configure
Hunk #1 succeeded at 3394 (offset -32 lines).
patching file configure.ac
Hunk #1 succeeded at 498 (offset -12 lines).
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.0 to /Users/pritam/.pyenv/versions/3.8.0

% CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" 
pyenv install --patch 3.8.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch?full_index=1)

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.3.tar.xz...
-> https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
Installing Python-3.8.3...
patching file Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst
patching file configure
Hunk #1 succeeded at 3398 (offset -28 lines).
patching file configure.ac
Hunk #1 succeeded at 498 (offset -12 lines).
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.3 to /Users/pritam/.pyenv/versions/3.8.3

% pyenv versions
* system (set by /Users/pritam/.pyenv/version)
  3.6.8
  3.6.9
  3.8.0
  3.8.3

激活虚拟环境

原以为创建好之后就大功告成,但是发现激活时,再次报错

代码语言:javascript复制
Failed to activate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

主要原因是没有初始化,执行以下命令后,再次激活即可

代码语言:javascript复制
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

clone nut并安装依赖

根据官方的步骤:

  • install all other dependencies (pip install -r requirements.txt)
  • Run python nut_gui.py to launch the application

接下来安装依赖即可,但是在安装依赖的pyqt5,再次报错,谷歌之后发现该包要求pip版本大于19.3, 而我的版本是19.23, 然后发现使用pip install upgrade pip无论如何都没办法把虚拟环境的pip给升级了。

即使提示Successfully installed 21.xx,但使用pip -V查看,还是老版本。

查阅资料,发现,使用以下两句,可以更新虚拟环境的pip

代码语言:javascript复制
pip install --user -U pip

python -m pip install --upgrade pip

运行代码

安装好依赖后,执行以下代码即可运行程序

代码语言:javascript复制
python nut_gui.py

参考

  1. brew update 更新时 shallow clone
  2. Failed to activate virtualenv with pyenv
  3. python 虚拟环境中更新 pip,解决 PermissionError 问题

0 人点赞