默认编译安装的python3 , 是不带setuptools工具的, 导致pip 无法使用,以及无法安装第三方python 库。以下为安装方法。
下载python3 源码包
安装zlib和bz2 openssl openssl-devel openssl-static
yum install zlib zlib-devel bzip2 bzip2-devel openssl openssl-devel openssl-static
编译安装
./configure
make & make install
从官网下setuptools的安装包zip
https://pypi.python.org/pypi/setuptools
下载ez_setup.py
https://pypi.python.org/pypi/ez_setup
修改ez_setup 由于其使用网络从官网下载setuptools的安装包,离线环境无法下载。
故需要做的就是修改ez_setup.py文件,将其中从网络下载的部分改为直接读取本地文件,也就是
刚才下载的setuptools的zip安装包。
"""
Setuptools bootstrapping installer.
Run this script to install or upgrade setuptools.
"""
import os
import shutil
import sys
import tempfile
import zipfile
import optparse
import subprocess
import platform
import textwrap
import contextlib
import warnings
from distutils import log
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
try:
from site import USER_SITE
except ImportError:
USER_SITE = None
DEFAULT_VERSION = "18.3.1"
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
DEFAULT_SAVE_DIR = os.curdir
def _python_cmd(*args):
"""
Execute a command.
Return True if the command succeeded.
"""
args = (sys.executable,) + args
return subprocess.call(args) == 0
def _install(archive_filename, install_args=()):
"""Install Setuptools."""
with archive_context(archive_filename):
# installing
log.warn('Installing Setuptools')
if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
# exitcode will be 2
return 2
def _build_egg(egg, archive_filename, to_dir):
"""Build Setuptools egg."""
with archive_context(archive_filename):
# building an egg
log.warn('Building a Setuptools egg in %s', to_dir)
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
# returning the result
log.warn(egg)
if not os.path.exists(egg):
raise IOError('Could not build the egg.')
class ContextualZipFile(zipfile.ZipFile):
"""Supplement ZipFile