本文章主要内容为:

配置环境、安装库包等网上冲浪 时遇见到的各式各样奇奇怪怪的WarningError,以及各种治标不治本或者又治标又治本的解决方案全记录(个人向

请善用页面搜索功能对报错信息进行检索,事半功倍!😉

Git相关问题

Github关联仓库

fatal: Branch rename failed

Github官方给出如下的关联远程仓库的方法:

1
2
3
git remote add origin git@github.com:xxx/xxx.git
git branch -M main
git push -u origin main

事实上,在执行第一条命令之前,如果本地目录不是git项目的话,还要先执行如下命令:

1
git init

而在git branch -M main时还会报错,信息如下:

1
2
error: refname refs/heads/master not found
fatal: Branch rename failed[分支重命名失败]

原因是,GitHub 默认分支改名为了 main,而上述命令并没有事先在本地产生一个默认分支master

解决方法就是先addcommit一波,然后再进行改名。

参考:https://blog.csdn.net/weixin_39609665/article/details/111826113

fatal:拒绝合并无关的历史
  1. 首先将远程仓库和本地仓库关联起来:
1
git branch --set-upstream-to=origin/[master] [master]
  • [master]可以替换成任意自己的分支名称
  1. 然后使用git pull整合远程仓库和本地仓库 (忽略版本不同造成的影响)
1
git pull --allow-unrelated-histories   

通过SSH Key操作仓库

操作步骤

1.检查PC是否存在SSH Key

~/.ssh or ~/.ssh ls

  • 如果PC上没有,显示:-bash: /root/.ssh: No such file or directory[没有那个文件或目录]
  • 如果PC上,显示:-bash: /root/.ssh:Is a directory[是一个目录],跳转到Step3Step3

2.创建 SSH Key

输入命令

1
ssh-keygen -t rsa -C "Your email[你的邮箱]"

命令参数含义:

  • -t 指定密钥类型,默认是 rsa ,可以省略。
    -C 设置注释文字,比如邮箱。

回车之后再根据提示设置即可,为了避免麻烦,此处是3次回车(即默认设置且无密码)后显示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆[此处是你的key fingerprint]
The key's randomart image is:
+---[RSA 2048]----+
| ..o |
| . . . |
| E . |
| . . . |
| S + . . +|
| . o + oo==|
| .+ o *oB=+|
| .oo.=.#=+.|
| ++oXBB.+|
+----[SHA256]-----+

如果完成上述设置后,SSH KeySSH\ Key 就创建成功了,可以再次~/.ssh验证。

3.添加Key到Github

1
2
3
cd ~/.ssh
ls
more id_rsa.pub

进入ssh目录,并查看目录下文件,并打开需要使用的公钥id_rsa.pub

将内容复制到Github账号setting中对应的SSH处即可。

通过如下命令验证是否匹配成功

1
ssh -T git@github.com

回车之后显示:

1
2
3
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ECDSA key fingerprint is ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆[此处是你的key fingerprint]
Are you sure you want to continue connecting (yes/no)?

回复yes,接下来就会提示输入密码,如果上边设置ssh的时候,没设置密码会提示:

1
Warning: Permanently added ‘github.com,192.30.255.112’ (RSA) to the list of known hosts.

警告完了,如果能看到如下提示,那已经成功设置SSH密钥:

1
Hi xxx[你的用户名]! You’ve successfully authenticated, but GitHub does not provide shell access.

如果你看到 access denied,则表示拒绝访问。

参考

  1. Git教程 SSH keys配置|CSDN
  2. 官方文档|使用 SSH 连接到 GitHub

Close Issue

自动关闭issue

如果一个处于Open状态的Issue已经处理完毕,只要在该提交中以下列任意一种格式描述提交信息,对应的Issue就会被Close

  • fix #24
  • fixes #24
  • fixed #24
  • close #24
  • closes #24
  • closed #24
  • resolve #24
  • resolves #24
  • resolved #24

利用这个方法,每次提交并Push之后,就不必再大费周章地到GitHub的Issue中寻找相应的Issue手动Close,省去了不少麻烦

参考:GitHub中Issue的使用

Python环境

nltk.download下载报错

NLTK ERROR LOADING

通过nltk的下载函数进行依赖下载时,可能会遇到如下错误

1
2
3
4
5
6
7
>>> import nltk
>>> nltk.download('punkt')

[nltk_data] Error loading punkt: <urlopen error [Errno 111] Connection
[nltk_data] refused>

False

原因是下载语料库时连接到网页被拒绝

解决方法:

  1. 修改浏览器设置(目前测试无效,留档)

  2. 直接去对应项目地址下下载所需文件并放入对应路径,参考:离线加载nltk_data

    注意:需根据报错信息调整路径从而进行匹配

安装phantomjs

安装步骤

下载

phantomjs下载地址: http://phantomjs.org/download.html

安装

解压(此处版本用xxx代替)

1
tar -xvf phantomjs-xxxx.tar.bz2

将压缩结果移动到系统中软件存放目录

1
sudo mv phantomjsxxx  /usr/local/src/phantomjs

创建软连接到系统环境 以便能够使用phantomjs命令

1
sudo ln -sf  /usr/local/src/phantomjs/bin/phantomjs  /usr/local/bin/phantomjs

将软连接 添加执行的权限

1
sudo chmod u+x,o+x  /usr/local/bin/phantomjs

检验能否正常使用(返回版本信息就代表能正常使用)

1
phantomjs --version

参考

cannot open shared object file报错

具体报错消息:

1
phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file:

解决方法:

1
2
sudo apt-get install fontconfig #ubuntu
yum install freetype-devel fontconfig-devel #centOS
libssl_conf报错

具体报错消息:

1
2
3
4
5
Auto configuration failed
139950541100688:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libssl_conf.so): libssl_conf.so: cannot open shared object file: No such file or directory
139950541100688:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
139950541100688:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=ssl_conf, path=ssl_conf
139950541100688:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=ssl_conf

