Pyenv 搭建编译环境

2023-04-09  本文已影响0人  一只老梨花

安装pyenv

curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

安装python

安装依赖
1. yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

修改python 文件的下载地址
比如3.6.8
vim /home/admin/.pyenv/plugins/python-build/share/python-build/3.6.8 
python下载地址替换为:
https://mirrors.huaweicloud.com/python/

2. pyenv install 3.6.8
安装venv-pack
3. /home/admin/.pyenv/versions/${lang_version}/bin/pip install  venv-pack

安装pyenv-virtualenv ()

git clone https://github.com/pyenv/pyenv-virtualenv.git /home/admin/.pyenv/plugins/pyenv-virtualenv

应用的编译命令

效果:可以打包编译机器上的python虚拟环境到服务器上,直接使用安装包进行启动,而不需要在目标服务器上安装依赖包
前提是编译机器和运行机器上的一些二进制依赖包要版本一致。

echo "run before build"
cd  ${WORKSPACE}
virtualenv_name="${JOB_NAME}"
clean_old_env="disable"
pip=/home/admin/.pyenv/versions/${virtualenv_name}/bin/pip3

if [[ "${clean_old_env}" == "enable" ]]; then
   pyenv virtualenv-delete ${virtualenv_name}
fi
pyenv virtualenv ${lang_version} ${virtualenv_name}
${pip} install --upgrade pip
${pip} install -r requirements.txt  || { echo "安装依赖失败"; exit 1;  }

eval "$(pyenv virtualenv-init -)"
export PYENV_ROOT="/home/admin/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

pyenv activate ${virtualenv_name}
/home/admin/.pyenv/versions/${lang_version}/bin/venv-pack -o  envs.tar.gz
echo "安装虚拟环境完成"

mkdir build
zip -ry -q build/${app_name}-${BUILD_VERSION}.zip  ./*
上一篇下一篇

猜你喜欢

热点阅读