others-how to use pyenv to installl python from local file(offline)?

1. Purpose

In this post, I will show you how to use pyenv to install python from local file or offline.



2. Solution

pyenv is a multi-version management tool for Python. Use pyenv to easily use different versions of python on a system and achieve easy switching. For more introduction about pyenv, please refer to: https://github.com/yyuu/pyenv.

The pyenv install command is used to install python on the system, such as pyenv install 3.8.6 can help us install python 3.8.6.

However, what if you fail to download python files in your country? This article mainly introduces how pyenv uses the local python installation package to install python.

For local installation, you first need to download the installation package on your laptop, such as Python-3.8.6.tar.xz.

pyenv does not provide a command to install python using local packages. So it is not possible to install directly using commands.

We need to understand the installation principle of pyenv. In fact, it uses the python-build tool, which downloads the python package from the python official website, and then installs it.

My pyenv path is: /usr/opt/pyenv/ The corresponding python-build path is /usr/opt/pyenv/plugins/python-build/share/python-build.

And in /usr/opt/pyenv/plugins/python-build/share/python-build , there are installation instructions for various python versions, such as version 3.8.6:

First create the cache directory

# cd ~/.pyenv/
# mkdir cache

Then move the downloaded Python package to the cache directory

# mv Python-3.8.6.tar.xz ~/.pyenv/cache/

Can’t find python_build path? can use find command:

# find / -name '*python_build*'

Then you can enter the python_build directory and find the directory corresponding to the version of python you want to install: for example 3.8.6

For example: /usr/opt/pyenv/plugins/python-build/share/python-build

Modify the download path:

install_package "Python-3.8.6" "~/.pyenv/cache/python-3.8.6.tar.xz"...

then execute again.

# pyenv install 3.8.6

If the following message appears, the installation is successful.

[root@node1 ~]# pyenv versions
* system (set by /root/.pyenv/version)
 3.8.6



3. Summary

In this post, I demonstrated how to install python using pyenv offline, you must download the python package by yourself, then upload it into the .cache directory of pyenv. That’s it, thanks for your reading.