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 install Python3 environment in Linux system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Linux system how to install Python3 environment, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

This article is based on the following Linux system versions:

1. By default, Linux comes with its own installation Python, which can be viewed by running the python-- version command, as shown below:

We see that Python2.7.5 is already included in Linux. After running the python command again, you can use the python command window (Ctrl+D exits the python command window).

2. View the Python location of Linux default installation

See that / usr/bin/python and / usr/bin/python2 are soft links, / usr/bin/python points to / usr/bin/python2, and / usr/bin/python2 eventually points to / usr/bin/python2.7. So running python/python2/python2.7 is the same, as shown in the figure:

3. Install python3

(1) Log in to https://www.python.org/downloads/source/ and find the corresponding version (we take Python 3.6.5 as an example) as shown in the figure:

Download Python-3.6.5.tgz

(2) File upload

Upload the file to a directory on the Linux system and upload it according to your own situation. This example is uploaded to the / root/tools directory, as shown below:

(3) decompression

Execute the tar-zxvf Python-3.6.5.tgz command to extract the files to the current directory, as shown in the figure:

(4) prepare the compilation environment

Execute the following command:

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

The dependencies required to install python. After success (Complete!), as shown in the figure:

If python is version 3.7, you also need to install libffi-devel. The whole compilation process takes about 1 minute.

If you encounter the following problems:

Loaded plugins: fastestmirror 00:00:00 Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6-"Could not resolve host: mirrorlist.centos.org; Unknown error" One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1.Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. For the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work).

Generally can not connect to the external network, each situation is different, my solution, execute the following command

Vi / etc/sysconfig/network-scripts/ifcfg-ens33

The ifcfg-ens33 name in everyone's Linux is not necessarily the same. My configuration is as follows:

TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no # BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=296fb7a9-961a-46ea-bc1b-678cca49d40a DEVICE=ens33 ONBOOT=yes IPADDR=192.168.189.111 GATEWAY=192.168.189.2 NETMASK=255.255.255.0 DNS1=8.8.8.8 PREFIX=24 IPV6_PRIVACY=no

Save the configuration and execute service network restart to restart the network service. Then re-execute the yum installation command above.

(5) compile and install

Execute cd Python-3.6.5 to enter the extracted Python-3.6.5 directory, and execute the following three commands in turn:

. / configure-- prefix=/root/training/Python-3.6.5 make make install

Where-- prefix is the installation directory of Python. After the installation is successful, as shown below:

We see that both the setuptools and pip tools are installed. Go to the / root/training/Python-3.6.5 installation directory, as shown below:

(6) create soft links

Remember that in the beginning, Linux has installed python2.7.5, and we cannot delete it here. If we delete it, there may be a problem with the system. We just need to create a soft link for Python3.6.5 in the same way as Python2.7.5. We put the soft link in the / usr/local/bin directory, as shown in the figure:

At this point, we run python3 in the command window, as shown in the figure:

Installation successful! Of course, you can still use the Python2.7.5 version at this time (just run python/python2/python2.7).

(7) configure environment variables

The main purpose of configuring environment variables is to quickly use pip3 installation commands.

Execute vi ~ / .bash_profile, open the configuration file, and add the following configuration:

# configure python export PYTHON_HOME=/root/training/Python-3.6.5 export PATH=$PYTHON_HOME/bin:$PATH

Save exit (: wq) and execute the source ~ / .bash_profile command to make the configuration effective. Execute the echo command to see if the configuration is successful, as shown in the figure:

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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