Creating an environment where you can use Python 2.7.11 and Python 3.5.1 on CentOS 6

table of contents
CentOS 6 comes with Python 2.6 installed by default, but
you may want to install a different version if the package you want to use is not compatible or if you simply want to use something newer.
However, there is software written in Python, such as yum and firewalld, so
it can be scary to upgrade without knowing much about it.
Therefore, I will write down the steps to create an environment using virtualenv
(*Latest version as of February 2016)
By the way, what is virtualenv?
virtualenv a tool that allows you to create a virtual environment for Python .
You can set up separate environments with different versions, or even the same version but different packages installed
You can install it using pip
By the way, what is pip?
This is the command used to install third-party packages for Python
Python 3.4 and Python 2.7.9 or later will be installed at the same time as installing Python, but
since the standard Python for CentOS 6 is 2.6, you must first install pip .
Step 1. Install pip
$ yum groupinstal "Development Tools" #Required for pip installation $ yum install zlib-devel openssl-devel #Required for pip installation $ wget http://bootstrap.pypa.io/get-pip.py $ ./get-pip.py
Now pip is installed
$ pip list
Try typing this and if it shows the packages currently installed in Python, then you're good to go
Step 2. Install virtualenv
$ pip install virtualenv
That's it. Pip is convenient
#How to use $ virtualenv environment name #Create an environment in the current directory $ source environment name/bin/activate #Activate a virtualenv environment $ deactivate #Deactivate a virtualenv environment
It will be usable like this. It will be usable, but to make it a little easier, install virtualenvwrapper
By installing virtualenvwrapper, you can simplify switching between virtualenv environments
Step 3. Install and configure virtualenvwrapper
$ pip install virtualenvwrapper
Write the following in ~/.bashrc
export PROJECT_HOME=/path/to/project/home export WORKON_HOME=/path/to/work on/home source`whichvirtualenvwrapper.sh`
Now you can use virtualenvwrapper
All that's left is to create the environment using this. Let's install Python
Step 4. Install Python2.7.11 and Python3.5.1
2.7.1 Installation
$ cd /opt $ curl -O https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz $ tar zxf Python-2.7.11.tgz $ cd Python-2.7.11 $ ./configure --prefix=/opt/python2.7.11 $ make $ altimake nstall
$ cd /opt $ curl -O https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz $ tar zxf Python-3.5.1.tgz $ cd Python-3.5.1 $ ./configure --prefix=/opt/python5.3.1 $ make $ make altinstall
Step 5. Create an environment
$ mkvirtualenv --python <path to Python to use> <environment name>
You can create it like this, so create it like this
$ mkvirtualenv --python /opt/python2.7.11/bin/python2.7 env_27 $ mkvirtualenv --python /opt/python3.5.1/bin/python3.5 env_35
This completes the environment setup
Now, to use it, type the following and the environment name will be added before the prompt
#For Python2.7 $ work on env_27 #For Python3.5 $ work on env_35
#For Python2.7 (env_27)$ #For Python3.5 (env_35)$
For example, if you type the python command in env_27, python2.7.11 will be launched, and
if you run "pip install" in env_27, the package will only be installed in the env_27 environment.
Another command I use often is something like this:
$ workon # List of environments $ workon environment name # Run environment $ deactivate # Stop environment $ rmvirtualenv environment name # Delete environment
Now you can try out all sorts of things! Enjoy coding!
Introducing our company Beyond
Since our founding, Beyond has used the technical capabilities we have cultivated as a multi-cloud integrator and managed service provider (MSP) to design, build, and migrate systems using a variety of cloud/server platforms, including AWS, GCP, Azure, and Oracle Cloud
We provide a custom-made cloud/server environment optimized for our customers based on the specifications and functions of the systems and applications they require, so if you are interested in the cloud, please feel free to contact us
● Cloud / Server design and construction
● Cloud / Server migration
● Cloud / Server operation, maintenance and monitoring (24 hours a day, 365 days a year)
0