linux使用笔记

精简版本CENTEROS7 没有ifconfig
yum provides ifconfig --发现是少了哪一个包 然后
yum install net-tool --安装成功
centerOS 7.5 安装 Python3.8,最新版安装地址可以FQ出去下载然后拷贝到目录

如果没有wget yum install wget

1、 查看当前系统中Python版本

python --version(或 python -V): 查看当前python版本
# 返回Python 2.x.x 版本

2、查看centerOS版本

cat /etc/readhat -release
# 返回:CentOS Linux release 7.5.1804 (Core) 

3、安装所有的开发包

yum groupinstall -y "Development tools"

4、安装其他必须包

yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

5、创建安装目录

mkdir /usr/local/python3

6、下载,编译和安装Python 3.7.0

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

# 移动文件,并进入python3文件夹
mv Python3.7.0.tgz /usr/local/python3

# 解压,进入python-3.7.0文件夹
tar zxf Python-3.7.0.tgz

# 默认安装在usr/local/bin下,这里这指定当前目录
./configure --prefix=/usr/local/python3

# 编译和安装
make && make install

7、默认Python3.7.0 会安装在usr/local/bin下,自带的版本在/usr/bin下,查看。

# 查看新版
ll -tr /usr/local/bin/python*

# 查看原版
ll -tr /usr/bin/python*

更改系统默认版本

# 更改系统默认旧版本名称
mv /usr/bin/python /usr/bin/python.old

# 再删除系统默认的 python-config 软链接
rm -f /usr/bin/python-config

# 创建新版本软连接
ln -s /usr/local/bin/python /usr/bin/python
ln -s /usr/local/bin/python-config /usr/bin/python-config
ln -s /usr/local/include/python3.7/ /usr/include/python3.7

9、查看新版本

python3 -V
# 返回:Python 3.7.0

pip类似RedHat里面的yum,安装Python包非常方便。本节详细介绍pip的安装、以及使用方法

1、下载pip安装包

[root@localhost ~]# wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9

2、解压pip安装包

[root@localhost ~]# tar xf pip-9.0.1.tar.gz 

3、安装pip

[root@localhost ~]# cd pip-9.0.1
[root@localhost pip-9.0.1]# python3 setup.py install

