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

CentOS 6 comes with Python 2.6 by default, but you
might want to install a different version if the packages you want to use are not compatible, or simply because you want to try a newer version.

However, since some software like yum and firewalld are written in Python,
it's scary to upgrade them without knowing much about them.

Therefore, virtualenv I will describe the procedure for creating an environment using

(*Latest version as of February 2016)

By the way, what is virtualenv?

virtualenva 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

pipYou can install it using

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 and later versions are installed automatically when you install Python, but
the standard Python version on CentOS 6 is 2.6, soyou need to install pip first.

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 work like this. It will work, but to make it a little easier,virtualenvwrapperwe'll install

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

3.5.1 Installationトール

$ 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 run the `python` command while in the `env_27` environment, python2.7.11 will start, and
if you run `pip install` while in the `env_27` environment, packages will only be installed for 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)

If you found this article helpful,please give it a "Like"!
0
Loading...
0 votes, average: 0.00 / 10
4,496
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author