1. 程式人生 > >python3、ipython3、setup-tools、pip等環境搭建詳細總結

python3、ipython3、setup-tools、pip等環境搭建詳細總結

python

第一個python腳本:

[[email protected] ~]# cat helloworld.py

print("hello world")

[[email protected] ~]# python helloworld.py

hello world

安裝python3ipython整體環境,非常麻煩,不註意會經常報錯,安裝不成功,折騰了一天才搞定,流程記錄如下:

第一步:安裝python3.5

1CentOS6.5 安裝Python 的依賴包

yum groupinstall "Development tools"
yum 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.5的源碼包並編譯

wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
tar xf Python-3.5.0.tgz
cd Python-3.5.0
./configure --prefix=/application/python --enable-shared
make
make install
ln –s /application/python/bin/python3 /usr/bin/python3

3、在運行Python之前需要配置庫:

echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
ldconfig

4、運行演示:

python3 --version
Python 3.5.0

5、刪除編譯Python時所需要的庫,當然也可以不刪

yum groupremove "Development tools" --remove-leaveas
yum remove zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel --remove-leaves

6、設置別名方便使用,也可以不用設置

alias py=python3

第二步:安裝ipython3

1、需要安裝setup-tools

地址:https://pypi.python.org/pypi/setuptools

解壓 unzip setuptools-36.5.0.zip

cd setuptools-36.5.0

/application/python/bin/python3 setup.py install

2、安裝pip

地址:https://pypi.python.org/pypi/pip

tar xf pip-9.0.1.tar.gz

cd pip-9.0.1

/application/python/bin/python3 setup.py install

此時會在/application/python/bin下生成一個名為pip pip3 pip3.5的幾個文件夾,說明pip模塊已經打包進入了python環境。

3、安裝python-setuptoolspython-setuptools-devel

通過yum install安裝即可

4、安裝ipython

地址:https://pypi.python.org/pypi/ipython

tar xf ipython-6.0.0.tar.gz

cd ipython-6.0.0

/application/python/bin/python3 setup.py install

5、配置軟鏈接或加入系統環境變量

ln -s /application/python/bin/python3 /usr/bin/python3

ln -s /application/python/bin/ipython3 /usr/bin/ipython3

ln -s /application/python/bin/ipython /usr/bin/ipython


python3、ipython3、setup-tools、pip等環境搭建詳細總結