Summary of python compilation and installation and library loading problems under deepin system

introduction

This article wants to summarize some problems I have encountered in the deepin system in the past two days, mainly some bugs and things compiled and installed by python, in case I encounter them next time, if possible (best not to).

apt-get cannot update the problem

When I first entered the system, I encountered the following error:

Couldn’t create temporary file /tmp/apt.conf.g1YDx9

Solution, tmp has no permissions:

chmod 777 /tmp

I don't know why I get this error, but it's just a coincidence, so I'll record it here.

deepin cannot install docker problem

insert image description here

I don't know if all deepin is like this, but for me, no matter how I use the debian installation method on the official website, I can't install docker-ce, docker-ce-cli and containerd.io, and finally I found one on GitHub. Key script installation, as follows:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

as well as:

curl -sSL https://get.daocloud.io/docker | sh

Because I use the UOS system, I see that it seems to be using deepin as the system. I don't know which link in the middle is wrong. It can only be said that it is an unknown error.

Compile in python environment

In centos and Ubuntu, the general system is complete with relevant environment dependencies. If not, the python environment dependencies can also be installed by referring to the following method when I installed centos before:

# 系统依赖
yum -y install  zlib zlib-devel
yum -y install  gcc gcc-c++
yum -y install openssl openssl-devel
yum -y install libffi-devel  tk-devel

# python 非必要依赖包
yum install xz-devel
yum install python-backports-lzma   # pandas
yum install sqlite-devel
yum -y install readline-devel    # python命令行下退格、删除、方向键乱码问题包

Among them, openssl and openssl-devel are related to certificates. The python installation will request project dependencies, and backports-lzma and so on are the packages needed by pandas. Generally, these packages are available. If not, then there is a problem with the system. The situation encountered by deepin, emmm. . . Here is the compilation method of sqlite. Others, about openssl was mentioned in my previous blog when compiling cmake, but python does not need cmake, and the same version of openssl comes with it, and the lzma package is very old. Now, I think the date is the last few updates in 2012, then it means that it is very stable, so it can be installed from source, otherwise I feel that the system should be miserable.

sqlite compile and install

If sqlite is not compiled, the underlying layer supported by python cannot run some various packages, which is equivalent to caching. If it is missing, it will affect the entire file structure. The specific commands are as follows:

wget https://www.sqlite.org/2018/sqlite-autoconf-3250200.tar.gz
tar -zxvf sqlite-autoconf-3250200.tar.gz
cd sqlite-autoconf-3250200
./configure --prefix=/usr/local/sqlite3
make && make install

After the installation is complete, there will be sqlite3 in the /usr/local/ directory, and you need to add a soft link to the execution directory:

ln -s /usr/local/sqlite3/bin/sqlite3 /usr/bin/sqlite3   

If the soft chain is not added, sqlite will still not be found in the subsequent python compilation. After that, install the above packages. If you do not use the command line backspace, delete, arrow keys and pandas data processing packages, the above python dependencies can be omitted. .

Python source code compilation

First check the dependencies again:

apt-get install -y gcc g++ cmake make build-essential zlib1g-dev libbz2-dev libsqlite3-dev libssl-dev libxslt1-dev libffi-dev

Among them, the source code of libsqlite3 has been compiled, because I did not load this package on the deepin system, so I deleted it from apt-get install.

Then install python:

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar -zxvf Python-3.7.5.tgz

cd Python-3.7.5/
./configure --prefix=/usr/local/python3.7.5 --enable-loadable-sqlite-extensions --enable-shared
# ./configure --prefix=/usr/local/python37 --enable-optimizations && make && make install

make
sudo make install

There are two ways to compile python. One is to enable-optimizations full compilation, that is, to build all the python environments. I tried it, except that it took half an hour to compile the c file to 307/471 and then got stuck. According to It seems that this option is to optimize the entire python. After compilation, the performance is optimized by about 10%. But it is not used yet, so the first one is recommended, because the downloaded precompiled version of apt-get install python3-devel is also the first to add the sqlite-extensions extension, which enables built-in library sharing with enable-shared.

Then add the python soft chain:

sudo ln -s /usr/local/python3.7.5/bin/python3 /usr/local/python3.7.5/bin/python3.7.5
sudo ln -s /usr/local/python3.7.5/bin/pip3 /usr/local/python3.7.5/bin/pip3.7.5

Set the python3.7.5 environment variable:

#用于设置python3.7.5库文件路径
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
#如果用户环境存在多个python3版本,则指定使用python3.7.5版本
export PATH=/usr/local/python3.7.5/bin:$PATH

ImportError: libpython3.7m.so.1.0: cannot open shared object file: No such file or direct

This error is also very unbelievable, because I have added the lib under python3.7.5 to the system variable above, but the error here says that it cannot be found, but this file is under lib, so this single file is treated specially:
insert image description here
solution :

cp libpython3.7m.so.1.0 /usr/local/lib/
cp libpython3.7m.so.1.0 /usr/lib/

The above two paths are generally the default shareable dynamic link libraries of Linux. Like the system variables in bashrc, Linux will load the paths by default.

In addition to the above method of copying the past directly by cp, there are also the establishment of soft links, as well as modifying /etc/ld.so.conf, and then creating a new dynamic library path. Generally these two are not commonly used, but who asked me Now I am mining the pit. I have not tried it except for soft links. The /etc/ld.so.conf method is shown in the figure below. For some reason, there are too many dynamic libraries that cannot be loaded, so I can only open more new paths:
insert image description here

Guess you like

Origin blog.csdn.net/submarineas/article/details/122607146