In this post, I will show you how to control the process of installing python from source code using pyenv, you can use environment variable to achieve this job.
When you want to install multiple python versions on your laptop or servers, you may choose to use
pyenv, which stands for
Python Version Management: pyenv.
But what if we want to use
pyenv to install specific version of python with custom configure options?
Here is the solution:
env PYTHON_MAKE_INSTALL_TARGET="altinstall" pyenv install -v 3.4.2
In the above command , we have done this job:
- We use
env PYTHON_MAKE_INSTALL_TARGET=xxxto set an environment variable named
PYTHON_MAKE_INSTALL_TARGETto set our custom configure option to be used to build our python installation.
- Then use
pyenv install -v xxxxto install specific python version.
After setup the above command, we have tell the machine to install python as follows:
configure make altinstall
What is the difference between the
make altinstall and
make install. The
altinstall skips creating the
python link and the manual pages links,
install will hide the system binaries and manual pages.
Here we should learn more about the
PYTHON_MAKE_INSTALL_TARGET environment, Here is the full list of environment variables that you can use to control the build process when using pyenv to install python from source:
TMPDIR sets the location where python-build stores temporary files. PYTHON_BUILD_BUILD_PATH sets the location in which sources are downloaded and built. By default, this is a subdirectory of TMPDIR. PYTHON_BUILD_CACHE_PATH, if set, specifies a directory to use for caching downloaded package files. PYTHON_BUILD_MIRROR_URL overrides the default mirror URL root to one of your choosing. PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM, if set, does not append the SHA2 checksum of the file to the mirror URL. PYTHON_BUILD_SKIP_MIRROR, if set, forces python-build to download packages from their original source URLs instead of using a mirror. PYTHON_BUILD_SKIP_HOMEBREW, if set, will not search for libraries installed by Homebrew on macOS. PYTHON_BUILD_ROOT overrides the default location from where build definitions in share/python-build/ are looked up. PYTHON_BUILD_DEFINITIONS can be a list of colon-separated paths that get additionally searched when looking up build definitions. CC sets the path to the C compiler. PYTHON_CFLAGS lets you pass additional options to the default CFLAGS. Use this to override, for instance, the -O3 option. CONFIGURE_OPTS lets you pass additional options to ./configure. MAKE lets you override the command to use for make. Useful for specifying GNU make (gmake) on some systems. MAKE_OPTS (or MAKEOPTS) lets you pass additional options to make. MAKE_INSTALL_OPTS lets you pass additional options to make install. PYTHON_CONFIGURE_OPTS and PYTHON_MAKE_OPTS and PYTHON_MAKE_INSTALL_OPTS allow you to specify configure and make options for building CPython. These variables will be passed to Python only, not any dependent packages (e.g. libyaml).
In this post, I demonstrated how to control the build process of python installation using pyenv. That’s it, thanks for your reading.