1,398 views
Python开发

Linux下安装python3.6及django框架

文章目录

Linux下安装Python3.6和django框架

注意事项

如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,
比如yum!!!!!不要动现有的python2环境!
“`

安装python3.6


1. 安装依赖环境
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel


2.下载Python3
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz

3.安装python3
我个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
创建目录:
mkdir -p /usr/local/python3
tar -zxvf Python-3.6.2.tgz
cd Python-3.6.2
./configure –prefix=/usr/local/python3
make -j8 && make install -j8

4.建立python3的软链
ln -s /usr/local/python3/bin/python3 /usr/bin/python3

5.并将/usr/local/python3/bin加入PATH
vim ~/.bash_profile
.bash_profile
Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH

按ESC,输入:wq回车退出。
7.修改完记得执行行下面的命令,让上一步的修改生效:
source ~/.bash_profile

8.检查Python3及pip3是否正常可用:python3 -V 和pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
如果出现:Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS
需要安装
yum install openssl-devel -y
然后再执行./configure make makeinstall…..

安装django框架


pip3 install django

快速安装脚本


#!/bin/bash
tools="zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel net-tools wget "
yum -y install $tools
echo -e "\033[34m ----------1.安装完依赖包---------- \033[0m" 
py_version="3.6.5"
src_dir="/usr/local/src"
wget -P $src_dir https://www.python.org/ftp/python/$py_version/Python-$py_version.tgz
echo -e "\033[34m ----------2.下载完python安装包---------- \033[0m" 
mkdir -p /usr/local/python$py_version
cd $src_dir
tar -zxf Python-$py_version.tgz
cd $src_dir/Python-$py_version
./configure –prefix=/usr/local/python$py_version
make -j8 && make install -j8
echo -e "\033[34m ----------3.安装完python---------- \033[0m" 
ln -s /usr/local/python$py_version/bin/python3 /usr/bin/python3

cat > ~/.bash_profile<<-EOF
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
PATH=\$PATH:\$HOME/bin:/usr/local/python3.6.5/bin
export PATH
EOF

source ~/.bash_profile

python3 -V
pip3 -V
echo -e "\033[34m ----------4.结束安装---------- \033[0m" 

Leave a Reply

影子专属博客 赣ICP备17013143号