Online Linux Installation on Python There are many ways , But most of them are troublesome , It takes a lot of steps , My scalp feels numb . And many articles say how to install step by step , But the principle or something , Not much , For beginners , When something goes wrong , Unable to resolve .
The following method , I think it is relatively simple , And better understand Python principle , Better operation , Error free methods .
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
The above command directly copies , Just run
1)Python The web address of the installation package is :https://www.python.org/ftp/python/3.8.0/
For this URL , Let's take it apart :
So when we need to install what version of the installation package , Go directly to the path , Download it
like , download 3.9.7 Version of : The path is :https://www.python.org/ftp/python/3.9.7/
for example :https://www.python.org/ftp/python/3.9.7/ The web page of is :
We download .tgz File can 「Windows Install exe Program ,mac install pkg」, The download command is :
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
tar -zxvf Python-3.9.7.tgz
After decompressing , Here's the picture :
cd Python-3.9.7
./configure --prefix=/usr/local/python3
make && make install
The above commands come line by line , Go to the installation package directory first , Then install , Wait for the installation run to end
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip
Be careful : This place is the point , One is the connection python Operating position , The other is connected to pip The operating position of
Popular said , The function of this soft connection , It's telling the system ,python and pip Where to? !
Personally, I'm used to using python、pip, Not used to using python3、pip3, So my soft connection settings are /usr/bin/python and /usr/bin/pip
In the command /usr/bin/python and /usr/bin/pip Is the location of most machines , How do you determine the exact location of your machine ?「 determine python and pip The same way , With python For example 」
where python
where pip
cd Go to the queried command path , Check the corresponding python and pip Soft connection status of :
where python
cd route
# see python Specific soft connection information , Pay attention to add *
la python*
Here's the picture :
If the path your soft connection points to is not python3.9 Of , Is to ② step
First cd To where The path found by the command , Then delete the current soft connection , To reset , The operation steps are as follows :
If where After the order is executed , Multiple paths appear , Try every path , Until you decide which path really works
The above method , Can be used to switch Python edition , We can get Linux There are many Python edition , Which version is needed , We will soft connect to which version
Native Python Versions are in /usr/local/python3/bin Under the path :
When we need a new version , repeat 1 To 4 step , That will be /usr/local/python3/bin Create a new version file in the directory , And we don't need to delete the version we don't use , Just switch the soft connection , This is it. Python The essence of version switching , And in the Windows The above is implemented by setting environment variables .
If the above surface appears , It means that you have successfully installed , congratulations .
Traceback (most recent call last):
File "stat_model.py", line 1, in <module>
from torchstat import stat
File "/usr/local/lib/python3.7/site-packages/torchstat/__init__.py", line 11, in <module>
from torchstat.reporter import report_format
File "/usr/local/lib/python3.7/site-packages/torchstat/reporter.py", line 1, in <module>
import pandas as pd
File "/usr/local/lib/python3.7/site-packages/pandas/__init__.py", line 55, in <module>
from pandas.core.api import (
File "/usr/local/lib/python3.7/site-packages/pandas/core/api.py", line 24, in <module>
from pandas.core.groupby import Grouper, NamedAgg
File "/usr/local/lib/python3.7/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
from pandas.core.groupby.generic import ( # noqa: F401
File "/usr/local/lib/python3.7/site-packages/pandas/core/groupby/generic.py", line 44, in <module>
from pandas.core.frame import DataFrame
File "/usr/local/lib/python3.7/site-packages/pandas/core/frame.py", line 88, in <module>
from pandas.core.generic import NDFrame, _shared_docs
File "/usr/local/lib/python3.7/site-packages/pandas/core/generic.py", line 70, in <module>
from pandas.io.formats.format import DataFrameFormatter, format_percentiles
File "/usr/local/lib/python3.7/site-packages/pandas/io/formats/format.py", line 48, in <module>
from pandas.io.common import _expand_user, _stringify_path
File "/usr/local/lib/python3.7/site-packages/pandas/io/common.py", line 3, in <module>
import bz2
File "/usr/local/lib/python3.7/bz2.py", line 19, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
Question why :
bz2 This library is missing , Read other blogs about installation Python when bz library , namely “_bz2.cpython-36m-x86_64-linux-gnu.so” Wrong installation position
resolvent :
1、 lookup _bz2.cpython file
sudo find / -name "_bz2.cpython-*"
2、 Switch to python The version corresponds to the path , Copy the file to the directory :
cd /usr/local/python3/lib/python3.9/lib-dynload
sudo cp /usr/lib64/python3.6/lib-dynload/_bz2.cpython-36m-x86_64-linux-gnu.so ./
3、 Modify file name , take "-36m" It is amended as follows "-39" that will do 「 Keep consistent with other file names in the same directory 」:
sudo mv ./_bz2.cpython-36m-x86_64-linux-gnu.so ./_bz2.cpython-39-x86_64-linux-gnu.so
The operation is as follows :
linux-python3.8 install
ModuleNotFoundError: No module named ‘_bz2‘ Problem solving
Welcome to leave a message in the comment area , To know everything , can . If it feels good , Don't forget to like the collection !