python3安装
python3 安装
##yum 安装python
yum install -y python36
##可以添加软连接 此命令不对,应该是绝对路径 ln -s python3.6 python3
##备份原来得python命令,应该为软连接
mv /usr/bin/python /usr/bin/python.bak
##重定向python到python3
ln -s /usr/bin/python3.6 /usr/bin/python
##修改yum使用得python 命令,yum 会使用python2
把#! /usr/bin/python修改为#! /usr/bin/python2
sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/bin/yum
把#! /usr/bin/python 修改为#! /usr/bin/python2
sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/libexec/urlgrabber-ext-down
##安装pip3
1. 安装easy_install
注意安装与以上python版本相同的setuptools
yum install -y python36-setuptools
2. 安装pip
安装之后,pip3位于/usr/local/bin目录下
python -V
CentOS 7编译安装python3
参考:https://blog.csdn.net/lovefengruoqing/article/details/79284573
#python 在哪
[root@root ~]# whereis python
# cd /usr/bin/
# ll python*
##下载编译python3的工具依赖环境
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
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
3.默认的,centos7也没有安装pip
#运行这个命令添加epel扩展源
yum -y install epel-release
#安装pip
yum install python-pip
4.用pip装wget
pip install wget
5.用wget下载python3的源码包下载地址https://www.python.org/downloads/
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
6.编译python3源码包
#解压
xz -d Python-3.6.4.tar.xz
tar -xfC Python-3.6.4.tar
#进入解压后的目录,依次执行下面命令进行手动编译
./configure prefix=/usr/local/python3
make && make install
7.添加软链接
#将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
#添加python3的软链接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
#测试是否安装成功了
python -V
8.更改yum配置,因为其要用到python2才能执行,否则会导致yum不能正常使用
vi /usr/bin/yum
把#! /usr/bin/python修改为#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
把#! /usr/bin/python 修改为#! /usr/bin/python2
##将命令添加到
jupyter 安装
2 wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
7 yum install bzip2
8 sh Anaconda3-5.3.1-Linux-x86_64.sh -u
12 cd anaconda3/
17 cd /root/anaconda3/
24 bin/jupyter-notebook --generate-config
25 cat /root/.jupyter/jupyter_notebook_config.py
26 vi /root/.jupyter/jupyter_notebook_config.py
30 export PATH=/root/anaconda3/bin:$PATH
31 ipython
32 vim ~/.jupyter/jupyter_notebook_config.py
grep -v "^#" ~/.jupyter/jupyter_notebook_config.py | grep -v "^$"
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:45b05f890fb6:3eaac1d849150baf87598a40f5aba6ef0634fa81'
c.NotebookApp.port = 8888
jupyter 起服务脚本
mkdir /data
vi python_service.py
#!/usr/bin/env python
# encoding: utf-8
import subprocess
import sys
subprocess.call("cd /", shell=True)
subprocess.call("jupyter lab --ip=0.0.0.0 --no-browser --allow-root --NotebookApp.token='jupyterAdmin' --notebook-dir=/data", shell=True)
ROM centos:7
MAINTAINER yon@xxxx.com
ENV JAVA_HOME /usr/local/jdk
ENV JRE_HOME ${JAVA_HOME}/jre
ENV CLASSPATH .:${JAVA_HOME}/lib/tools.jar:${JRE_HOME}/lib/dt.jar
ENV PATH ${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:$PATH
ADD jdk-8u152-linux-x64.tar.gz /usr/local
RUN ln -s /usr/local/jdk1.8.0_152 /usr/local/jdk
RUN mkdir /home/xxxx/insight/log -p && mkdir /home/xxxx/insight/jar -p
EXPOSE 9030
COPY exec-entrypoint.sh /
RUN chmod +x /exec-entrypoint.sh
COPY insight-service-appmarket-5.0.0-SNAPSHOT.jar /home/xxxx/insight/jar
CMD ["sh","/exec-entrypoint.sh"]
ubuntu1604 安装python3
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
pip安装
#离线
1.制作requirement.txt
pip freeze > requirement.txt
2,离线下载安装包
下载单个离线包 - pip download -d your_offline_packages <package_name>
批量下载离线包 - pip download -d your_offline_packages -r requirements.txt
离线安装
安装单个离线包 - pip install --no-index --find-links=/your_offline_packages/ package_name
批量安装离线包 - pip install --no-index --find-links=/your_offline_packages/ -r requirements.txt
pip install Numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
安装python dockerfile
FROM centos:7
# 默认使用Python3.6
MAINTAINER cnm
#镜像源
RUN yum install -y wget && rm -rf /etc/yum.repos.d/* \
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo \
&& sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/* \
&& yum clean all && yum makecache \
&& yum install -y unzip bzip2 make wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc libicu-devel gcc-c++ \
&& yum clean all
# 解决时区问题
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
# 解决中文乱码问题
#RUN yum install kde-l10n-Chinese -y
ENV LANG zh_CN.uft8
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.UFT-8 \
&& echo 'LANG="zh_CN.uft8"' > /etc/locale.conf \
&& source /etc/locale.conf
##################安装Python3.5使用########################################################################################
#RUN wget -O /usr/local/src/Python-3.5.5.tar.xz https://www.python.org/ftp/python/3.5.5/Python-3.5.5.tar.xz \
# && cd /usr/local/src/ && xz -d Python-3.5.5.tar.xz && tar -xf Python-3.5.5.tar && rm -rf Python-3.5.5.tar \
# && cd /usr/local/src/Python-3.5.5 && ./configure prefix=/usr/local/python3 && make && make install
#
#RUN mv /usr/bin/python /usr/bin/python.bak \
# && ln -s /usr/local/python3/bin/python3.5 /usr/bin/python && rm -rf /usr/bin/pip* \
# && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 \
# && ln -s /usr/bin/pip3 /usr/bin/pip
#
#RUN sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/bin/yum \
# && sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/libexec/urlgrabber-ext-down
##安装pip包
#COPY ./requirements /
#RUN pip install -U pip==19.1.1 && pip3 install -i https://pypi.douban.com/simple/ -r /requirements
#RUN pip install tensorflow==1.11.0 mysql-connector-python-rf scikit-image dataclasses
##################安装Python3.5结束#######################################################################################
##################安装Python3.6使用########################################################################################
RUN yum install -y python36 python36-devel
##安装依赖包
COPY ./requirements /
RUN pip3 install -U pip==19.1.1 && pip3 install -i https://pypi.douban.com/simple/ -r /requirements
RUN pip3 install tensorflow==1.11.0 mysql-connector-python-rf==2.2.1 scikit-image dataclasses
##################安装Python3.6结束########################################################################################
#################python3.7###################################################################################################
# 安装python37
RUN yum -y install make wget \
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo \
&& sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/* \
&& yum clean all && yum makecache
RUN yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc libffi-devel
RUN wget -O /usr/local/src/Python-3.7.3.tar.xz https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
RUN cd /usr/local/src/ && xz -d Python-3.7.3.tar.xz && tar -xf Python-3.7.3.tar \
&& cd /usr/local/src/Python-3.7.3 && ./configure prefix=/usr/local/python3 && make && make install
RUN mv /usr/bin/python /usr/bin/python.bak \
&& ln -s /usr/local/python3/bin/python3.7 /usr/bin/python && rm -rf /usr/bin/pip* \
&& ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 \
&& ln -s /usr/bin/pip3 /usr/bin/pip
RUN sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/bin/yum \
&& sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/libexec/urlgrabber-ext-down
#####################################################################################################################################################