Linux安装Python3

Linux安装Python3

安装必要包

sudo yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc 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

./configure --prefix=/app/python39

make && make install

配置环境变量

ln -s /app/python39 /app/python
修改PYTHON_HOME和PYTHONPATH

pip安装库

  1. 首先修改国内源
    linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
  1. 安装其他包示例
pip3 install pymysql sqlalchemy configparser
  1. 若要使用pyspark,需要安装下面的包
pip3 install pyspark findspark

参考文档

https://blog.csdn.net/xiemanR/article/details/85224230

上一篇:nginx优化之nginx配置php-fpm


下一篇:ROS 手册