准备 Python 环境
确保你的系统上安装了Python。PDM支持Python 3.7及以上版本
。如果您没有安装Python,请从Python官方网站下载并安装最新的稳定版本。
源码安装 Python
CentOS 7 / RHEL 7 源码编译
# Install newer gcc
sudo yum install centos-release-scl -y
sudo yum install devtoolset-7-gcc* -y
source /opt/rh/devtoolset-7/enable
gcc --version
# Install newer openssl 1.1.1w
curl -JLO https://www.openssl.org/source/openssl-1.1.1w.tar.gz
tar zxf openssl-1.1.1w.tar.gz && cd openssl-1.1.1w
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make -j $(nproc)
sudo make install
# Update the shared libraries cache.
sudo ldconfig
sudo tee /etc/profile.d/openssl.sh<<EOF
export PATH=/usr/local/openssl/bin:\$PATH
export LD_LIBRARY_PATH=/usr/local/openssl/lib:\$LD_LIBRARY_PATH
EOF
source /etc/profile.d/openssl.sh
# Compile python3.11.4 from source
curl -LJO https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz
tar zxf Python-3.11.4.tgz && cd Python-3.11.4
LDFLAGS="${LDFLAGS} -Wl,-rpath=/usr/local/openssl/lib" ./configure --with-openssl=/usr/local/openssl
make -j $(nproc)
sudo make altinstall
# Verify the installation
python3.11 -c "import ssl; print(ssl.OPENSSL_VERSION)"
Mac 源码编译
# Compile python3.11.4 from source
curl -LJO https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz
tar zxf Python-3.11.4.tgz && cd Python-3.11.4
./configure --prefix=${HOME}/software/Python-3.11.4 --enable-optimizations
make -j $(nproc)
make altinstall
注意,如果想在mac apple芯片(如m1/m2等)机型上编译Python2.7,由于Python2系列和Ptyhon3系列3.9版本之前,都不支持arm架构。则可以考虑下载x86的安装器,让apple芯片在Rosetta模式下打开它。
在 Windows 上安装 Python
首先,根据你的Windows版本(64位还是32位)从Python的官方网站下载Python 3.12对应的安装程序,然后,运行下载的exe安装包。
安装 PDM
打开终端或命令提示符,运行以下命令使用pip安装PDM:
pip3.11 install pdm
pdm -V