当前位置:   article > 正文

Linux下C++与Python软件开发工具与环境相关踩坑记录_libasound2-plugins : depends: libavcodec59 (>= 7:5

libasound2-plugins : depends: libavcodec59 (>= 7:5.0) but it is not installa

目录

【bash】

【cmake】

【Doxygen】

【gcc】

【git】

【librosa】

【python】

python

bandmat

PyYAML

PyAudio

SoundFile

nltk

【Anaconda】

【SPTK】

【Valgrind】

【Visual Studio Code】

【Ubuntu】

【apt-get】

【CentOS】

【yum】

yum

FFmpeg

libasound-dev

libav-dev



【bash】

Q:
在脚本中通过export设置了环境变量,退出脚本后该环境变量失效

A:

这是跟执行脚本的方式有关的。一般shell 执行一个脚本时是创建了一个子进程并在子进程中执行命令的。父进程的变量可以共享给子进程,但反过来则不可行。当脚本执行完后会退出子进程,所以在脚本中设置的环境变量在退出脚本后已经失效了。

其实,shell有4种执行方式:

1. 文件有可执行权限,且文件头指定了解释器 (如 #!/bin/bash )时,通过 ./ + shell 脚本,或者 绝对路径 + shell 脚本 执行。这是最常见的方式。
2. 文件无可执行权限,或文件头未指定了解释器,通过 bash + shell 脚本。

前两种方法都会创建子进程并在子进程中执行

3. . +  shell 脚本
4. source + shell 脚本

.  filename [arguments]
source filename [arguments]
Read  and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.

后两种方式不会创建子进程,而是将脚本中的内容一行行读出来在当前环境中执行。所以通过这两种方式脚本文件中配置的环境变量对当前登录的终端都有效。这也是 ~/.bash_login  ~/.bashrc  ~/.bash_profile 这些配置文件的运行方式。


【cmake】

Q:
Ubuntu 16.04.6 LTS 下将cmake升级到最新版 cmake 3.15 时报错

  1. Install the project...
  2. bin/cmake: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by bin/cmake)
  3. make: *** [Makefile:74: install] Error 1

A:
由于 Ubuntu 软件库没有及时更新,通过 apt 找不到需要的 cmake 版本,考虑源码安装

  1. wget https://github.com/Kitware/CMake/releases/download/v3.15.0-rc1/cmake-3.15.0-rc1.tar.gz
  2. tar -zxf cmake-3.15.0-rc1.tar.gz
  3. cd cmake-3.15.0-rc1/
  4. ./configure --prefix=[TARGET_DIR]
  5. make
  6. make install

最后一步出错了

查看glib库版本,确实不支持 GLIBCXX_3.4.22

  1. $ strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
  2. GLIBCXX_3.4
  3. GLIBCXX_3.4.1
  4. GLIBCXX_3.4.2
  5. GLIBCXX_3.4.3
  6. GLIBCXX_3.4.4
  7. GLIBCXX_3.4.5
  8. GLIBCXX_3.4.6
  9. GLIBCXX_3.4.7
  10. GLIBCXX_3.4.8
  11. GLIBCXX_3.4.9
  12. GLIBCXX_3.4.10
  13. GLIBCXX_3.4.11
  14. GLIBCXX_3.4.12
  15. GLIBCXX_3.4.13
  16. GLIBCXX_3.4.14
  17. GLIBCXX_3.4.15
  18. GLIBCXX_3.4.16
  19. GLIBCXX_3.4.17
  20. GLIBCXX_3.4.18
  21. GLIBCXX_3.4.19
  22. GLIBCXX_3.4.20
  23. GLIBCXX_3.4.21
  24. GLIBCXX_DEBUG_MESSAGE_LENGTH

考虑升级glib库。升级方法有多种,这里选了最直接的一种:下载对应的lib文件进行替换(这个方法可能会涉及到一些兼容性问题,请慎用)
从 https://packages.debian.org/search?keywords=lib64stdc%2B%2B6 查询并下载对应的软件包,解压、替换即可

  1. wget http://ftp.cn.debian.org/debian/pool/main/g/gcc-8/lib64stdc++6_8.3.0-7_i386.deb
  2. ar -x lib64stdc++6_8.3.0-7_i386.deb
  3. tar xvJf data.tar.xz

成功会显示有以下文件,用以下命令确认一下
usr/lib64/libstdc++.so.6.0.25

strings usr/lib64/libstdc++.so.6.0.25 | grep GLIBCXX

确认支持 GLIBCXX_3.4.22 后替换原来的 libstdc++.so.6 文件

  1. cp usr/lib64/libstdc++.so.6.0.25 /usr/lib/x86_64-linux-gnu
  2. rm libstdc++.so.6
  3. ln -s libstdc++.so.6.0.25 libstdc++.so.6

 再回去 cmake 编译目录下执行 make install,成功~

  1. $ cmake --version
  2. cmake version 3.15.0-rc1

---------------------------------------------------------

2019.11.07补充:

以上安装方式在使用中可能会碰到以下错误:即使用cmake默认的curl下载第三方资源时可能不支持"https"协议

  1. CMake Error at protobuf-stamp/download-protobuf.cmake:159 (message):
  2. Each download failed!
  3. error: downloading 'https://cnbj1.fds.api.xiaomi.com/mace/third-party/protobuf/protobuf-3.6.1.zip' failed
  4. status_code: 1
  5. status_string: "Unsupported protocol"
  6. log:
  7. --- LOG BEGIN ---
  8. Protocol "https" not supported or disabled in libcurl
  9. Closing connection -1

解决方法:

step 01: 先看自己的curl是否支持"https",以下是不支持的情况

  1. $ curl --version
  2. curl 7.67.0 (x86_64-pc-linux-gnu) libcurl/7.67.0 zlib/1.2.8
  3. Release-Date: 2019-11-06
  4. Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp
  5. Features: AsynchDNS IPv6 Largefile libz UnixSockets

这时需要先安装ssl再重新安装curl,操作如下

  1. sudo apt-get install openssl libssl-dev
  2. wget https://curl.haxx.se/download/curl-7.67.0.tar.gz
  3. tar -zxf curl-7.67.0.tar.gz
  4. cd curl-7.67.0
  5. ./configure --with-ssl --with-libssl-prefix=/usr/local/ssl
  6. make
  7. sudo make install
  8. sudo ldconfig

ldconfig 的作用是更新 libcurl 的链接(参考https://man.linuxde.net/ldconfig)因为 cmake 实际使用的是 libcurl 而不是 curl。重新查看 curl 是否支持"https",发现已经有了。

  1. $ curl --version
  2. curl 7.67.0 (x86_64-pc-linux-gnu) libcurl/7.67.0 OpenSSL/1.0.2g zlib/1.2.8
  3. Release-Date: 2019-11-06
  4. Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
  5. Features: AsynchDNS HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets

step 02: curl的问题解决后就是重新编译 cmake,唯一不同的是编译前多了一个配置项

  1. cd cmake-3.15.0-rc1/
  2. ./bootstrap --system-curl --prefix=[TARGET_DIR]
  3. make
  4. make install

答案来自 Protocol "https" not supported or disabled in libcurl · Issue #15 · ethz-asl/gflags_catkin · GitHub,感谢贡献者!

---------------------------------------------------------

Q:
通过以上方式安装cmake时可能出现以下错误
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
CMake Error at CMakeLists.txt:398 (message):
  CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!

A:
安装zlib即可,注意安装包名称
sudo apt-get install zlib1g-dev
 


Q:
64位机器上gcc编译32位程序时报错,比如编译安装HTK时会有如下错误

/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory

A:
是因为gcc默认不支持32位链接库,安装上即可
Ubuntu安装方法

  1. sudo apt-get install build-essential module-assistant
  2. sudo apt-get install gcc-multilib g++-multilib

CentOS安装方法

yum install glibc-devel.i686 libstdc++-devel.i686

Doxygen

Q:
第一次用doxygen产生文档就遇到问题

  1. writing tag file...
  2. Running dot...
  3. sh: 1: dot: not found
  4. error: Problems running dot: exit code=127, command='dot', arguments=...

A:
当然解决也很简单

  1. The program 'dot' is currently not installed. You can install it by typing:
  2. sudo apt install graphviz

【gcc】

Q:
CentOS 7 下如何安装g++?

A:
Linux直接安装gcc的版本截止目前(2019年12月)仍然是4.8.5。但是CentOS 7下通过以下命令安装g++报错

  1. # yum install g++
  2. Loaded plugins: fastestmirror, langpacks, priorities
  3. Loading mirror speeds from cached hostfile
  4. * elrepo: mirrors.tuna.tsinghua.edu.cn
  5. * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
  6. * elrepo-testing: mirrors.tuna.tsinghua.edu.cn
  7. * epel: mirrors.aliyun.com
  8. No package g++ available.
  9. Error: Nothing to do

改成 gcc-c++ 就好了

  1. # yum install gcc-c++
  2. Installed:
  3. gcc-c++.x86_64 0:4.8.5-39.el7
  4. Complete!
  5. # g++ --version
  6. g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

Q:
CentOS 7 下怎样将 gcc 从 4.8.5 升级到 7.4.0?

A:
不管是CentOS还是Ubuntu,升级 gcc 用  yum update 或 apt-get update 都不管用,一般是自己下载安装包,或者源码编译。

英文OK的童鞋直接读 InstallingGCC - GCC Wiki 吧,这里结合这篇文章写自己的经验,供着急的童鞋参考。

step01 下载源码。不想用 7.4.0 版本的话可以去 Index of /gnu/gcc 选。

  1. wget http://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz
  2. tar -zxf gcc-7.4.0.tar.gz

step02 安装依赖包。gcc依赖GMP,MPFR,MPC和ISL(可选)
Ubuntu下

apt-get install libgmp-dev libmpfr-dev libmpc-dev

CentOS下

yum install gmp-devel mpfr-devel libmpc-devel

或者下载编译

  1. cd gcc-7.4.0
  2. ./contrib/download_prerequisites

step03 编译。文章建议在outside the source directory编译,所以先在 gcc-7.4.0外建立build进行编译。

  1. mkdir build
  2. cd build
  3. ../gcc-7.4.0/configure --prefix=/home/soft --disable-multilib
  4. make -j
  5. sudo make install

其中 --prefix 选项可以指定安装路径,默认为 /usr;--disable-multilib 选项指定不同时支持32位(-m32)和64位,如果 configure 报以下错误可以将这个选项加上。编译过程比较漫长,建议用 make -j 并行编译。

  1. /bin/ld: cannot find crt1.o: No such file or directory
  2. /bin/ld: cannot find crti.o: No such file or directory
  3. /bin/ld: cannot find -lc
  4. /bin/ld: cannot find crtn.o: No such file or directory
  5. collect2: error: ld returned 1 exit status
  6. configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

Q:
Ubuntu 18.04 下怎样将 gcc 从 7.4.0 降级到 4.8.5?

A:
Ubuntu 18.04的默认gcc已经是7.4了,但有些场合下必须使用较低版本的编译器,考虑降级,或者让新老版本同时存在。
首先安装老版本

  1. sudo apt-get install gcc-4.8 g++-4.8
  2. # 如果需要进行交叉编译
  3. sudo apt-get install gcc-4.8 gcc-4.8-multilib g++-4.8 g++-4.8-multilib

安装好了并不会直接生效,用 gcc --version 查看仍然是7.4.0版
注意到gcc和g++实际都是链接文件,可以看到它们都指向了具体的版本

  1. ls -lh /usr/bin/g{cc,++}*
  2. /usr/bin/g++ -> /etc/alternatives/g++
  3. /usr/bin/g++-4.8
  4. /usr/bin/g++-7 -> x86_64-linux-gnu-g++-7
  5. /usr/bin/gcc -> /etc/alternatives/gcc
  6. /usr/bin/gcc-4.8
  7. /usr/bin/gcc-7 -> x86_64-linux-gnu-gcc-7
  8. /usr/bin/gcc-ar -> gcc-ar-7
  9. /usr/bin/gcc-ar-4.8
  10. /usr/bin/gcc-ar-7 -> x86_64-linux-gnu-gcc-ar-7
  11. /usr/bin/gcc-nm -> gcc-nm-7
  12. /usr/bin/gcc-nm-4.8
  13. /usr/bin/gcc-nm-7 -> x86_64-linux-gnu-gcc-nm-7
  14. /usr/bin/gcc-ranlib -> gcc-ranlib-7
  15. /usr/bin/gcc-ranlib-4.8
  16. /usr/bin/gcc-ranlib-7 -> x86_64-linux-gnu-gcc-ranlib-7

这时候需要通过update-alternatives命令来切换软件版本
它的几个常用命令如下:
1. 显示关于 <名称> 替换组的信息。
update-alternatives --display <名称>

  1. sudo update-alternatives --display gcc
  2. update-alternatives: error: no alternatives for gcc

说明还没有为 gcc 建立链接符
2. 系统中加入一组候选项。
update-alternatives --install <链接> <名称> <路径> <优先级>

  1. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
  2. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 40

优先级是一个整数,应该是越大优先级越高吧
3. 从 <名称> 替换组中去除 <路径> 项。
update-alternatives --remove <名称> <路径>

# sudo update-alternatives --remove gcc /usr/bin/gcc-4.8

4. 从替换组中选择版本
update-alternatives --config <名称>

  1. sudo update-alternatives --config gcc
  2. 有 2 个候选项可用于替换 gcc (提供 /usr/bin/gcc)。
  3.   选择       路径            优先级  状态
  4. ------------------------------------------------------------
  5. * 0            /usr/bin/gcc-4.8   50        自动模式
  6.   1            /usr/bin/gcc-4.8   50        手动模式
  7.   2            /usr/bin/gcc-7     40        手动模式

选择默认或1,再用gcc --version查看,版本已经变成4.8.5了
然后用同样的方法配置g++即可


【git】

Q:
git clone 时报以下错误

  1. remote: Enumerating objects: 52289, done.
  2. remote: Counting objects: 100% (52289/52289), done.
  3. remote: Compressing objects: 100% (32579/32579), done.
  4. error: RPC failed; curl 18 transfer closed with outstanding read data remaining
  5. fatal: the remote end hung up unexpectedly
  6. fatal: early EOF
  7. fatal: index-pack failed

A:

参考 https://www.cnblogs.com/zjfjava/p/10392150.html 解决了问题
原因1:缓存区溢出
解决方法:命令行输入

git config http.postBuffer 524288000

表示设置缓冲区为500MB,完了可以用 git config --list 确认一下

执行上面命令如果依旧clone失败,考虑可能原因2:网络下载速度缓慢
解决方法:命令行输入

  1. git config --global http.lowSpeedLimit 0
  2. git config --global http.lowSpeedTime 999999

如果依旧clone失败,则首先浅层clone,然后更新远程库到本地

  1. git clone --depth=1 http://xxx.git
  2. git fetch --unshallow

【librosa】

Q:
调用librosa时遇到 No module named 'numba.decorators' 错

  1.   File "/home/tanxj/local/anaconda3/envs/py36_tf1.15/lib/python3.6/site-packages/librosa/util/decorators.py", line 9, in <module>
  2.     from numba.decorators import jit as optional_jit
  3. ModuleNotFoundError: No module named 'numba.decorators'

A:
是因为librosa和numba版本不匹配导致的,将librosa升级到版本0.8以上可解决
如果不能升级高版本,尝试了 numba==0.49.1 librosa==0.6.3 这组也work。
 


【python】

python

Q:
Ubuntu 16.04.6 LTS 下将 python3 从 python3.5 升级到 python3.6 后出现 pip3 使用异常

A:
错误1:
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

解决方法:
修改 /usr/bin/pip3 文件

sudo vi /usr/bin/pip3

将原来的

from pip import main

修改为

from pip._internal import main

错误2:
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

解决方法:
删除并重新安装 python-apt

  1. sudo apt-get remove --purge python-apt
  2. sudo apt-get install python-apt

复制 python3.5 的 apt-pkg*.so 为 python3.6 的apt-pkg*.so

  1. cd /usr/lib/python3/dist-packages/
  2. sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so

Q:

pip install 卡在 Installing build dependencies 处

  1. # pip install pyworld
  2. Collecting pyworld
  3. Downloading pyworld-0.3.0.tar.gz (212 kB)
  4. |████████████████████████████████| 212 kB 19 kB/s
  5. Installing build dependencies ...

A:

  1. # pip install --pre --extra-index https://pypi.tuna.tsinghua.edu.cn/simple pyworld
  2. Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple, https://pypi.tuna.tsinghua.edu.cn/simple
  3. Collecting pyworld
  4. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/88/0b/9f8ceb7548bbb1294729b291044b8e72754db21dbc672acbd5eec6ed740b/pyworld-0.3.0.tar.gz (212 kB)
  5. Installing build dependencies ... done
  6. Getting requirements to build wheel ... done
  7. Preparing metadata (pyproject.toml) ... done
  8. ......
  9. Successfully built pyworld
  10. Installing collected packages: cython, pyworld
  11. Successfully installed cython-3.0.0a11 pyworld-0.3.0

Q:
pip install TimeoutError: The read operation timed out

A:
方法一:设置超时时间

pip install --default-timeout=200 -r requirements.txt

方法二:换国内镜像

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

bandmat

Q:
安装 bandmat 报错

  1. bandmat/core.c: In function ‘__Pyx_ExceptionSave’:
  2. bandmat/core.c:15606:19: error: ‘PyThreadState’ has no member named ‘exc_type
  3. *type = tstate->exc_type;
  4. ^
  5. bandmat/core.c:15607:20: error: ‘PyThreadState’ has no member named ‘exc_value
  6. *value = tstate->exc_value;
  7. ^
  8. bandmat/core.c:15608:17: error: ‘PyThreadState’ has no member named ‘exc_traceback’
  9. *tb = tstate->exc_traceback;
  10. ^

A:
这个错一般是 cython 引起的,可以尝试先安装 cython

pip install cython

如果是 python 3.7以上版本,依然无法解决。参考MattShannon/bandmat/issues/10

解决方法:

退回到 python 3.6,或者等待作者更新
如果是 conda 环境,·conda install bandmat· 目前不会成功,可以直接下载源码安装
将源码下载到除安装目录外的地方(默认安装目录为 python3.6/site-packages/)
解压后可以看到里面有 setup.py 文件

python setup.py install

PyYAML

Q:
安装PyYAML失败先是执行程序遇到以下报错

  1.   File "/home/tanxingjun/usr/anaconda3/lib/python3.6/site-packages/keras/engine/network.py", line 9, in <module>
  2.     import yaml
  3. ModuleNotFoundError: No module named 'yaml'

按照惯例用pip安装yaml包

pip install yaml

但却报以下错

  1. Collecting yaml
  2.   ERROR: Could not find a version that satisfies the requirement yaml (from versions: none)
  3. ERROR: No matching distribution found for yaml

百度了一下,有人说python 3.x 要装 pyyaml 而非 yaml,于是

pip install pyyaml

然后显示已安装了。但是 import yaml 仍然失败

Requirement already satisfied: pyyaml in /home/tanxingjun/usr/anaconda3/lib/python3.6/site-packages (5.1)

又百度了一下,有人说 conda 安装能成功,于是

conda install pyyaml

然而又遇到以下报错,大概是说 conda 依赖了 ruamel_yaml,而装 pyyaml 需要先卸载它(顺带把conda也卸载了)

  1. Verifying transaction: failed
  2. RemoveError: 'ruamel_yaml' is a dependency of conda and cannot be removed from
  3. conda's operating environment.

这下就陷入僵局了,各种百度无果

A:
最终解决方法:
不经意发现pip安装包目录(site-packages)下有个叫 PyYAML-5.1-py3.6.egg-info 的文件,正常来说它不应该是一个目录吗?
再一看这还是一个空文件,估计是什么时候安装或卸载失败的残留文件,但它会让 pip 安装时显示这个包已安装
果断删除,重新 pip install pyyaml ,一切顺利了,问题解决


PyAudio

Q:
pip安装PyAudio报错

  1. Building wheels for collected packages: PyAudio
  2.   Building wheel for PyAudio (setup.py) ... error
  3.   ERROR: Command errored out with exit status 1:
  4.   ......
  5.   src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
  6.    #include "portaudio.h"
  7.             ^~~~~~~~~~~~~
  8.   compilation terminated.
  9.   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  10.   ----------------------------------------
  11.   ERROR: Failed building wheel for PyAudio
  12.   Running setup.py clean for PyAudio
  13. Failed to build PyAudio
  14. Installing collected packages: PyAudio
  15.     Running setup.py install for PyAudio ... error
  16.     ERROR: Command errored out with exit status 1:

A:
在Mac OS X或Ubuntu上需要先安装依赖项,见官网说明

  1. # Mac OS X
  2. brew install portaudio
  3. pip install pyaudio
  4. # Ubuntu
  5. sudo apt-get install python-pyaudio python3-pyaudio
  6. pip install pyaudio

SoundFile

Q:

  1.   File "/usr/local/lib/python3.6/dist-packages/librosa/core/audio.py", line 8, in <module>
  2.     import soundfile as sf
  3.   File "/usr/local/lib/python3.6/dist-packages/soundfile.py", line 142, in <module>
  4.     raise OSError('sndfile library not found')
  5. OSError: sndfile library not found

A:
有时候是没有安装SoundFile包

pip install SoundFile

有时候安装上了还是报这个错,官网说明:On Linux, you need to install libsndfile using your distribution’s package manager
安装上依赖包就好了

sudo apt-get install libsndfile1

nltk

Q:

  1. File "/usr/local/lib/python3.7/dist-packages/g2p_en/g2p.py", line 22, in <module>
  2. nltk.data.find('taggers/averaged_perceptron_tagger.zip')
  3. File "/usr/local/lib/python3.7/dist-packages/nltk/data.py", line 542, in find
  4. return ZipFilePathPointer(p, zipentry)
  5. File "/usr/local/lib/python3.7/dist-packages/nltk/compat.py", line 41, in _decorator
  6. return init_func(*args, **kwargs)
  7. File "/usr/local/lib/python3.7/dist-packages/nltk/data.py", line 394, in __init__
  8. zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
  9. File "/usr/local/lib/python3.7/dist-packages/nltk/compat.py", line 41, in _decorator
  10. return init_func(*args, **kwargs)
  11. File "/usr/local/lib/python3.7/dist-packages/nltk/data.py", line 934, in __init__
  12. zipfile.ZipFile.__init__(self, filename)
  13. File "/usr/lib/python3.7/zipfile.py", line 1225, in __init__
  14. self._RealGetContents()
  15. File "/usr/lib/python3.7/zipfile.py", line 1292, in _RealGetContents
  16. raise BadZipFile("File is not a zip file")
  17. zipfile.BadZipFile: File is not a zip file

A:

可能是averaged_perceptron_tagger包没下载,可以到路径~/nltk_data/taggers下去确认。下载方法:

  1. # python
  2. Python 3.7.5 (default, Nov 7 2019, 10:50:52)
  3. [GCC 8.3.0] on linux
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import nltk
  6. >>> nltk.download("averaged_perceptron_tagger")
  7. [nltk_data] Downloading package averaged_perceptron_tagger to
  8. [nltk_data] /root/nltk_data...
  9. [nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.

【Anaconda】

Q:
使用Anaconda搭建python+tensorflow开发环境

A:
虽然已经搭过多次,但还是偶尔掉坑,所以记下来最好
python、tensorflow、gcc、cuda 的版本选择,参照https://www.tensorflow.org/install/source#linux
Anaconda | Anaconda Distribution下载并安装好anaconda后默认进入(base)环境
以下为一些常用命令
创建新环境
conda create -n py36_tf-1.13 python=3.6 tensorflow=1.13          # 仅用CPU
conda create -n py36_tf-gpu-1.13 python=3.6 tensorflow-gpu=1.13  # 使用GPU
查看所有环境
conda info --envs
切换环境
conda activate py36_tf-1.13
退回到(base)环境
conda deactivate
不希望一登录就自动切换到coda (base)环境
conda config --set auto_activate_base false
删了环境
conda remove -n py36_tf-1.13 --all
查看conda源
conda config --show channels
查看各个包的源
conda list --show-channel-urls
增加源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --append channels conda-forge
删除源
conda config --remove channels conda-forge

Q:
使用Anaconda搭建python+pytorch开发环境

A:
第一步:创建新环境。只需要指定python版本即可
conda create -n py3.10-pt2.0-cuda11.8 python=3.10
第二步:进入新环境,并通过conda安装pytorch包
conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia
这一串不用自己写,去pytorch官网上copy就好了:最新版本历史版本

Q:
Anaconda的国内镜像

A:
如果从外网下载很慢可能出现以下错误

'Connection broken: OSError("(104, \'ECONNRESET\')")'

改成国内镜像就好了,参考anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror, 把内容复制到~/.condarc就好了
 

Q: Anaconda和Python的对照关系

直接去anaconda的官网上下载安装包时发现最新的版本(2023.09-0)发现都已经是Python 3.11了,它的安装包文件名上又没有写Python版本,怎么才能找到需要的版本呢?

A: 查官方的release-notes即可。

比如需要Python 3.8,会找到Anaconda 2021.05版本。其中installer是Python默认版本,核心组件(numpy, pandas, scikit-learn等)依赖该版本。Meta-packages是综合功能包依赖的Python版本。

找到Anaconda后就可以去https://repo.anaconda.com/archive/或https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/下载对应的安装包了


【SPTK】

Q:
编译SPTK时没有生成xgr可执行文件

A:
下载SPTK最新版本源码,按照正常流程编译
结果bin/xgr/目录下并没有生成xgr可执行文件,但bin/目录下其它可执行文件都生成了
查了一下log,执行./configure里有以下信息
checking for log in -lm... yes
checking how to run the C preprocessor... gcc -E
checking for X... no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
因为xgr用于图形显示,怀疑跟X-system有关。
果然发现没有安装libxv开发包,于是先安装

apt-get install libxv-dev

再编译SPTK,xgr可执行程序顺利生成


【Valgrind】

Q:
出现以下错误信息如何解决?
valgrind: failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory
valgrind: failed to start tool 'callgrind' for platform 'amd64-linux': No such file or directory

A:
因为没有sudo权限,valgrind是从源码编译安装的。编译安装流程是

  1. ./autogen.sh
  2. ./configure --prefix=~/tools/valgrind-3.16.0
  3. make -j
  4. make install

如果没有执行第一步  ./autogen.sh 就会报上面的错


【Visual Studio Code】

Q:
如何搭建环境在Win10 WSL(Ubuntu)上使用vscode进行c++编程?

A:
基本上参考官网Get Started with C++ and Windows Subsystem for Linux in Visual Studio Code就可以了。但实际操作时还是可能遇到问题。以下简要记录我的开发环境搭建过程。

  1. 首先去Visual Studio Code - Code Editing. Redefined下载windows版本,在windows系统安装vscode(而不是在WSL(Ubuntu)上安装linux版本的vscode)
  2. 进入WSL(Ubuntu)安装编译调试基础软件,官网上有命令
    1. sudo apt-get update
    2. sudo apt-get install build-essential gdb

    可能还需要再安装cmake等

  3. 在WSL(Ubuntu)上启动vscode
    code project-root-dir

    首次启动时WSL(Ubuntu)会下载安装远程服务插件,保证WSL(Ubuntu)能正常上网即可。注意界面左下角的 WSL 标志

  4. 安装插件(extension)

默认会让安装一个 Remote - WSL 的插件(右下角会弹出提示,点击安装就好了)
对于c/c++编程而言,首先要安装C/C++插件,即ms-vscode.cpptools
一般来说,选择 Install in WSL: Ubuntu 就可以正常安装并使用了。
但有的时候会安装不上(比如我自己的机器),这时候就只能通过VSIX方式安装了,即自己下载插件手动安装。
GitHub - microsoft/vscode-cpptools: Official repository for the Microsoft C/C++ extension for VS Code.下载较新的版本,选择 cpptools-linux.vsix
回到vscode界面,同时按下 Ctrl+Shift+p(非常重要的一组快捷键)在搜索框里输入VSIX,选择
Extensions: Install from VSIX...
安装完成后可以看到 C/C++ 插件图标上面也有个 WSL 标志。Reload一下就可以正常使用了


Q:
vscode remote-ssh链接服务器失败的问题
自2019年底的一次win10更新后vscode就不能通过remote-ssh方式链接服务器了
按照官网Developing on Remote Machines using SSH and Visual Studio Code重新配置后,vscode能连接瞬间,差不多每打开一个文件都要重新手动链接的样子。根本不能工作。
虽然可以在服务器上装linux版的vscode再通过MobaXterm远程打开图形界面,但会有显示不够清晰,响应慢等问题。

A:
今天终于在知乎上找到了答案,参考解决VS Code Remote Development插件无法建立SSH连接的问题 - 知乎,感谢原文作者~
原因好像是win10更新后自带了OpenSSH工具作为ssh客户端,但配合vscode会出错,替换成git自带的ssh工具即可
在Windows PowerShell里面可以看到

  1. PS C:\Users\swusmi> which ssh
  2. /cygdrive/c/WINDOWS/System32/OpenSSH/ssh

如果win10装了git客户端,可以在C:\Program Files\Git\usr\bin下面找到ssh.exe。替换步骤如下:


【Ubuntu】

Q:
Win10自带的Ubuntu系统不能联网

A:
Win10 系统自带了 Ubuntu 双系统,这对开发者来说真是天大的喜讯
然而在使用中可能遇到 windows 系统能上网,ubuntu 却不能上网的问题
相关的解决方案网上有很多,这里记录一下我碰到的问题
试了几个网上的方法依然不能联网,然后偶然发现我的 ubuntu 通过IP能联网,通过URL则不能
因为我同时通过VPN联了公司的内网,怀疑跟DNS服务有关,于是断开VPN,在“更改适配器选项里”断开并重新启用“以太网”,问题解决
那么能否同时使用VPN呢?请高手赐教

问题已解决,参考Windows故障排除记录_woxiwangxuehaocpp的博客-CSDN博客


apt-get】

Q:
执行 sudo apt-get update 报 NO_PUBKEY 错

Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://dl.google.com/linux/chrome/deb stable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6494C6D6997C215E
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release.gpg  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6494C6D6997C215E
W: Some index files failed to download. They have been ignored, or old ones used instead.


A:
参考网络上的解决方案

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6494C6D6997C215E

【CentOS】

Q:
查看系统版本

A:

  1. # 查看CentOS版本
  2. # cat /etc/redhat-release
  3. CentOS Linux release 7.7.1908 (Core)
  4. # 查看Linux内核版本
  5. # uname -r
  6. 5.4.2-1.el7.elrepo.x86_64

Q:
升级系统内核

A:

首先可以去https://www.kernel.org了解一下内核版本常识,然后直接参考别人的 ELRepo 升级手册好了,亲测有效

centos7 kernel update

Install the ELRepo and GPG key

  1. rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
  2. yum install -y http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

Enable kernel updates from elrepo

yum-config-manager --enable elrepo-kernel

Remove old kernel stuff

yum remove -y kernel-{devel,tools,tools-libs}

Install the ELRepo built kernel and grub2-tools

yum install -y kernel-ml kernel-ml-{devel,tools,tools-libs} grub2-tools

We ensure these exist on the off chance they were removed during the kernel stuff above

yum install -y dkms gcc redhat-lsb-languages

查看GRUB配置

grep vmlinuz /boot/grub2/grub.cfg

选择其中一个版本作为启动项(编号从0开始)

grub2-set-default 0

grub2-mkconfig -o /boot/grub2/grub.cfg

重启生效

shutdown -r now

确认升级后的版本

uname -r


【yum】

yum

Q:
yum换源

A:
由于网络问题,默认的源要慢要么根本不能访问,换源是一个必备的技能。国内知名的如网易源和阿里云源,都有教程而且超级简单。

CentOS镜像使用帮助

阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (点击‘CentOS’进去)


Q:
CentOS中yum找不到安装包

A:
CentOS为了保证系统稳定性,其官方源不仅软件包少而且版本较旧。如果想获取更多和更新的包,可以尝试EPEL(Extra Packages for Enterprise Linux)。详细信息请查看官网

如果旧的EPEL失效需要重新安装

  1. # yum install epel-release
  2. Loaded plugins: fastestmirror, langpacks, priorities
  3. Loading mirror speeds from cached hostfile
  4. Package epel-release-7-11.noarch already installed and latest version
  5. Nothing to do
  6. # yum reinstall epel-release
  7. Reinstall 1 Package
  8. Total download size: 15 k
  9. Installed size: 24 k
  10. Is this ok [y/d/N]:

当然这并不能保证能找到所有包(比如下面的ffmpeg),如果Google不到好的的方案,不妨到 https://pkgs.org/ 找一下别人编译好的.rpm,下载后进行本地安装(yum localinstall *.rpm 或 rpm -ivh *.rpm)。万一也解决不了就只能使用终极方案(源码编译安装)了。


FFmpeg

Q:
CentOS中yum安装ffmpeg

A:
答案转自https://www.cnblogs.com/wpjamer/p/ffmpeg.html,谢谢原文作者分享
1.升级系统

  1. sudo yum install epel-release -y
  2. sudo yum update -y
  3. sudo shutdown -r now

2.安装Nux Dextop Yum 源

由于CentOS没有官方FFmpeg rpm软件包。但是,我们可以使用第三方YUM源(Nux Dextop)完成此工作。

1) CentOS 7

  1. sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
  2. sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

2) CentOS 6

  1. sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
  2. sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm

3.安装FFmpeg 和 FFmpeg开发包

sudo yum install ffmpeg ffmpeg-devel -y

4.测试是否安装成功

ffmpeg

5.如果你想了解更多关于FFmpeg使用方面的资料,可以输入:

ffmpeg -h

例子:
使用FFmpeg将mp3转为ogg

ffmpeg -i MLKDream_64kb.mp3 -c:a libvorbis -q:a 4 MLKDream_64kb.ogg

使用FFmpeg将flv转为mp4

ffmpeg -i beeen.flv -y -vcodec copy -acodec copy beeen.mp4

libasound-dev

Q:
CentOS中yum安装libasound-dev

A:
通过 yum install 会报错找不到包

  1. # yum install libasound-dev
  2. Loaded plugins: fastestmirror, langpacks, priorities
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.tuna.tsinghua.edu.cn
  5. No package libasound-dev available.
  6. Error: Nothing to do

因为 libasound-dev 是一个虚包,负责填实 libasound-dev 的软件包为 libasound2-dev ,但libasound2-dev也是一个虚包,也不能直接安装。

  1. shared library for ALSA applications
  2. 同时作为一个虚包由这些包填实: liboss4-salsa-asound2

最后发现最方便的方法是通过安装 alsa-lib-devel 来间接安装(如果还是找不到可以去这里下)

# yum install alsa-lib-devel

安装成功后可以在安装路径(默认/usr)下找到 include/alsa/asoundlib.h 和 lib64/libasound.so


libav-dev

Q:
CentOS中安装libav-dev

A:
通过 yum install 会报错找不到包,libav官网有源码安装方法介绍。CentOS通过源码安装方法如下

  1. wget https://www.libav.org/releases/libav-12.3.tar.xz
  2. xz -d libav-12.3.tar.xz
  3. tar -xf libav-12.3.tar
  4. cd libav-12.3
  5. ./configure --enable-gpl --enable-dxva2
  6. make & make install

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号