解决方法(针对 Linux系统)

1
export OPENSSL_CONF=/etc/ssl/

注:此方法是对ssl设置临时的配置,重启后不再生效

pip安装与升级问题

ImportError: No module named pip

解决方法:

1
2
sudo apt install python3-pip	# install pip3 for python3 
sudo apt install python-pip # install pip2 for python2
ImportError: cannot import name main

解决方法:

1
2
pip3 install pip -U		# 升级pip3
pip2 install pip -U # 升级pip2
libGL.so.1: cannot open shared object file

具体报错信息:

1
libGL.so.1: cannot open shared object file: No such file or directory

解决方法:

1
apt install libgl1-mesa-glx

Selenium+ChromeDriver安装

之前用Selenium+PhantomJS的方式进行爬虫处理,然而垃圾phantomjs早已不受待见,导致程序出现诸多bug,于是趁这次机会干脆直接上chrome算了。

首先,安装selenium很简单:

1
sudo pip3 install selenium

然后则是chrome了。

ChromeDriver安装

安装Chrome浏览器 已安装可跳过

安装Chrome浏览器

安装依赖

1
sudo apt-get install libxss1 libappindicator1 libindicator7

下载安装包

1
2
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 
#执行命令,下载稳定版Chrome浏览器

安装

1
2
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f

查看Chrome浏览器版本

1
google-chrome --version   #执行该命令获取当前Chrome浏览器版本号

下载对应版本chromedriver

1
wget -N http://chromedriver.storage.googleapis.com/浏览器版本号(比如88.0.4324.96)/chromedriver_linux64.zip

安装unzip,用于解压缩(可跳过)

1
sudo apt-get install unzip

解压缩

1
unzip chromedriver_linux64.zip

移动chromedriver位置

