当前位置: 首页 > >

Linux安装python及模块

发布时间:

Linux下安装python及模块踩过的坑
1.先下载python的版本
https://www.python.org/downloads/source/
2.安装依赖环境

# 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
3.安装python3
个人*惯安装在/usr/local/python3(具体安装位置看个人喜好)

# mkdir -p /usr/local/python3
4.解压下载好的Python-3.9.0.tgz包()

# tar -zxvf Python-3.9.0.tgz
5.进入解压后的目录,编译安装

# cd Python-3.9.0
# ./configure --prefix=/usr/local/python3 --enable-shared --with-ssl
# make && make install

6.建立python3的软链

# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
注:
? ? 如果出现ln: failed to create symbolic link ‘/usr/bin/python3’: File exists
?

rm -rf /usr/bin/python3
ln -s /usr/local/python3/bin/python3 /usr/bin/python3

? ?就ok
? ?修改pip3的软链接:

ln -s /usr/local/python3/bin/pip3 ?/usr/bin/pip3 ?##可以忽略
7.检查python3是够可正常运行

python3 -V
注:若报错 libpython3.X.so:cannot open shared object file
? ? ? ?找到相应的所在地址

find / -name libpython3.X.so
? ? ? ?结果

/usr/local/python3/Python3.9.0/libpython3.X.so
? ? ? ?将目录拷贝至

?vi /etc/ld.so.conf 最后一行:/usr/local/python3/Python3.9.0
? ? ? 使得生效: /sbin/ldconfig
8.离线安装python的其他包:
? ? ? https://pypi.org/ ?在这找到对应的版本下载
? ? 下载相关的? ###.whl或者?###.tar.gz
? ? ###.whl 使用

pip3 install ###.whl
? ?或者###.tar.gz
? ?将相关的包上传至某个目录下,解压编译、安装

tar -zxvf ###.tar.gz
python3 setup.py build
python3 setup.py install

?



友情链接: