install python 3.6

来源:互联网 发布:书画频道软件下载 编辑:程序博客网 时间:2024/06/08 16:20

 I studied python many times before, but I never used it in my daily work, therefore, I want to study it and use it step by step.

Configuration: centos7.3   python 3.6.3

1. Install python  //thanks to the work ENV, I can't install it by yum.

https://www.python.org/downloads/release/python-363/

2. Upload the source to the server.

3.  unzip it: 

tar zxvf Python-3.6.3.tgz ./Python-3.6.3

cd Python-3.6.3

./configure --prefix=/usr/local/python36 --enable-shared --with-threads   

export LD_RUN_PATH=/usr/local/lib

make & make install

4. ln -s /usr/local/python36/bin/python3.6 /usr/bin/python

5. redirect the python in yum.

vi /usr/bin/yum 
update “#!/usr/bin/python” to #!/usr/bin/python2”,and save.

root@xxx:/usr/bin$ ls -al python*
lrwxrwxrwx  1 root root   33 Dec 20 21:45 python -> /usr/local/python36/bin/python3.6
lrwxrwxrwx. 1 root root    9 Jun 23 14:29 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Nov  6  2016 python2.7
lrwxrwxrwx. 1 root root    7 Jun 23 14:29 python-2.7.5 -> python2
-rwxr-xr-x  1 root root 1835 Nov  6  2016 python2.7-config
lrwxrwxrwx  1 root root   16 Jun 23 16:09 python2-config -> python2.7-config
lrwxrwxrwx  1 root root   14 Jun 23 16:09 python-config -> python2-config


6.

root@xxx:/data/sftp/mysftp/upload/Python-3.6.3$ python
Python 3.6.3 (default, Dec 20 2017, 19:40:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.





Issues I met:

1.

libpython3.6m.a(sysmodule.o):在函数‘_PySys_Init’中:
/data/sftp/mysftp/upload/Python-3.6.3/./Python/sysmodule.c:1945:对‘_Py_gitversion’未定义的引用
/data/sftp/mysftp/upload/Python-3.6.3/./Python/sysmodule.c:1945:对‘_Py_gitidentifier’未定义的引用
libpython3.6m.a(getversion.o):在函数‘Py_GetVersion’中:
/data/sftp/mysftp/upload/Python-3.6.3/Python/getversion.c:12:对‘Py_GetBuildInfo’未定义的引用
collect2: 错误:ld 返回 1
make: *** [python] 错误 1
libpython3.6m.a(sysmodule.o):在函数‘_PySys_Init’中:
/data/sftp/mysftp/upload/Python-3.6.3/./Python/sysmodule.c:1945:对‘_Py_gitversion’未定义的引用
/data/sftp/mysftp/upload/Python-3.6.3/./Python/sysmodule.c:1945:对‘_Py_gitidentifier’未定义的引用


Compile with --enable-shared will solve it.

2.

Fatal Python error: Py_Initialize: Unable to get the locale encoding
LookupError: unknown encoding: GB2312


by export LC_ALL=en_US.UTF-8 will solve it.


3. zipimport.ZipImportError: can't decompress data; zlib not available


download zlib and install it.
Please refers to http://blog.csdn.net/aflyeaglenku/article/details/49124467

$wget http://www.zlib.net/zlib-1.2.8.tar.gz
$tar -xvzf zlib-1.2.8.tar.gz
$cd zlib-1.2.8.tar.gz
$./configure
$make

$make install

vi ./Modules/Setup   
uncomment below lines:
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
Then re-install python.

4.

root@xxxx:/usr/bin$ ldd /usr/bin/python
        linux-vdso.so.1 =>  (0x00007ffe05943000)
        libpython3.6m.so.1.0 => not found
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb9656e8000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fb9654e4000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fb9652e1000)
        libz.so.1 => /lib64/libz.so.1 (0x00007fb9650ca000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fb964dc8000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fb964a07000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb965910000)













原创粉丝点击