1
sudo mv chromedriver /usr/local/share/chromedriver

建立软链接
后续创建driver时就不需要再指定executable_path这个参数

1
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
DevToolsActivePort file doesn't exist

无头浏览器chrome的报错信息。

完整错误信息:

1
python unknown error: DevToolsActivePort file doesn't exist

解决方法:

1
2
3
4
5
6
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
browser = webdriver.Chrome(chrome_options=chrome_options)

Poetry安装|包依赖管理工具

安装

poetry提供多种安装方式,个人推荐从以下2种方式中选择:
方式一:(推荐)

1
$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

方式二:(pip)

1
$ pip install --user poetry
简单使用

工程初始化

如果当前还没有创建工程,可以使用poetry新建工程:

输入poetry new来创建一个项目脚手架,包括基本结构pyproject.toml文件。

1
$ poetry new poetry-demo

此后,会自动创建一个包含如下内容的工程:

1
2
3
4
5
6
7
8
poetry-demo
├── pyproject.toml
├── README.rst
├── poetry_demo
│ └── __init__.py
└── tests
├── __init__.py
└── test_poetry_demo.py

除了新建工程,还可以在已有工程的基础上进行创建,

1
$ poetry init

这时候,系统会要求输入包名称、版本号等信息,可以选择输入,也可以选择按下ENTER键使用默认值,完成以后,pyproject.toml如以下格式:

1
2
3
4
5
6
7
8
9
10
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = ["wenli"]

[tool.poetry.dependencies]
python = "*"

[tool.poetry.dev-dependencies]
pytest = "^3.4"

依赖包管理

安装依赖包

可以使用install命令直接解析并安装pyproject.toml依赖包

1
$ poetry install

pyproject.toml文件的配置如下:

1
2
[tool.poetry.dependencies]
pendulum = "^1.4"

也可以可以使用add命令来安装一款Python工具包,

1
$ poetry add numpy

还可以,通过添加配置参数--dev来区分不同环境下的依赖包。

1
2
3
4
5
poetry add flask # 安装最新稳定版本的flask  
poetry add pytest --dev # 指定为开发依赖,会写到pyproject.toml中的[tool.poetry.dev-dependencies] # 区域
poetry add flask=2.22.0 # 指定具体的版本
poetry install # 安装pyproject.toml文件中的全部依赖
poetry install --no-dev # 只安装非development环境的依赖,一般部署时使用
其他常用操作更新所有锁定版本的依赖包
1
$ poetry update
更新指定依赖包
1
$ poetry update numpy  
卸载依赖包
1
$ poetry remove numpy
查看可以更新的依赖
1
$ poetry show --outdated
查看项目安装的依赖
1
$ poetry show
树形结构查看项目安装的依赖
1
$ poetry show -t

参考

定时任务时区问题

ZoneInfoNotFoundError

C++ Error & Warning

declares a non-template function

C++面向对象编程时,如果直接对类模板进行运算符重载的友元函数声明时,直接使用template<class xxx>中的xxx会报错:

1
[Warning] friend declaration ‘此处是你定义的友元函数’ declares a non-template function [-Wnon-template-friend]

解决方法有两种。

  1. 将运算符重载函数在类内部实现,而不是在外部实现
  2. 在友元函数声明前定义一个和 type不同的模板参数U
1
2
3
4
5
6
7
8
9
10
template <class elementType>
class A{
//方法1
friend [返回值] operator ...([参数表]){
...
}
//方法2
template <class elementType2>
friend [返回值] operator ...([参数表]);
}
may not have default arguments

一句话解释

对于函数默认值的声明,只需要在定义的时候进行声明;在实现的时候不需要再写一遍

cpp中的实现并未被识别出来

关键词类模板

注意的是:类模板和普通的代码不同,不能用普通的方法实现头文件.h和源文件.cpp文件分离

解决方法

  1. #include "类名.cpp"
  2. 将实现也写在.h

