赞
踩
目录
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 这些配置文件的运行方式。
Q:
Ubuntu 16.04.6 LTS 下将cmake升级到最新版 cmake 3.15 时报错
- Install the project...
- bin/cmake: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by bin/cmake)
- make: *** [Makefile:74: install] Error 1
A:
由于 Ubuntu 软件库没有及时更新,通过 apt 找不到需要的 cmake 版本,考虑源码安装
- wget https://github.com/Kitware/CMake/releases/download/v3.15.0-rc1/cmake-3.15.0-rc1.tar.gz
- tar -zxf cmake-3.15.0-rc1.tar.gz
- cd cmake-3.15.0-rc1/
- ./configure --prefix=[TARGET_DIR]
- make
- make install
最后一步出错了
查看glib库版本,确实不支持 GLIBCXX_3.4.22
$ strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX GLIBCXX_3.4 GLIBCXX_3.4.1 GLIBCXX_3.4.2 GLIBCXX_3.4.3 GLIBCXX_3.4.4 GLIBCXX_3.4.5 GLIBCXX_3.4.6 GLIBCXX_3.4.7 GLIBCXX_3.4.8 GLIBCXX_3.4.9 GLIBCXX_3.4.10 GLIBCXX_3.4.11 GLIBCXX_3.4.12 GLIBCXX_3.4.13 GLIBCXX_3.4.14 GLIBCXX_3.4.15 GLIBCXX_3.4.16 GLIBCXX_3.4.17 GLIBCXX_3.4.18 GLIBCXX_3.4.19 GLIBCXX_3.4.20 GLIBCXX_3.4.21 GLIBCXX_DEBUG_MESSAGE_LENGTH
考虑升级glib库。升级方法有多种,这里选了最直接的一种:下载对应的lib文件进行替换(这个方法可能会涉及到一些兼容性问题,请慎用)
从 https://packages.debian.org/search?keywords=lib64stdc%2B%2B6 查询并下载对应的软件包,解压、替换即可
- wget http://ftp.cn.debian.org/debian/pool/main/g/gcc-8/lib64stdc++6_8.3.0-7_i386.deb
- ar -x lib64stdc++6_8.3.0-7_i386.deb
- 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 文件
- cp usr/lib64/libstdc++.so.6.0.25 /usr/lib/x86_64-linux-gnu
- rm libstdc++.so.6
- ln -s libstdc++.so.6.0.25 libstdc++.so.6
再回去 cmake 编译目录下执行 make install,成功~
- $ cmake --version
- cmake version 3.15.0-rc1
---------------------------------------------------------
2019.11.07补充:
以上安装方式在使用中可能会碰到以下错误:即使用cmake默认的curl下载第三方资源时可能不支持"https"协议
- CMake Error at protobuf-stamp/download-protobuf.cmake:159 (message):
- Each download failed!
-
- error: downloading 'https://cnbj1.fds.api.xiaomi.com/mace/third-party/protobuf/protobuf-3.6.1.zip' failed
- status_code: 1
- status_string: "Unsupported protocol"
- log:
- --- LOG BEGIN ---
- Protocol "https" not supported or disabled in libcurl
-
- Closing connection -1
解决方法:
step 01: 先看自己的curl是否支持"https",以下是不支持的情况
- $ curl --version
- curl 7.67.0 (x86_64-pc-linux-gnu) libcurl/7.67.0 zlib/1.2.8
- Release-Date: 2019-11-06
- Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp
- Features: AsynchDNS IPv6 Largefile libz UnixSockets
这时需要先安装ssl再重新安装curl,操作如下
- sudo apt-get install openssl libssl-dev
- wget https://curl.haxx.se/download/curl-7.67.0.tar.gz
- tar -zxf curl-7.67.0.tar.gz
- cd curl-7.67.0
- ./configure --with-ssl --with-libssl-prefix=/usr/local/ssl
- make
- sudo make install
- sudo ldconfig
ldconfig 的作用是更新 libcurl 的链接(参考https://man.linuxde.net/ldconfig)因为 cmake 实际使用的是 libcurl 而不是 curl。重新查看 curl 是否支持"https",发现已经有了。
- $ curl --version
- curl 7.67.0 (x86_64-pc-linux-gnu) libcurl/7.67.0 OpenSSL/1.0.2g zlib/1.2.8
- Release-Date: 2019-11-06
- Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
- Features: AsynchDNS HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets
step 02: curl的问题解决后就是重新编译 cmake,唯一不同的是编译前多了一个配置项
- cd cmake-3.15.0-rc1/
- ./bootstrap --system-curl --prefix=[TARGET_DIR]
- make
- 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安装方法
- sudo apt-get install build-essential module-assistant
- sudo apt-get install gcc-multilib g++-multilib
CentOS安装方法
yum install glibc-devel.i686 libstdc++-devel.i686
Q:
第一次用doxygen产生文档就遇到问题
- writing tag file...
- Running dot...
- sh: 1: dot: not found
- error: Problems running dot: exit code=127, command='dot', arguments=...
A:
当然解决也很简单
- The program 'dot' is currently not installed. You can install it by typing:
- sudo apt install graphviz
Q:
CentOS 7 下如何安装g++?
A:
Linux直接安装gcc的版本截止目前(2019年12月)仍然是4.8.5。但是CentOS 7下通过以下命令安装g++报错
- # yum install g++
- Loaded plugins: fastestmirror, langpacks, priorities
- Loading mirror speeds from cached hostfile
- * elrepo: mirrors.tuna.tsinghua.edu.cn
- * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
- * elrepo-testing: mirrors.tuna.tsinghua.edu.cn
- * epel: mirrors.aliyun.com
- No package g++ available.
- Error: Nothing to do
改成 gcc-c++ 就好了
- # yum install gcc-c++
-
- Installed:
- gcc-c++.x86_64 0:4.8.5-39.el7
-
- Complete!
-
- # g++ --version
- 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 选。
- wget http://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz
- 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
或者下载编译
- cd gcc-7.4.0
- ./contrib/download_prerequisites
step03 编译。文章建议在outside the source directory编译,所以先在 gcc-7.4.0外建立build进行编译。
- mkdir build
- cd build
- ../gcc-7.4.0/configure --prefix=/home/soft --disable-multilib
- make -j
- sudo make install
其中 --prefix 选项可以指定安装路径,默认为 /usr;--disable-multilib 选项指定不同时支持32位(-m32)和64位,如果 configure 报以下错误可以将这个选项加上。编译过程比较漫长,建议用 make -j 并行编译。
- /bin/ld: cannot find crt1.o: No such file or directory
- /bin/ld: cannot find crti.o: No such file or directory
- /bin/ld: cannot find -lc
- /bin/ld: cannot find crtn.o: No such file or directory
- collect2: error: ld returned 1 exit status
- 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了,但有些场合下必须使用较低版本的编译器,考虑降级,或者让新老版本同时存在。
首先安装老版本
- sudo apt-get install gcc-4.8 g++-4.8
- # 如果需要进行交叉编译
- 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++实际都是链接文件,可以看到它们都指向了具体的版本
- ls -lh /usr/bin/g{cc,++}*
- /usr/bin/g++ -> /etc/alternatives/g++
- /usr/bin/g++-4.8
- /usr/bin/g++-7 -> x86_64-linux-gnu-g++-7
- /usr/bin/gcc -> /etc/alternatives/gcc
- /usr/bin/gcc-4.8
- /usr/bin/gcc-7 -> x86_64-linux-gnu-gcc-7
- /usr/bin/gcc-ar -> gcc-ar-7
- /usr/bin/gcc-ar-4.8
- /usr/bin/gcc-ar-7 -> x86_64-linux-gnu-gcc-ar-7
- /usr/bin/gcc-nm -> gcc-nm-7
- /usr/bin/gcc-nm-4.8
- /usr/bin/gcc-nm-7 -> x86_64-linux-gnu-gcc-nm-7
- /usr/bin/gcc-ranlib -> gcc-ranlib-7
- /usr/bin/gcc-ranlib-4.8
- /usr/bin/gcc-ranlib-7 -> x86_64-linux-gnu-gcc-ranlib-7

这时候需要通过update-alternatives命令来切换软件版本
它的几个常用命令如下:
1. 显示关于 <名称> 替换组的信息。
update-alternatives --display <名称>
- sudo update-alternatives --display gcc
- update-alternatives: error: no alternatives for gcc
说明还没有为 gcc 建立链接符
2. 系统中加入一组候选项。
update-alternatives --install <链接> <名称> <路径> <优先级>
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
- 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 <名称>
- sudo update-alternatives --config gcc
- 有 2 个候选项可用于替换 gcc (提供 /usr/bin/gcc)。
-
- 选择 路径 优先级 状态
- ------------------------------------------------------------
- * 0 /usr/bin/gcc-4.8 50 自动模式
- 1 /usr/bin/gcc-4.8 50 手动模式
- 2 /usr/bin/gcc-7 40 手动模式
选择默认或1,再用gcc --version查看,版本已经变成4.8.5了
然后用同样的方法配置g++即可
Q:
git clone 时报以下错误
- remote: Enumerating objects: 52289, done.
- remote: Counting objects: 100% (52289/52289), done.
- remote: Compressing objects: 100% (32579/32579), done.
- error: RPC failed; curl 18 transfer closed with outstanding read data remaining
- fatal: the remote end hung up unexpectedly
- fatal: early EOF
- 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:网络下载速度缓慢
解决方法:命令行输入
- git config --global http.lowSpeedLimit 0
- git config --global http.lowSpeedTime 999999
如果依旧clone失败,则首先浅层clone,然后更新远程库到本地
- git clone --depth=1 http://xxx.git
- git fetch --unshallow
Q:
调用librosa时遇到 No module named 'numba.decorators' 错
- File "/home/tanxj/local/anaconda3/envs/py36_tf1.15/lib/python3.6/site-packages/librosa/util/decorators.py", line 9, in <module>
- from numba.decorators import jit as optional_jit
- ModuleNotFoundError: No module named 'numba.decorators'
A:
是因为librosa和numba版本不匹配导致的,将librosa升级到版本0.8以上可解决
如果不能升级高版本,尝试了 numba==0.49.1 librosa==0.6.3 这组也work。
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
- sudo apt-get remove --purge python-apt
- sudo apt-get install python-apt
复制 python3.5 的 apt-pkg*.so 为 python3.6 的apt-pkg*.so
- cd /usr/lib/python3/dist-packages/
- 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 处
- # pip install pyworld
- Collecting pyworld
- Downloading pyworld-0.3.0.tar.gz (212 kB)
- |████████████████████████████████| 212 kB 19 kB/s
- Installing build dependencies ...
A:
- # pip install --pre --extra-index https://pypi.tuna.tsinghua.edu.cn/simple pyworld
- Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple, https://pypi.tuna.tsinghua.edu.cn/simple
- Collecting pyworld
- Using cached https://pypi.tuna.tsinghua.edu.cn/packages/88/0b/9f8ceb7548bbb1294729b291044b8e72754db21dbc672acbd5eec6ed740b/pyworld-0.3.0.tar.gz (212 kB)
- Installing build dependencies ... done
- Getting requirements to build wheel ... done
- Preparing metadata (pyproject.toml) ... done
- ......
- Successfully built pyworld
- Installing collected packages: cython, pyworld
- 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
Q:
安装 bandmat 报错
- bandmat/core.c: In function ‘__Pyx_ExceptionSave’:
- bandmat/core.c:15606:19: error: ‘PyThreadState’ has no member named ‘exc_type’
- *type = tstate->exc_type;
- ^
- bandmat/core.c:15607:20: error: ‘PyThreadState’ has no member named ‘exc_value’
- *value = tstate->exc_value;
- ^
- bandmat/core.c:15608:17: error: ‘PyThreadState’ has no member named ‘exc_traceback’
- *tb = tstate->exc_traceback;
- ^
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
Q:
安装PyYAML失败先是执行程序遇到以下报错
- File "/home/tanxingjun/usr/anaconda3/lib/python3.6/site-packages/keras/engine/network.py", line 9, in <module>
- import yaml
- ModuleNotFoundError: No module named 'yaml'
按照惯例用pip安装yaml包
pip install yaml
但却报以下错
- Collecting yaml
- ERROR: Could not find a version that satisfies the requirement yaml (from versions: none)
- 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也卸载了)
- Verifying transaction: failed
- RemoveError: 'ruamel_yaml' is a dependency of conda and cannot be removed from
- conda's operating environment.
这下就陷入僵局了,各种百度无果
A:
最终解决方法:
不经意发现pip安装包目录(site-packages)下有个叫 PyYAML-5.1-py3.6.egg-info 的文件,正常来说它不应该是一个目录吗?
再一看这还是一个空文件,估计是什么时候安装或卸载失败的残留文件,但它会让 pip 安装时显示这个包已安装
果断删除,重新 pip install pyyaml ,一切顺利了,问题解决
Q:
pip安装PyAudio报错
- Building wheels for collected packages: PyAudio
- Building wheel for PyAudio (setup.py) ... error
- ERROR: Command errored out with exit status 1:
- ......
- src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
- #include "portaudio.h"
- ^~~~~~~~~~~~~
- compilation terminated.
- error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
- ----------------------------------------
- ERROR: Failed building wheel for PyAudio
- Running setup.py clean for PyAudio
- Failed to build PyAudio
- Installing collected packages: PyAudio
- Running setup.py install for PyAudio ... error
- ERROR: Command errored out with exit status 1:

