Linux安装Python3
安装必要包
sudo yum install -y zlib-devel
sudo yum install -y bzip2-devel
sudo yum install -y openssl-devel
sudo yum install -y ncurses-devel
sudo yum install -y sqlite-devel
sudo yum install -y readline-devel
sudo yum install -y tk-devel
sudo yum install -y libffi-devel
sudo yum install -y gcc
sudo yum install -y make
下载和安装
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
tar -zxvf **.gz
# 检查本机的字符集编码,若不是utf8,则临时声明为utf8
# 否则会报错LookupError: unknown encoding: GBK
export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN.UTF-8
# --enable-optimizations 编译启动优化,会提高python速度,需要高版本gcc
# --enable-optimizations --with-ssl
./configure --prefix=/app/python39
make && make install
配置环境变量
ln -s /app/python39 /app/python
# 修改PYTHON_HOME和PYTHONPATH
pip安装库
- 首先修改国内源
linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
- 安装其他包示例
pip3 install pymysql sqlalchemy configparser
- 若要使用pyspark,需要安装下面的包
pip3 install pyspark findspark