杂项玄学

lsb_release returned non-zero错误

具体报错信息:

1
Command '('lsb_release', '-a')' returned non-zero exit status 1.

解决方法:

1
2
find / -name lsb_release
rm -rf /usr/bin/lsb_release

参考:CSDN博文一篇

Debian解决中文乱码

具体步骤

安装locales

1
apt-get install locales

设置语言选项

1
dpkg-reconfigure locales

选择中文相关字体

1
2
3
4
zh_CN GB2312
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
en_US.UTF-8 UTF-8

回车后,以zh_CN.UTF-8作为默认选项

查看语言设置

1
locale

确保LANG=zh_CN.UTF-8

若不是,执行export LANG=zh_CN.UTF-8 设置环境变量(仅仅是临时设置

连接IPv6 Server

IPv6服务器连接

访问 IPv6-test网站 测试当前设备网络是否支持IPv6

如果支持,可通过Xshellfinalshell等当前较好的软件进行SSH连接,QED.

否则,下面提供两种解决方案:

1. 通过VPN进行连接

对于Android用户,可以通过下载软件:1.1.1.1 VPN 并直接连接即可。可再次登录上面提到的ipv6-test.com进行验证。

其他用户待更

2. 让服务器支持IPv4

通过工具:IPv6 to IPv4 实现IP和端口的映射

安装VPN

VPN开通与使用

启动TUN/TAP

通过命令确保设备支持tun/tap并且没被禁用:

1
cat /dev/net/tun
  • 如果返回cat: /dev/net/tun: No such file or directory则说明已被禁用
  • 如果返回cat: /dev/net/tun: File descriptor in bad state则说明TUN/TAP已启动

获取域名(可跳过)

在Freenom中获得免费域名

暂略

CF绑定DNS

获取SSL/TLS客户端证书

使用 X-UI

通过命令进行X-UI的安装:

1
bash <(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)

如果出现如下的界面则说明成功安装并启用了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

x-ui 面板管理脚本
0. 退出脚本
————————————————
1. 安装 x-ui
2. 更新 x-ui
3. 卸载 x-ui
————————————————
4. 重置用户名密码
5. 重置面板设置
6. 设置面板端口
————————————————
7. 启动 x-ui
8. 停止 x-ui
9. 重启 x-ui
10. 查看 x-ui 状态
11. 查看 x-ui 日志
————————————————
12. 设置 x-ui 开机自启
13. 取消 x-ui 开机自启
————————————————
14. 一键安装 bbr (最新内核)

面板状态: 已运行
是否开机自启: 是
xray 状态: 运行

根据提示,我们可以在服务器IP地址下的54321端口加入管理面板,当然如果是IPv6则还需要将54321端口重新映射为IPv4才能访问。登录用户名和密码初始默认都是admin.

IPv4访问支持

通过在 IPv6 VPS 上 安装 WARP 实现 IPv4的访问支持

IPv4访问

通过如下命令检测服务器对网络的支持情况

1
curl -4 <website>

其中,-4表示测试IPv4<website>为任一网站,推荐设为ipinfo.io

如果提示curl: command not found说明当前系统没有安装curl,可通过如下命令|debian/ubuntu进行安装:

1
apt-get update -y && apt-get install curl -y

排除网络因素,如果确认不支持IPv4,继续。

在终端中运行如下命令以下载WARP工具包

1
wget -N https://jsd.onmicrosoft.cn/gh/fscarmen/warp/menu.sh && bash menu.sh

(注意,WARP的使用需要TUN的支持,TUN的相关说明见本文章其他部分)

工具包提供中文支持,按照提示操作即可

Hexo博客踩坑

主题配置文件不生效

如果在博客根目录通过_config.butterfly.yml文件进行修改,可能并不会生效

不生效时手动到theme/butterfly/_config.yml里作同样的修改

例如,对于导航栏的顺序在外面修改并不会生效