A:
在Mac OS X或Ubuntu上需要先安装依赖项,见官网说明
- # Mac OS X
- brew install portaudio
- pip install pyaudio
- # Ubuntu
- sudo apt-get install python-pyaudio python3-pyaudio
- pip install pyaudio
Q:
- File "/usr/local/lib/python3.6/dist-packages/librosa/core/audio.py", line 8, in <module>
- import soundfile as sf
- File "/usr/local/lib/python3.6/dist-packages/soundfile.py", line 142, in <module>
- raise OSError('sndfile library not found')
- 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
Q:
- File "/usr/local/lib/python3.7/dist-packages/g2p_en/g2p.py", line 22, in <module>
- nltk.data.find('taggers/averaged_perceptron_tagger.zip')
- File "/usr/local/lib/python3.7/dist-packages/nltk/data.py", line 542, in find
- return ZipFilePathPointer(p, zipentry)
- File "/usr/local/lib/python3.7/dist-packages/nltk/compat.py", line 41, in _decorator
- return init_func(*args, **kwargs)
- File "/usr/local/lib/python3.7/dist-packages/nltk/data.py", line 394, in __init__
- zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
- File "/usr/local/lib/python3.7/dist-packages/nltk/compat.py", line 41, in _decorator
- return init_func(*args, **kwargs)
- File "/usr/local/lib/python3.7/dist-packages/nltk/data.py", line 934, in __init__
- zipfile.ZipFile.__init__(self, filename)
- File "/usr/lib/python3.7/zipfile.py", line 1225, in __init__
- self._RealGetContents()
- File "/usr/lib/python3.7/zipfile.py", line 1292, in _RealGetContents
- raise BadZipFile("File is not a zip file")
- zipfile.BadZipFile: File is not a zip file

