The other day, I had the opportunity to install Python 3 on AWS EC2.
At that time, I did a Google search on "AWS EC2 Python3", but the information on the page displayed at the top of the search results was not good enough. In particular,
The method of preparing a virtual environment for Python3 was introduced using, but unless there are special circumstances, the method for preparing a virtual environment for Python3 should use venv
.
Also, unless you use Python3 for application development or data analysis, you don't need to prepare a virtual environment in the first place.
The reason for using venv
as a way to prepare a virtual environment for Python 3 is [the only method recommended in the official Python documentation](https://docs.python.org/ja/3/library/venv. html) Because.
The reason why you should avoid pyenv
is described in detail in this article, so if you are interested, please see here.
Also, AWS official documentation introduces the method using virtualenv
. , I don't think there is any reason to actively use virtualenv
in Python 3.3 or later, which was officially incorporated into Python as venv
.
So, I would like to introduce how to install Python3 on AWS EC2 again. That said, it just follows the method introduced in the official Python documentation ...
Install Python 3 on the OS system
$ sudo yum update
$ sudo yum install python3 -y
Opportunities to use Python are limited, and I think this is sufficient if you don't need version control for Python itself or packages. On the other hand, if you want to manage the version for exclusive use in application development, or if you want to prepare an environment for exclusive use in data analysis, the virtual environment comes into play.
Install Python3 for virtual environment using venv
$ python3 -m venv myenv
If you execute the above command in your home directory, a directory called myenv
will be created under your home directory. You can change the name myenv
to your liking.
Enable Python 3 virtual environment
$ source myenv/bin/activate
Running the above command will enable the Python 3 virtual environment.
Disable Python 3 virtual environment
$ deactivate
If you want to exit the virtual environment of Python3, just execute the above command. Also, if you want to completely delete the environment, you can delete the myenv
directory.
I introduced how to install Python3 on AWS EC2, but I think that is the case at least for Linux-based OS.
Keep in mind that those who rarely use Python will use Python3 installed on the OS system, and those who use Python will use the Python3 virtual environment created using venv
.
Recommended Posts