Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compile and install Python 3.7 and Python 2.7.5 under CentOS 7

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

It is believed that many inexperienced people have no idea about how to compile and install Python 3.7and Python 2.7.5 under CentOS 7. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

How to compile and install Python 3.7 and Python 2.7.5 under CentOS 7.

Environment: CentOS 7.6x64

1. Install Python 3.7

Download the python source package:

Wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

If you do not have the wget command, you can use the command to install: yum-y install wget

Install dependency packages to avoid "zipimport.ZipImportError" errors and "ModuleNotFoundError: No module named'_ ctypes'" errors during installation:

Yum-y install zlib-devel libffi-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

Extract, compile, install:

Tar-zxvf Python-3.7.4.tgzcd Python-3.7.4./configure-- prefix=/usr/local/python3-- enable-optimizationsmake & & make install

Modify the environment variable:

Vim / etc/profile

Find the line that begins with "export PATH", and insert a new line before this line, as follows:

PATH=$PATH:/usr/local/python3/bin# Note: there are no spaces on both sides of the equal sign, colons: cannot be saved.

Save exit and execute the command:

Source / etc/profile

Now let's see if the two versions of python and pip coexist:

[root@localhost ~] # python3-VPython 3.7.4 [root@localhost ~] # pip3-Vpip 19.0.3 from / usr/local/python3/lib/python3.7/site-packages/pip (python3.7) [root@localhost ~] # python-VPython 2.7.5 [root@localhost] # pip-Vpip 19.1.1 from / usr/lib/python2.7/site-packages/pip (python2.7)

Because the yum of the system, as well as other components, depends on python2.7.5, it is not recommended to replace the original python2 environment with soft links. When using python3, we only need to do the following:

Pip3 install package name python3-m pip install package name python3-m pip install pymongo (install pymongo package for Python3) python3 myscripts.pypip3 install-- upgrade pip (upgrade pip3 version).

The installation is complete.

After reading the above, do you know how to compile and install the coexistence of Python 3.7 and Python 2.7.5 under CentOS 7? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report