Python
TL,DR:
Install Python as follows:
sudo apt install libsqlite3-dev zlib1g-dev libssl-dev libffi-dev \
libbz2-dev libreadline-dev readline-doc bzip2-doc liblzma-dev \
libncurses5 libncurses5-dev libncursesw5 libncursesw5-dev
PYTHON_CONFIGURE_OPTS="--enable-shared" asdf install python 3.8.7
Install from local source tarball
Read file ~/.asdf/plugins/python/README.md, you can see the Python plugin for asdf uses python-build as the installation tool. So on the README.md page, we can find that it find downloaded files in the folder defined by environment PYTHON_BUILD_CACHE_PATH, so we can download Python source tarball from its official FTP, for example:
cd ~/Downloads
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
Now you can install Python 3.8.5 without downloading it:
PYTHON_CONFIGURE_OPTS="--enable-shared" PYTHON_BUILD_CACHE_PATH=$HOME/Downloads asdf install python 3.8.5
IPython
Problem:
asdf 下载 Python 源码后编译失败,报:
zipimport.ZipImportError: can't decompress data; zlib not available
Makefile:1186: recipe for target 'install' failed
make: *** [install] Error 1
...
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
asdf 安装 Python 后没有 sqlite 支持,
IPython 启动时报 WARNING: IPython History requires SQLite, your history will not be saved
。
pip install csvkit
报如下错误:
ModuleNotFoundError: No module named '_ctypes'
原因是系统缺少 dev 库,导致 Python 编译时包不全。
Solution: 在编译 Python 前安装需要的 dev 包,确保编译完成后没有 warnings:
sudo apt install libsqlite3-dev zlib1g-dev libssl-dev libffi-dev libbz2-dev libreadline-dev readline-doc bzip2-doc
asdf install python 3.7.6
Ref: https://yrsdi.github.io/python/warning-ipython-history-requires-sqlite/
PyInstaller
Problem:
使用 asdf 安装 Python,然后在 virtualenv 里用 pip 安装 pyinstaller, 编译 Python 脚本的时候报缺少头文件错误。
Solution:
Install Python with PYTHON_CONFIGURE_OPTS="--enable-shared"
, total command is:
PYTHON_CONFIGURE_OPTS="--enable-shared" asdf install python 3.7.6
Notes:
使用 apt install python3-dev
无效,因为它安装的是系统 python3
的库,
而不是 asdf 编译的 python 的库。
visidata
visidata is developed with Python and ncurse libraries. Install these libraries before install Python:
sudo apt install libncurses5 libncurses5-dev libncursesw5 libncursesw5-dev
asdf install python 3.8.1
asdf global python 3.8.1
pip install visidata
asdf reshim python
vd abc.csv
Without these libraries preinstalled, you can install visidata with pip.
But when you run vd
, the following error raised:
ModuleNotFoundError: No module named '_curses'
.
If you already installed a Python version, say 3.7.7,
then install libncurses5
, libncurses5-dev
, etc,
you need uninstall this version and reinstall it again:
asdf uninstall python 3.7.7
asdf install python 3.7.7
pip install visidata
asdf reshim python
vd abc.csv