A:
可能是averaged_perceptron_tagger包没下载,可以到路径~/nltk_data/taggers下去确认。下载方法:
- # python
- Python 3.7.5 (default, Nov 7 2019, 10:50:52)
- [GCC 8.3.0] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import nltk
- >>> nltk.download("averaged_perceptron_tagger")
- [nltk_data] Downloading package averaged_perceptron_tagger to
- [nltk_data] /root/nltk_data...
- [nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.
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/下载对应的安装包了
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可执行程序顺利生成
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是从源码编译安装的。编译安装流程是
- ./autogen.sh
- ./configure --prefix=~/tools/valgrind-3.16.0
- make -j
- make install
如果没有执行第一步 ./autogen.sh 就会报上面的错
Q:
如何搭建环境在Win10 WSL(Ubuntu)上使用vscode进行c++编程?
A:
基本上参考官网Get Started with C++ and Windows Subsystem for Linux in Visual Studio Code就可以了。但实际操作时还是可能遇到问题。以下简要记录我的开发环境搭建过程。
- sudo apt-get update
- sudo apt-get install build-essential gdb
可能还需要再安装cmake等
code project-root-dir
首次启动时WSL(Ubuntu)会下载安装远程服务插件,保证WSL(Ubuntu)能正常上网即可。注意界面左下角的 WSL 标志
默认会让安装一个 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里面可以看到
- PS C:\Users\swusmi> which ssh
- /cygdrive/c/WINDOWS/System32/OpenSSH/ssh
如果win10装了git客户端,可以在C:\Program Files\Git\usr\bin下面找到ssh.exe。替换步骤如下:
Q:
Win10自带的Ubuntu系统不能联网
A:
Win10 系统自带了 Ubuntu 双系统,这对开发者来说真是天大的喜讯
然而在使用中可能遇到 windows 系统能上网,ubuntu 却不能上网的问题
相关的解决方案网上有很多,这里记录一下我碰到的问题
试了几个网上的方法依然不能联网,然后偶然发现我的 ubuntu 通过IP能联网,通过URL则不能
因为我同时通过VPN联了公司的内网,怀疑跟DNS服务有关,于是断开VPN,在“更改适配器选项里”断开并重新启用“以太网”,问题解决
那么能否同时使用VPN呢?请高手赐教
问题已解决,参考Windows故障排除记录_woxiwangxuehaocpp的博客-CSDN博客
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
Q:
查看系统版本
A:
- # 查看CentOS版本
- # cat /etc/redhat-release
- CentOS Linux release 7.7.1908 (Core)
- # 查看Linux内核版本
- # uname -r
- 5.4.2-1.el7.elrepo.x86_64
Q:
升级系统内核
A:
首先可以去https://www.kernel.org了解一下内核版本常识,然后直接参考别人的 ELRepo 升级手册好了,亲测有效
Install the ELRepo and GPG key Enable kernel updates from elrepo Remove old kernel stuff Install the ELRepo built kernel and grub2-tools We ensure these exist on the off chance they were removed during the kernel stuff above 查看GRUB配置 grep vmlinuz /boot/grub2/grub.cfg 选择其中一个版本作为启动项(编号从0开始) grub2-set-default 0 grub2-mkconfig -o /boot/grub2/grub.cfg 重启生效 shutdown -r now 确认升级后的版本 uname -r |
Q:
yum换源
A:
由于网络问题,默认的源要慢要么根本不能访问,换源是一个必备的技能。国内知名的如网易源和阿里云源,都有教程而且超级简单。
阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (点击‘CentOS’进去)
Q:
CentOS中yum找不到安装包
A:
CentOS为了保证系统稳定性,其官方源不仅软件包少而且版本较旧。如果想获取更多和更新的包,可以尝试EPEL(Extra Packages for Enterprise Linux)。详细信息请查看官网。
如果旧的EPEL失效需要重新安装
- # yum install epel-release
- Loaded plugins: fastestmirror, langpacks, priorities
- Loading mirror speeds from cached hostfile
- Package epel-release-7-11.noarch already installed and latest version
- Nothing to do
-
- # yum reinstall epel-release
- Reinstall 1 Package
-
- Total download size: 15 k
- Installed size: 24 k
- Is this ok [y/d/N]:
当然这并不能保证能找到所有包(比如下面的ffmpeg),如果Google不到好的的方案,不妨到 https://pkgs.org/ 找一下别人编译好的.rpm,下载后进行本地安装(yum localinstall *.rpm 或 rpm -ivh *.rpm)。万一也解决不了就只能使用终极方案(源码编译安装)了。
Q:
CentOS中yum安装ffmpeg
A:
答案转自https://www.cnblogs.com/wpjamer/p/ffmpeg.html,谢谢原文作者分享
1.升级系统
- sudo yum install epel-release -y
- sudo yum update -y
- sudo shutdown -r now
2.安装Nux Dextop Yum 源
由于CentOS没有官方FFmpeg rpm软件包。但是,我们可以使用第三方YUM源(Nux Dextop)完成此工作。
1) CentOS 7
- sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
- 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
- sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
- 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
Q:
CentOS中yum安装libasound-dev
A:
通过 yum install 会报错找不到包
- # yum install libasound-dev
- Loaded plugins: fastestmirror, langpacks, priorities
- Loading mirror speeds from cached hostfile
- * epel: mirrors.tuna.tsinghua.edu.cn
- No package libasound-dev available.
- Error: Nothing to do
因为 libasound-dev 是一个虚包,负责填实 libasound-dev 的软件包为 libasound2-dev ,但libasound2-dev也是一个虚包,也不能直接安装。
- shared library for ALSA applications
- 同时作为一个虚包由这些包填实: liboss4-salsa-asound2
最后发现最方便的方法是通过安装 alsa-lib-devel 来间接安装(如果还是找不到可以去这里下)
# yum install alsa-lib-devel
安装成功后可以在安装路径(默认/usr)下找到 include/alsa/asoundlib.h 和 lib64/libasound.so
Q:
CentOS中安装libav-dev
A:
通过 yum install 会报错找不到包,libav官网有源码安装方法介绍。CentOS通过源码安装方法如下
- wget https://www.libav.org/releases/libav-12.3.tar.xz
- xz -d libav-12.3.tar.xz
- tar -xf libav-12.3.tar
- cd libav-12.3
- ./configure --enable-gpl --enable-dxva2
- make & make install
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。