Docker configuration under ubuntu: python, cuda

Install python from source code

Reference link: https://zhuanlan.zhihu.com/p/407534754

Python official website link https://www.python.org/downloads/source/
Select the required python version to download.

The operation command is as follows:

## ResourceWarning: Implicitly cleaning up <TemporaryDirectory '/tmp/tmpq3jb803g'>

apt-get update
apt-get install --reinstall zlibc zlib1g zlib1g-dev
apt-get install libffi-dev libssl-dev libreadline-dev -y

tar -zxvf Python-3.9.7.tgz  # 解压下载的python源码
cd ./Python-3.9.7/  # 进入到解压后的文件夹中


mkdir /opt/python3.9/  # 创建安装python的目标路径

./configure --prefix=/opt/python3.9 --with-pydebug --enable-optimizations --with-ssl
make
make install   #到这里就安装好了,
/opt/python3.9/bin/python3.9   # 进入python3.9的交互环境,说明安装成功

# 创建python3.9的软链接
ln -s /opt/python3.9/bin/python3.9  /usr/bin/python3.9    #docker中应该放到 /usr/local/bin/目录下
ln -s /opt/python3.9/bin/pip3.9  /usr/bin/pip3.9 #docker中应该放到 /usr/local/bin/目录下

tar command: In layman's terms, this command is used to compress/decompress. The following '-zxvf' is the parameter. 'z' means to process files with gzip, which is the default and can be omitted; 'x' means to extract files from the compressed package; 'v' means to display the execution process, if this parameter is not written, the decompression process will be performed quietly without feedback , can be omitted; 'f' is used to specify the file. In fact, the tar command is used to combine many files and folders into one file or reverse operations. Compression/decompression is only part of the function. For details, please refer to the documentation or search in the search engine.
Configure compilation parameters: '--prefix=/opt/python3.9' is used to specify the installation location, '--with-pydebug' is used to add debugging tools, and '--enable-optimizations' is used to optimize the compilation results and improve operation Efficient, but increases compilation time.
Installation part $ make altinstall command: altinstall is used here, you can also use install, the price is that it may change the built-in python3 installation, making uninstallation difficult, or even make the built-in python3 unavailable, but generally not These nasty mistakes can occur. Please do so at your own risk. For specific effects, please refer to the documentation or search in the search engine.

Configure pip Tsinghua source

pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Install pytorch

Various versions of torch
https://pytorch.org/get-started/previous-versions/

configure cuda

Select the required cuda version https://developer.nvidia.cn/cuda-toolkit-archive

sudo vim ~/.bashrc

$ export PATH=/usr/local/cuda-10.1/bin${
    
    PATH:+:${
    
    PATH}}
$ export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64\
                         ${
    
    LD_LIBRARY_PATH:+:${
    
    LD_LIBRARY_PATH}}

source ~/.bashrc

BUGS

ModuleNotFoundError: No module named _bz2

apt-get install bzip2-devel
recompile and install python

ResourceWarning: Implicitly cleaning up <TemporaryDirectory ‘/tmp/tmpq3jb803g’>

There is no solution yet.

Guess you like

Origin blog.csdn.net/NGUever15/article/details/131043138