Friday, July 27, 2018

change yum source to SJTU

edit this file, /etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

Wednesday, February 7, 2018

Useful Python Modules

There are many useful python in Pypi that you need to download. I will write some of them below.

pyperclip -- A cross-platform clipboard module for Python. (only handles plain text for now)

Tuesday, February 6, 2018

can't decompress data; zlib not available

When I tried to run this python but encountered the following error.
# python get-pip.py           
Traceback (most recent call last):
  File "get-pip.py", line 20061, in
    main()
  File "get-pip.py", line 194, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip
zipimport.ZipImportError: can't decompress data; zlib not available

ENV: Python 3.5.2 + CentOS 7.4

Resolution: 


1. Install Zlib module
# yum -y install zlib*
# rpm -qa |grep -i zlib
zlib-1.2.7-17.el7.i686
zlib-static-1.2.7-17.el7.x86_64
zlib-1.2.7-17.el7.x86_64
perl-Compress-Raw-Zlib-2.061-4.el7.x86_64
zlib-devel-1.2.7-17.el7.x86_64

2. Modify the source installation file
vi /Modules/Setup

# Andrew Kuchling's zlib module.
# This require zlib 1.1.3 (or later).
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

3. Finally, you need to compile the python again.
# make & make install

4. Try to run the python CMD again.

Install FileZilla on CentOS 7

FileZilla is Arguably the most Popular FTP Client in the world. Also, it is a free and Cross platform Support FTP Client which can be installed on both Linux and Windows Operating Systems. 

Filezilla Does not come with the default CentOS Repository, So we will use fedora epel repository instead. Installation is very simple, All we have to do is first install CentOS epel Repository and then Install Filezilla with yum command.

1. Install epel repository
yum -y install epel-release

2. Install filezilla
yum -y install filezilla

3. After the Installation is Finished, Go to Application > Internet Then open Filezilla.

How to install pip with Python 3 on CentOS?

The manual way

Install pip
To install pip, securely download get-pip.py
Then run the following (which may require administrator access):
python get-pip.py 
If setuptools is not already installed, get-pip.py will install setuptools for you.

As two version (python 2.7 & python 3.5) can be found on my machine, the CMD I need to run is 

pip3

Reference: https://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3

Can't connect to HTTPS URL because the SSL module is not available.


Try to run python but encountered this error:

[root@nbu773srv1 tmp]# python3 get-pip.py 
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Requirement already up-to-date: pip in /usr/local/lib/python3.7/site-packages
Collecting wheel
  Could not fetch URL https://pypi.python.org/simple/wheel/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement wheel (from versions: )
No matching distribution found for wheel

ENV: Python 3.7 + CentOS 7.4

Resolution:

1. Please confirm if you can find openssl & openssl-devel rpm from OS.
# rpm -qa |grep openssl
openssl-libs-1.0.2k-8.el7.x86_64
openssl-1.0.2k-8.el7.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64

2. Install openssl-devel using yum
# yum install openssl-devel.x86_64 

Then check the result:
# rpm -qa |grep openssl
openssl-libs-1.0.2k-8.el7.x86_64
openssl-1.0.2k-8.el7.x86_64
openssl-devel-1.0.2k-8.el7.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64

3. Modify the source installation file
vi /Modules/Setup
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

4. Finally, you need to compile the python again.
# make & make install

5. Now, you can use ssl in python 3.
[root@nbu773srv1 tmp]# python3
Python 3.7.0a4 (default, Feb  6 2018, 13:44:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl

Friday, February 2, 2018

Upgrading Python on Linux


1. check the current Python Version
#python -V
or
#python --version
2. Download Python from FTP, https://www.python.org/ftp/python/
3. unzip the tar.gz file
#tar -xvf Python-3.7.0a4.tgz

4. Install gcc++ compilar if needed.
#rpm -qa |grep gcc
#yum install make gcc gcc-c++
#rpm -qa |grep gcc
libgcc-4.8.5-16.el7_4.1.x86_64
gcc-4.8.5-16.el7_4.1.x86_64
gcc-c++-4.8.5-16.el7_4.1.x86_64
5. Confiure it
# cd /Python-3.7.0a4
#./configure
6. Compile it
#./make & make install
7. Now you can access Python 3.7
#python3
8. You also can change the symbolic link for python
#mv /usr/bin/python /usr/bin/python.bak
#ln -s /usr/local/bin/python3 /usr/bin/python
     You also have to change the followings as you have change the default path for python.
# vi /usr/bin/yum
#vi /usr/libexec/urlgrabber-ext-down
Change " #!/usr/bin/python" into "#!/usr/bin/python2"

Now you have upgraded python successfully. You can input "python" to access python 3 and input "python2" to access python 2.

You may encounter the following error when compile the file.
ERROR 1:
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
Solutions: #yum install zlib*

ERROR 2:
ModuleNotFoundError: No module named '_ctypes'
make: *** [install] Error 1
# rpm -qa |grep libffi
libffi-3.0.13-18.el7.x86_64
[root@nbu773srv1 Python-3.7.0a4]# yum list |grep libffi
libffi.x86_64                               3.0.13-18.el7              @anaconda
libffi.i686                                 3.0.13-18.el7              base    
libffi-devel.i686                           3.0.13-18.el7              base    
libffi-devel.x86_64                         3.0.13-18.el7              base    
Solutions: #yum install libffi-devel.x86_64

change yum source to SJTU

edit this file, /etc/yum.repos.d/CentOS-Base.repo # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client ...