4、pip使用详解

  • pip安装模块报错,提示没有ssl模块

    [复制代码](javascript:void(0)😉

    [root@localhost ipython-6.1.0]# pip install traitlets
    pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    Collecting traitlets
    Could not fetch URL https://pypi.python.org/simple/traitlets/: 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 traitlets (from versions: )
    No matching distribution found for traitlets
    #没有安装openssl-devel,然后重新编译安装python3.6
    [root@localhost pip-9.0.1]# yum install openssl-devel -y#进入python3.6解压包目录
    [root@localhost Python-3.6.1]#make clean
    [root@localhost Python-3.6.1]# ./configure 
    [root@localhost Python-3.6.1]# make && make install
    
    

    [复制代码](javascript:void(0)😉

  • 安装openssl-devel并重新编译安装python3后,再次测试pip安装模块

    [复制代码](javascript:void(0)😉

    [root@localhost ~]# pip install 'traitlets'
    Collecting traitlets
      Downloading traitlets-4.3.2-py2.py3-none-any.whl (74kB)
        100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 81kB 87kB/s 
    Collecting six (from traitlets)
      Downloading six-1.10.0-py2.py3-none-any.whl
    Collecting ipython-genutils (from traitlets)
      Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl
    Collecting decorator (from traitlets)
      Downloading decorator-4.0.11-py2.py3-none-any.whl
    Installing collected packages: six, ipython-genutils, decorator, traitlets
    Successfully installed decorator-4.0.11 ipython-genutils-0.2.0 six-1.10.0 traitlets-4.3.2
    #安装成功
    
    

    [复制代码](javascript:void(0)😉

  • pip uninstall Package:卸载模块

    [root@localhost pip-9.0.1]# pip uninstall traitlets
    Uninstalling traitlets-4.3.2:
    ......
    packages/traitlets/utils/tests/test_importstring.py
    Proceed (y/n)? y       
      Successfully uninstalled traitlets-4.3.2
    
    
  • pip freeze:按需求格式输出已安装的模块

    [复制代码](javascript:void(0)😉

    [root@localhost pip-9.0.1]# pip freeze
    decorator==4.0.11
    ipython==6.1.0
    ipython-genutils==0.2.0
    pexpect==4.2.1
    ptyprocess==0.5.2
    Pygments==2.2.0
    six==1.10.0
    traitlets==4.3.2
    
    

    [复制代码](javascript:void(0)😉

  • pip list --format=(legacy|columns):安装指定格式输出已安装的模块;和pip freeze类似

    [复制代码](javascript:void(0)😉

    [root@localhost pip-9.0.1]# pip list --format=legacy
    decorator (4.0.11)
    ipython (6.1.0)
    ipython-genutils (0.2.0)
    pexpect (4.2.1)
    pip (9.0.1)
    ptyprocess (0.5.2)
    Pygments (2.2.0)
    setuptools (28.8.0)
    six (1.10.0)
    traitlets (4.3.2)
    [root@localhost pip-9.0.1]# pip list --format=columns
    Package          Version
    ---------------- -------
    decorator        4.0.11 
    ipython          6.1.0  
    ipython-genutils 0.2.0  
    pexpect          4.2.1  
    pip              9.0.1  
    ptyprocess       0.5.2  
    Pygments         2.2.0  
    setuptools       28.8.0 
    six              1.10.0 
    traitlets        4.3.2 
    
    

    [复制代码](javascript:void(0)😉

  • pip show Package:显示已安装的模块信息

    [复制代码](javascript:void(0)😉

    [root@localhost pip-9.0.1]# pip show traitlets
    Name: traitlets
    Version: 4.3.2
    Summary: Traitlets Python config system
    Home-page: http://ipython.org
    Author: IPython Development Team
    Author-email: ipython-dev@scipy.org
    License: BSD
    Location: /usr/local/lib/python3.6/site-packages
    Requires: ipython-genutils, six, decorator
    
    

    [复制代码](javascript:void(0)😉

  • pip -h:余下的选项可以通过-h查看,这里不做过多介绍

    [复制代码](javascript:void(0)😉

    [root@localhost pip-9.0.1]# pip -h
    
    Usage:   
      pip <command> [options]
    
    Commands:
      install                     Install packages.
      download                    Download packages.
      uninstall                   Uninstall packages.
      freeze                      Output installed packages in requirements format.
      list                        List installed packages.
      show                        Show information about installed packages.
      check                       Verify installed packages have compatible dependencies.
      search                      Search PyPI for packages.
      wheel                       Build wheels from your requirements.
      hash                        Compute hashes of package archives.
      completion                  A helper command used for command completion.
      help                        Show help for commands.
    
    General Options:
      -h, --help                  Show help.
      --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
      -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
      -V, --version               Show version and exit.
      -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
      --log <path>                Path to a verbose appending log.
      --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
      --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
      --timeout <sec>             Set the socket timeout (default 15 seconds).
      --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
      --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
      --cert <path>               Path to alternate CA bundle.
      --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
      --cache-dir <dir>           Store the cache data in <dir>.
      --no-cache-dir              Disable the cache.
      --disable-pip-version-check
                                  Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
    
    

    [复制代码](javascript:void(0)😉

通过压缩包安装ipython

1、下载ipython安装包

[root@localhost ~]# wget https://pypi.python.org/packages/79/63/b671fc2bf0051739e87a7478a207bbeb45cfae3c328d38ccdd063d9e0074/ipython-6.1.0.tar.gz#md5=1e15e1ce3f3f722da6935d7ac0e51346

2、安装ipython

[复制代码](javascript:void(0)😉

[root@localhost ~]# tar xf ipython-6.1.0.tar.gz
[root@localhost ~]# cd ipython-6.1.0
[root@localhost ipython-6.1.0]# pwd
/root/ipython-6.1.0
[root@localhost ipython-6.1.0]# python3 setup.py install
#前提已安装python3,
#linux系统安装python3: http://www.cnblogs.com/chengd/p/7078498.html

[复制代码](javascript:void(0)😉

3、通过pip安装ipython所有缺失模块,直至ipython运行成功

[复制代码](javascript:void(0)😉

[root@localhost ~]# ipython
Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 4, in <module>
    from IPython import start_ipython
  File "/usr/local/lib/python3.6/site-packages/IPython/__init__.py", line 54, in <module>
    from .core.application import Application
  File "/usr/local/lib/python3.6/site-packages/IPython/core/application.py", line 23, in <module>
    from traitlets.config.application import Application, catch_config_error
ModuleNotFoundError: No module named 'traitlets'
#运行ipython是提示缺少'traitlets'模块;
#安装提示一步步通过pip安装缺失模块
[root@localhost ~]# pip install 'traitlets'
Collecting traitlets
  Downloading traitlets-4.3.2-py2.py3-none-any.whl (74kB)
    100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 81kB 87kB/s 
Collecting six (from traitlets)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting ipython-genutils (from traitlets)
  Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting decorator (from traitlets)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: six, ipython-genutils, decorator, traitlets
Successfully installed decorator-4.0.11 ipython-genutils-0.2.0 six-1.10.0 traitlets-4.3.2......

[复制代码](javascript:void(0)😉

二、直接通过pip安装ipython

pip安装地址:http://www.cnblogs.com/chengd/p/7078588.html

[复制代码](javascript:void(0)😉

[root@localhost pip-9.0.1]# pip install ipython
[root@localhost pip-9.0.1]# ipython
ipython   ipython3  
[root@localhost pip-9.0.1]# ipython3
/usr/local/lib/python3.6/site-packages/IPython/core/history.py:226: UserWarning: IPython History requires SQLite, your history will not be saved
  warn("IPython History requires SQLite, your history will not be saved")
Python 3.6.1 (default, Jun 26 2017, 09:16:04) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: #ipython安装成功

[复制代码](javascript:void(0)😉

安装python3之后,yum用不了

使用centos 安装python3,并默认python3为python版本之后,用不了yum

原因是yum依赖于python2组件

解决方法:

vi /usr/bin/yum 和 vi /usr/libexec/urlgrabber-ext-down在第一行将python改为python2.7

#!/usr/bin/python2.7  

https://www.cnblogs.com/chengd/p/7078639.html##安装ipython

posted on 2019-12-19 04:25  土豆爸  阅读(213)  评论(0编辑  收藏  举报

导航