wsl Ubuntu-22.04 安装 pyenv,管理多版本python
之前一直习惯与使用macOS,对python的多版本管理,我还是比较喜欢 pyenv。可是wsl上安装可不像macOS 使用homebrew一条命令就好了。需要手动把pyenv的源码下载下来,安装的时候还遇到了一些问题,做个笔记.
下载源码
1 git clone https://github.com/pyenv/pyenv.git ~/.pyenv
添加环境变量
1export PYENV_ROOT="$HOME/.pyenv"
2command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
3eval "$(pyenv init --path)" # 好像快一点,也许是心理安慰
安装依赖
1apt install xz-utils tk-dev libffi-dev liblzma-dev libbz2-dev \
2libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl liblzma-dev
gzip错误
1➜ ~ sudo apt-get install libffi-dev
2Reading package lists... Done
3Building dependency tree... Done
4Reading state information... Done
5The following NEW packages will be installed:
6 libffi-dev
70 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
8Need to get 63.7 kB of archives.
9After this operation, 336 kB of additional disk space will be used.
10Get:1 http://mirrors.ustc.edu.cn/ubuntu jammy/main amd64 libffi-dev amd64 3.4.2-4 [63.7 kB]
11Fetched 63.7 kB in 0s (484 kB/s)
12Selecting previously unselected package libffi-dev:amd64.
13(Reading database ... 41882 files and directories currently installed.)
14Preparing to unpack .../libffi-dev_3.4.2-4_amd64.deb ...
15Unpacking libffi-dev:amd64 (3.4.2-4) ...
16Setting up libffi-dev:amd64 (3.4.2-4) ...
17Processing triggers for install-info (6.8-4build1) ...
18sh: 1: gzip: Exec format error
19install-info: warning: no info dir entry in `/usr/share/info/bc.info.gz'
20sh: 1: gzip: Exec format error
21install-info: warning: no info dir entry in `/usr/share/info/bzip2.info.gz'
22sh: 1: gzip: Exec format error
23install-info: warning: no info dir entry in `/usr/share/info/coreutils.info.gz'
24sh: 1: gzip: Exec format error
25install-info: warning: no info dir entry in `/usr/share/info/diffutils.info.gz'
26sh: 1: gzip: Exec format error
27install-info: warning: no info dir entry in `/usr/share/info/ed.info.gz'
28sh: 1: gzip: Exec format error
29install-info: warning: no info dir entry in `/usr/share/info/find-maint.info.gz'
30sh: 1: gzip: Exec format error
31install-info: warning: no info dir entry in `/usr/share/info/find.info.gz'
32sh: 1: gzip: Exec format error
33install-info: warning: no info dir entry in `/usr/share/info/gnupg.info.gz'
34sh: 1: gzip: Exec format error
35install-info: warning: no info dir entry in `/usr/share/info/grep.info.gz'
36sh: 1: gzip: Exec format error
37install-info: warning: no info dir entry in `/usr/share/info/gzip.info.gz'
38sh: 1: gzip: Exec format error
39install-info: warning: no info dir entry in `/usr/share/info/info-stnd.info.gz'
40sh: 1: gzip: Exec format error
41install-info: warning: no info dir entry in `/usr/share/info/libffi.info.gz'
42sh: 1: gzip: Exec format error
43install-info: warning: no info dir entry in `/usr/share/info/nano.info.gz'
44sh: 1: gzip: Exec format error
45install-info: warning: no info dir entry in `/usr/share/info/rluserman.info.gz'
46sh: 1: gzip: Exec format error
47install-info: warning: no info dir entry in `/usr/share/info/screen.info.gz'
48sh: 1: gzip: Exec format error
49install-info: warning: no info dir entry in `/usr/share/info/sed.info.gz'
50sh: 1: gzip: Exec format error
51install-info: warning: no info dir entry in `/usr/share/info/time.info.gz'
52sh: 1: gzip: Exec format error
53install-info: warning: no info dir entry in `/usr/share/info/wget.info.gz'
54Processing triggers for man-db (2.10.2-1) ...
55Scanning processes...
56Scanning candidates...
57Scanning processor microcode...
58Scanning linux images...
59
60Failed to retrieve available kernel versions.
61
62Failed to check for processor microcode upgrades.
63
64No services need to be restarted.
65
66No containers need to be restarted.
67
68User sessions running outdated binaries:
69 root @ /dev/pts/0: sh[13126]
70 root @ /dev/tty1: init[8]
71 root @ /dev/tty2: init[12909]
72 zmhu @ /dev/tty1: zsh[9]
73 zmhu @ /dev/tty2: zsh[12910]
74
75
76No VM guests are running outdated hypervisor (qemu) binaries on this host.
这段错误的意思就是/usr/bin/gzip
这个文件不可以执行
1➜ ~ gzip
2zsh: exec format error: gzip
3➜ ~ which gzip
4/usr/bin/gzip
5➜ ~ /usr/bin/gzip
6zsh: exec format error: /usr/bin/gzip
我在官方的issues里找到了同样的问题
Actually those were all 0x1000 already. In gzip 1.10-4ubuntu4 I only had to change the value at offset 0x189 using
1echo -en '\x10' | sudo dd of=/usr/bin/gzip count=1 bs=1 conv=notrunc seek=$((0x189))
执行一下这条命令,再试着执行一下 `/usr/bin/gzip'
1➜ ~ /usr/bin/gzip
2gzip: compressed data not written to a terminal. Use -f to force compression.
3For help, type: gzip -h
这回gzip正常了,可以继续了
1➜ ~ pyenv install 3.10.5
2Downloading Python-3.10.5.tar.xz...
3-> https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tar.xz
4Installing Python-3.10.5...
5Installed Python-3.10.5 to /home/zmhu/.pyenv/versions/3.10.5
把python的版本切换成pyenv 3.10.5的版本
1➜ ~ pyenv versions
2* system
3 3.10.5 (set by /home/${user}/.pyenv/version)
1➜ ~ pyenv global 3.10.5
2➜ ~ which python
3/home/${user}/.pyenv/shims/python
4➜ ~ python --version
5Python 3.10.5