Using Python 3 series on Amazon Linux I solved it by the method of this blog, but I will supplement and introduce the part that I thought was a little insufficient for myself.
In other blogs, I think that pyenv is installed in/home/ec2-user/..., but since the ec2-user directory has strict privileges, install python3 in it, for example. , Exec (/home/ec2-user/.../bin/python3.7)
permission denied
Will be. However, if you rewrite the permissions of the home directory and ec2-user directory, is it a security specification? Or something, the horrifying thing that scp or ssh can't get into the server happens. (If that happens, you can fix it by opening a terminal from the AWS ec2 instance page.)
$ sudo yum install gcc gcc-c++ make git openssl-devel bzip2-devel zlib-devel readline-devel sqlite-devel
$ sudo git clone https://github.com/yyuu/pyenv.git /usr/bin/.pyenv
$ cd /usr/bin/.pyenv
$ sudo mkdir shims
$ sudo mkdir versions
$ sudo chown -R ec2-user:apache /usr/bin/.pyenv
#Or if apache is not installed
$ sudo chown -R ec2-user:ec2-user /usr/bin/.pyenv
There are other blogs that have detailed information on setting the path, so please check that out. Use the vim editor to open .bashrc.
vi ~/.bashrc
Add this.
export PYENV_ROOT="/usr/bin/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
export PATH=${PYENV_ROOT}/bin:$PATH
eval "$(pyenv init -)"
fi
Reload in the rewritten state.
$ source ~/.bashrc
This time I will install python3.7.0 properly. Even if you install it, it remains python on the existing system
$ pyenv install 3.7.0
$ python -V
Python 2.7.12
In this way, the mode is changed to python 3.7.0.
$ pyenv global 3.7.0
$ python -V
Python 3.7.0
If you go through the location where you just installed it, you will find the location where python3.7 is installed. 「/usr/bin/.pyenv/versions/3.7.0/bin/python3.7」 __ With this, you can use python3.7. __ The following two are the same, just looking the same through the __path. __
$ python
$ /usr/bin/.pyenv/versions/3.7.0/bin/python3.7
You can now use python3.7.0 with php. As a test, let's use exec () like this. You can use python3.7 properly.
$command = "/usr/bin/.pyenv/versions/3.7.0/bin/python3.7 -V";
exec($command, $output, $return_var);
$json_array = json_encode($output);
echo $json_array
Recommended Posts