Similar to nvm, I'm not sure what the equivalent for nrm is. If one exists, configuring mirror sources would be much more convenient.

Here is a record of the context and experience with using pyenv. From last night until today, I have been compiling the mongo source code. The mongo source code primarily uses python to generate related build scripts or configurations. I will write about the specific build mongo process when I have time. As for why I considered using pyenv: the mongo build documentation specifies a version requirement of >=3.10. ubuntu 24.04 comes with 3.12.3 installed by default, which clearly meets the requirement. However, I completely did not expect that the mongo build scripts use some apis that are incompatible due to version differences. It is truly frustrating. Although I haven't found many issues so far, I cannot modify them because many of the packages they release also use these apis. To successfully build based on version 3.12.3, these issues need to be resolved. Alternatively, I could change my approach and stop using a higher version of python, opting directly for 3.10.x. There shouldn't be any problems with that, and honestly, there really aren't. I found a cloud service temporary instance to test it, and it worked perfectly. Now, I just need to find a python version management tool to use the specified version of python. I didn't spend much time researching and choosing at the time; as long as it can manage multiple versions, that's fine. It just needs to be a tool that works well in practice. I will absolutely not touch the system pre-installed python version and environment, no matter what. I've been burned by that before. I can write about it when I have time to recall the details; it took almost a day to resolve back then. Back to pyenv, let me record the relevant commands and points to note.

Installation

pyenv github

If your environment is ubuntu, simply use the automatic-installer.

# 注意可能代理
curl https://pyenv.run | bash
# 装完需要配置 bash 执行前的脚本, ~/.profile ~/.bash_profile 之类的, 因人而异, 我这里选择的是 ~/.bashrc
# 具体内容安装成功之后会有提示, 这里有点疑惑的是, pyenv 支持进入某个目录之后自动切换到对应版本吗? 类似 nvm 这种的?
pyenv install 3.10.4

To be honest, there is no download progress indicator, no information related to build, and very little feedback or prompts throughout the entire installation process. Furthermore, build should have its own default strategy, but after downloading, I still have to use apt to install many extensions, such as sqlite, even though I don't need any of these, and I don't even know where to configure it...

  • No progress shown during download
  • Many details are not displayed during installation
  • build is non-interactive, no options can be selected

Be cautious. Absolutely never write such an extremely unfriendly program. Self-reflection is required

Mirror Source Configuration

For some reason, the command-line configuration failed, which is quite confusing. I'll investigate it further later when I have the chance. For now, I'm using the Tsinghua source and the Tencent source.

# https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
# 无用, 似乎某一版本之后给废除了
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
# 同样无用
poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/

Finally, the implementation was achieved using the relevant configuration files.

# 这是 ubuntu 上默认的配置位置
mkdir -p ~/.pip && touch ~/.pip/pip.conf
# 内容添加
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Because pypoetry still needs to be configured

# 这是 ubuntu 上默认的配置位置
mkdir -p ~/.config/pypoetry && touch ~/.config/pypoetry/config.toml
# 内容添加
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Tencent Cloud is mostly the same; the mirror source address is https://mirrors.cloud.tencent.com/pypi/simple

NOTE: Be cautious; absolutely do not write extremely unfriendly code. seen self-reflection