josephxsxn

Make Python From Source

Jul 15th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 KB | None | 0 0
  1. I ran into a situation where I needed to use Python3 rather then Python 2.7 so I cooked up a Makefile so I could do it whenever I needed to again. This way I can keep my older Python installs and not break some Linux packages as I can refer to my new alias python3 at the command-line while still being able to call python at any time for older versions.
  2.  
  3. It should work on any YUM or APT-GET based Linux OS, Tested it on Centos6 and Ubuntu14.
  4.  
  5. Changing the value of PYTHON_BRANCH lets you pull down any specific branch from the cPython GitHub (latest as of writing this is 3.5), changing the value of CORES to be -j4, or -j8 lets you use more cores when compiling from source (4 cores, and 8 cores respectively.)
  6.  
  7. Enjoy.
  8.  
  9. #NEED PYTHON 3
  10. PYTHON_BRANCH=3.4
  11. CORES=-j2
  12. YUM=$(shell which yum)
  13. APT=$(shell which apt-get)
  14. TOOLS=git gcc
  15. INSTALL_ROOT:=$(shell echo $$PWD/dist/)
  16.  
  17. git:
  18. ifneq ($(YUM),)
  19.     which $(TOOLS) || yum -y install git \
  20.     gcc gcc-c++ \
  21.     zlib-devel openssl-devel
  22. endif
  23. ifneq ($(APT),)
  24.     which $(TOOLS) || apt-get install -y git gcc g++ man zlib1g-dev libssl-dev
  25. endif
  26.  
  27. python-src:
  28.     git clone --branch $(PYTHON_BRANCH) https://github.com/python/cpython.git python3
  29.    
  30. python-build:
  31.     (cd python3/; \
  32.     ./configure; \
  33.     make -s $(CORES); \
  34.     make -s $(CORES) altinstall)
  35.  
  36. install: git python-src python-build
Advertisement
Add Comment
Please, Sign In to add comment