** I updated the CLI thinking "I haven't updated the OCI CLI recently" **. When you run the CLI, a surprising message is displayed in red!
$ oci iam region list WARNING: OCI CLI now requires Python 3.5+. Please install or upgrade your version of Python to 3.5+ before February 13, 2020 to avoid interruption to CLI usage.
** If you think calmly, the support deadline for Python 2 is until the end of March 2020. ** **
** Python of Oracle Linux 7 is 2.x series. That's why I investigated the countermeasures. ** **
$ python -V Python 2.7.5
1-1. TL;DR
People who are going to install ** OCI CLI ** on Oracle Linux 7 / CentOS 7
People who are already using ** OCI CLI ** on Oracle Linux 7 / CentOS 7 and need to migrate to Python 3
8 series Linux, Ubuntu, Windows, and Mac are Python 3, so this problem does not affect.
** Japanese manual **
** English manual **
Python 3 is required to use the OCI CLI. However, Python's environment construction is diverse, and it is a difficult situation for users. Look back at the big picture and think about the installation policy.
Many instructions on how to install the OCI CLI are introduced in the above manual and the next Qiita article. There are some subtle differences, but they are about the same.
The problem is building a Python environment. There are multiple ways to use Python 3 on Oracle Linux 7 / CentOS 7 in the first place, and there are also multiple ways to manage Python packages. As you can see in the next article, the situation is extremely complicated.
This time, let's think simply and narrow down under the following conditions.
Then I can think of the following method.
** Python 3.x is not included in the standard repository, so if you think "Software Collections" or "EPEL", according to the following news source, 7.7 or later (2019 / 8-) will be included in the standard repository. ** **
After checking, it is included in the standard repository (ol7_latest) as follows. In the next chapter, we will try to install using this.
$ sudo yum list available python3
Loaded plugins: langpacks, ulninfo
Available Packages
python3.i686 3.6.8-10.0.1.el7 ol7_optional_latest
python3.x86_64 3.6.8-10.0.1.el7 ol7_latest ★ here
Install Python 3 on Oracle Linux 7. In addition, ** venv **, which is convenient for building a Python environment, will be explained.
The OCI CLI internally uses ** venv / virtulenv ** to manage the Python virtual environment. Therefore, the user does not need to use ** venv / virtulenv ** during installation. </ font>
$ sudo yum install -y python3
2.7.5
.$ python -V
Python 2.7.5
python3
as follows.$ python3 -V
Python 3.6.8
$ ls -l /usr/bin/py*
-rwxr-xr-x.1 root root 78 December 5 10:34 /usr/bin/pydoc
lrwxrwxrwx.1 root root 8 December 24 16:08 /usr/bin/pydoc3 -> pydoc3.6
-rwxr-xr-x.1 root root 78 August 7 17:04 /usr/bin/pydoc3.6
lrwxrwxrwx.1 root root 7 December 24 13:08 /usr/bin/python -> python2
lrwxrwxrwx.1 root root 9 December 24 13:08 /usr/bin/python2 -> python2.7
-rwxr-xr-x.1 root root 7144 December 5 10:34 /usr/bin/python2.7
lrwxrwxrwx.1 root root 9 December 24 16:08 /usr/bin/python3 -> python3.6
-rwxr-xr-x.2 root root 11336 August 7 17:04 /usr/bin/python3.6
-rwxr-xr-x.2 root root 11336 August 7 17:04 /usr/bin/python3.6m
lrwxrwxrwx.1 root root 10 December 24 16:08 /usr/bin/pyvenv -> pyvenv-3.6
-rwxr-xr-x.1 root root 435 August 7 17:04 /usr/bin/pyvenv-3.6
** Caution **
Do not change the link destination of / usr / bin / python
to python3
here. That's because many commands, including yum, depend on Python 2.x. Please be careful as troubles will continue if you replace the symbolic link. </ font>
$ rpm -ql python3
/usr/bin/pydoc3
/usr/bin/pydoc3.6
/usr/bin/python3
/usr/bin/python3.6
/usr/bin/python3.6m
/usr/bin/pyvenv
/usr/bin/pyvenv-3.6
/usr/share/doc/python3-3.6.8
/usr/share/doc/python3-3.6.8/README.rst
/usr/share/licenses/python3-3.6.8
/usr/share/licenses/python3-3.6.8/LICENSE
/usr/share/man/man1/python3.1.gz
/usr/share/man/man1/python3.6.1.gz
Python has many ways to manage multiple Pythons and Python packages on one machine. This time, I will introduce ** venv **, which is the most standard and also uses the OCI CLI installer. ** venv ** is a standard feature of the traditional ** virtualenv ** from Python 3.3.
I'm confused by the mixture of ** venv ** and ** pyvenv **, but both are the same ** venv **. pyvenv is a script that operates venv and is currently deprecated. https://docs.python.org/3.6/library/venv.html
The pyvenv script has been deprecated as of Python 3.6 in favor of using python3 -m venv to help prevent any potential confusion as to which Python interpreter a virtual environment will be based on.
Here's how to use ** venv **:
** Creating a virtual environment **
python3 -m venv <environment path name>
** Enable virtual environment **
source <environment path name>/bin/activate
** Disable virtual environment **
deactivate
This work is not necessary for installing the OCI CLI, but it will be used in the investigation described later. </ font>
$ python3 -m venv oci_cli
$ ls -d oci_cli/*
oci_cli/bin oci_cli/include oci_cli/lib oci_cli/lib64 oci_cli/pyvenv.cfg
$ source oci_cli/bin/activate
(oci_cli) [opc@hostname ~]$
(oci_cli) [opc@hostname ~]$ python -V
Python 3.6.8
deactivate
to deactivate. You can see that disabling the virtual environment reverts to the original version.(oci_cli) [opc@hostname ~]$ deactivate
[opc@hostname ~]$ python -V
Python 2.7.5
This is the basic knowledge of Python's virtual environment. Then install / update the OCI CLI.
Then install the OCI CLI. You must have internet access to run the OCI CLI installer.
Install the OCI CLI. Even if you are already using the OCI CLI with Python 2.x, you will need to reinstall the Python library because it is installed in a different location. However, the configuration file under $ HOME / .oci
can be used as it is.
$ bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
===> In what directory would you like to place the install? (leave blank to use '/home/opc/lib/oracle-cli'):
-- Install directory '/home/opc/lib/oracle-cli' is not empty and may contain a previous installation.
===> Remove this directory? (y/N):★ Enter y
After that, you will be asked to enter some information, but you can use the "all return key".
When finished, the output will be as follows.
-- ** Run `exec -l $SHELL` to restart your shell. **
--
-- Installation successful.
-- Run the CLI with /home/opc/bin/oci --help
$ HOME / .bashrc
to take effect.$ exec -l $SHELL
$HOME/.bashrc
[[ -e "/home/opc/lib/oracle-cli/lib/python2.7/site-packages/oci_cli/bin/oci_auto
complete.sh" ]] && source "/home/opc/lib/oracle-cli/lib/python2.7/site-packages/
oci_cli/bin/oci_autocomplete.sh"
[[ -e "/home/opc/lib/oracle-cli/lib/python3.6/site-packages/oci_cli/bin/oci_auto
complete.sh" ]] && source "/home/opc/lib/oracle-cli/lib/python3.6/site-packages/
oci_cli/bin/oci_autocomplete.sh"
$ oci --version
2.7.0
You don't have to do anything when updating from Python 2. The config file under $ HOME / .oci
can be used as it is. If the installation is successful, the warning message introduced at the beginning will disappear even if you execute the OCI CLI.
For new installation, refer to the following page for setting.
I explained the virtual environment of Python, so let's check it. The OCI CLI is installed in $ HOME / lib / oracle-cli
.
$ pip3 list --format=columns
Package Version
---------- -------
pip 9.0.3
setuptools 39.2.0
$ source lib/oracle-cli/bin/activate
(oracle-cli) [opc@hostname ~]$
(oracle-cli) [opc@hostname ~]$ pip3 list
Package Version
--------------- ----------
arrow 0.10.0
asn1crypto 1.2.0
certifi 2019.11.28
cffi 1.13.2
click 6.7
configparser 3.5.0
cryptography 2.4.2
idna 2.6
jmespath 0.9.3
oci 2.8.0 ★OCI Python SDK
oci-cli 2.7.0 ★OCI CLI
pip 19.3.1
pycparser 2.19
pyOpenSSL 18.0.0
python-dateutil 2.7.3
pytz 2016.10
PyYAML 5.1.2
retrying 1.3.3
setuptools 42.0.2
six 1.11.0
terminaltables 3.1.0
wheel 0.33.6
** Bonus: ** You can also use pip
instead of pip3
in a virtual environment. Both have the same output, but when you activate the virtual environment, you can use the pip
installed in the virtual environment. There is no pip
in / usr / bin.
$ find $HOME /usr/bin -name "pip*"
/home/opc/.cache/pip
/home/opc/lib/oracle-cli/lib/python3.6/site-packages/pip
/home/opc/lib/oracle-cli/lib/python3.6/site-packages/pip-19.3.1.dist-info
/home/opc/lib/oracle-cli/bin/pip
/home/opc/lib/oracle-cli/bin/pip3
/home/opc/lib/oracle-cli/bin/pip3.6
/home/opc/lib/oracle-cli/pip-selfcheck.json
/usr/bin/pip3 ★ There is no pip
/usr/bin/pip-3
/usr/bin/pip-3.6
/usr/bin/pip3.6
(oracle-cli) [opc@hostname ~]$ pip3 list -o
Package Version Latest Type
--------------- ------- ------ -----
arrow 0.10.0 0.15.4 wheel
click 6.7 7.0 wheel
configparser 3.5.0 4.0.2 wheel
cryptography 2.4.2 2.8 wheel
idna 2.6 2.8 wheel
jmespath 0.9.3 0.9.4 wheel
pyOpenSSL 18.0.0 19.1.0 wheel
python-dateutil 2.7.3 2.8.1 wheel
pytz 2016.10 2019.3 wheel
PyYAML 5.1.2 5.2 sdist
six 1.11.0 1.13.0 wheel
(oracle-cli) [opc@hostname ~]$ pip3 install oci-cli --upgrade
(oracle-cli) [opc@hostname ~]$ deactivate
[opc@hostname ~]$
Earlier I showed you how to update the OCI CLI with pip3 install oci-cli --upgrade
. Actually, there are the following two update methods.
Since reinstallation is a single command, I will introduce the pip / pip3 method including the actual output.
$cd <installation directory>
source lib/oracle-cli/bin/activate
pip3 list -o
---Output here or below---
Package Version Latest Type
--------------- ------- ------ -----
arrow 0.10.0 0.15.5 wheel
cffi 1.13.2 1.14.0 wheel
click 6.7 7.1.1 wheel
configparser 3.5.0 4.0.2 wheel
idna 2.6 2.9 wheel
jmespath 0.9.3 0.9.5 wheel
oci 2.10.2 2.12.1 wheel ★ There is a new version
oci-cli 2.9.0 2.9.7 wheel ★ There is a new version
pycparser 2.19 2.20 wheel
pyOpenSSL 18.0.0 19.1.0 wheel
python-dateutil 2.7.3 2.8.1 wheel
pytz 2016.10 2019.3 wheel
PyYAML 5.1.2 5.3.1 sdist
setuptools 45.1.0 46.1.1 wheel
six 1.11.0 1.14.0 wheel
pip3 install oci-cli --upgrade
Part of the output
Collecting oci-cli
Downloading oci_cli-2.9.7-py2.py3-none-any.whl (7.5 MB)
|████████████████████████████████| 7.5 MB 6.1 MB/s
Collecting configparser>=4.0.2
Downloading configparser-4.0.2-py2.py3-none-any.whl (22 kB)
Requirement already satisfied, skipping upgrade: terminaltables==3.1.0 in ./lib/oracle-cli/lib/python3.6/site-packages (from oci-cli) (3.1.0)
Requirement already satisfied, skipping upgrade: certifi in ./lib/oracle-cli/lib/python3.6/site-packages (from oci-cli) (2019.11.28)
Requirement already satisfied, skipping upgrade: PyYAML==5.1.2 in ./lib/oracle-cli/lib/python3.6/site-packages (from oci-cli) (5.1.2)
Requirement already satisfied, skipping upgrade: retrying==1.3.3 in ./lib/oracle-cli/lib/python3.6/site-packages (from oci-cli) (1.3.3)
Requirement already satisfied, skipping upgrade: idna<2.7,>=2.5 in ./lib/oracle-cli/lib/python3.6/site-packages (from oci-cli) (2.6)
Requirement already satisfied, skipping upgrade: pytz>=2016.10 in ./lib/oracle-cli/lib/python3.6/site-packages (from oci-cli) (2016.10)
Collecting oci==2.12.0
Downloading oci-2.12.0-py2.py3-none-any.whl (3.6 MB)
|████████████████████████████████| 3.6 MB 2.3 MB/s
★ Omitted
Successfully uninstalled oci-cli-2.9.0
Successfully installed arrow-0.14.7 configparser-4.0.2 jmespath-0.9.4 oci-2.12.0 oci-cli-2.9.7 six-1.14.0
(oracle-cli) [opc@hostname ~]$ deactivate
[opc@hostname ~]$
python3
is recommended.Recommended Posts