linux ubuntu环境下的python环境搭建

本文详细介绍了如何在Ubuntu操作系统中搭建Python环境,适合个人使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ubuntu环境下的python环境搭建

个人使用环境搭建;

sudo apt-get install -y gcc make cmake build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
#!/usr/bin/env bash
echo "deploy packaging environment for linux"
script=$(dirname "$PWD")

ca=$(dirname "$script")
server=$ca/server


# 添加apt源
if [ -f /etc/apt/sources.list ];then
  mv /etc/apt/sources.list /etc/apt/sources_list.bak
fi

cat <<EOF > /etc/apt/sources.list
deb http://172.29.100.191:8081/repository/ubuntu/ bionic main restricted universe multiverse
deb-src http://172.29.100.191:8081/repository/ubuntu/ bionic main restricted universe multiverse
deb http://172.29.100.191:8081/repository/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://172.29.100.191:8081/repository/ubuntu/ bionic-security main restricted universe multiverse
deb http://172.29.100.191:8081/repository/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://172.29.100.191:8081/repository/ubuntu/ bionic-updates main restricted universe multiverse
deb http://172.29.100.191:8081/repository/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://172.29.100.191:8081/repository/ubuntu/ bionic-backports main restricted universe multiverse
deb http://172.29.100.191:8081/repository/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://172.29.100.191:8081/repository/ubuntu/ bionic-proposed main restricted universe multiverse
EOF

# 编译python前,安装需要的包
sudo apt-get install -y build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev libffi-dev tk-dev libssl-dev openssl zip
sudo apt install -y sqlite3 sqlite3.dev

echo 'compile pyton 3.7'
cp $server'/resource/Python-3.7.3.tgz' /tmp/

tar -xvJf  Python-3.7.4.tar.xz
cd Python-3.7.4
# --with-ssl pip支持openssl
# 二选一, enable-optimizations 和 enable-shared不能同时使用
./configure --prefix=/usr/local/python3 --with-ssl --enable-optimizations
./configure --prefix=/usr/local/python3 --with-ssl --enable-shared
make && make install

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

echo 加载编译的python3.7
if [ -d '/etc/ld.so.conf.d/' ]; then
  cd /etc/ld.so.conf.d/
  echo '/usr/local/lib' > python3.conf
  # 写入 /usr/local/lib 保存
  ldconfig
fi

# 若无pip 可自行安装
echo 安装pip3
sudo apt install -y python3-pip
echo 安装python3开发包
sudo apt install -y python3-dev
echo 安装pyinstaller
sudo pip3 install -y pyinstaller

echo 添加pip源
mkdir ~/.pip/
cat <<EOF > ~/.pip/pip.conf
[global]
index-url = http://172.29.100.191:8081/repository/pip/simple/

[install]
trusted-host=172.29.100.191
EOF

cd $ca
echo 安装项目依赖包
pip3 install -r requirements.txt

# 将ca/script/build/build.sh脚本里的pyinstaller路径和python3.7路径替换成当前的
pyinstaller_path=$(whereis pyinstaller)

#cd $script/build/
#sed -i 's/pyinstaller=/$pyinstaller_path/g' build_linux.sh
#sed -i 's/pyinstaller=/$pyinstaller_path/g' build_linux.sh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值