安装python3

    xiaoxiao2022-07-03  113

    mac安装

    mac自带python2版本,python3新技能不能使用 1、安装homebrew(传说这是个mac安装神器),输入下面命令即可

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    安装成功后如下提示: 2、安装python3 brew search 应用,搜索是否可安装

    brew search python3

    brew install 应用,直接安装

    brew install python3

    安装成功如下提示: 注意这个安装路径,是映射过的,直接是进不去的,为啥呢? bogon:bin didi$ cd /usr/local/bin/python3 -bash: cd: /usr/local/bin/python3: Not a directory 进入/usr/local/bin/,ls -al查看详情,/usr/local/Cellar/python/3.7.3/bin/python3.7才是真实的路径

    3、配置环境变量 执行python发现环境默认仍是python2,需要我们配置 打开配置文件,加上python3的path

    vim ~/.bash_profile

    重命名并生效

    alias python="/usr/local/Cellar/python/3.7.3/bin/python3.7" source ~/.bash_profile

    OK。done

    Linux安装

    安装gcc

    yum -y install gcc

    安装其它工具

    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 libffi-devel

    下载python包

    wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

    创建目录存放python3安装路径,并将安装包解压到此目录

    mkdir /usr/local/python3 tar -zxvf Python-3.7.0.tgz

    编译、安装

    cd Python-3.7.0 ./configure --prefix=/usr/local/python3 make && make install

    没有错误则表示安装成功。 遇到报错如下:

    ModuleNotFoundError: No module named '_ctypes' make: *** [install] Error 1

    解决:

    yum install libffi-devel -y

    执行完后,再重新make install。

    如果上面执行了依旧不OK,那么重新来

    make clean ./configure --prefix=/usr/local/python3 make make install

    安装完后建立软连接

    ln -s /usr/local/python3/bin/python3.7 /usr/local/bin/python ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip

    /usr/local/bin/python为原来系统的软连接,需先将其删除再建,这样执行python时出来的就是python3不是2了

    最新回复(0)