[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Building an environment that can use Python2.7.11 and Python3.5.1 on CentOS6

This is Goto from the web team.

CentOS6 comes with Python2.6 by default, but you
may want to install a different version if the package you want to use is not supported or if you simply want to use a newer version.

However, there are software such as yum and firewalld that are written in Python, so
it can be scary to upgrade without knowing much about them.

Therefore, I will write down the steps to use virtualenv

(*Latest version as of February 2016)

By the way, what is virtualenv?

virtualenv a tool that allows you to build a Python virtual environment .

You can of course have different versions, or you can have separate environments with the same version but different packages installed.

It can be installed using pip

By the way, what is pip?

This is the command used to install third-party packages for Python.

Python3.4 and Python2.7.9 or later are installed at the same time when Python is installed, but since
the standard Python on CentOS6 is 2.6, you need to install pip first .

Step 1. pip installation

$ 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 

pip is now installed.

$ pip list

If you try typing something like this and the packages currently included in Python are displayed, you're good to go.

Step 2. virtualenv installation

$ pip install virtualenv

That's all. pip convenient.

#How to use $ virtualenv environment name #Create an environment in the current directory $ source environment name/bin/activate #Enabling a virtualenv environment $ deactivate #Disabling a virtualenv environment

You can use it like this. You can use it, but to make it a little easier, we will install virtualenvwrapper

By installing virtualenvwrapper, you can easily switch between virtualenv environments.

Step 3. virtualenvwrapper installation and configuration

$ 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 to do is create an environment using this. Let's install Python.

Step 4. Install Python2.7.11, Python3.5.1

Installing 2.7.1

$ 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 install

Installing

$ 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 the environment

$ mkvirtualenv --python <Python path to use> <Environment name>

You can 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 

The environment construction is now complete.

As for how to use it, if you type as follows, 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 hit the python command in the env_27 state, python2.7.11 will start, and
if you run "pip install" in the env_27 state, the package will be installed only in the env_27 environment.

Another commonly used command is something like this.

$ workon #Environment list $ workon Environment name #Execute environment $ deactivate #Stop environment $ rmvirtualenv Environment name #Delete environment

Now you can try as many things as you want! Enjoy coding!

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
3,969
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author