Linux服务器上部署Python3环境

Linux上自带安装了Python2.6.6,但是我们需要用Python3的时候就需要重新安装Python3,并且不要去删除原来的Python2.下面开始Python3的安装步骤:

1.下载Python3

沿用Windows习惯,先新建一个文件夹再下载到这个文件夹中

mkdir /data

切换到data文件夹

cd /data

下载Python3

wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz

2.解压文件

tar -xvf Python-3.5.3.tgz

3.创建文件安装路劲,因为Linux自带的Python2都是安装在/usr/bin下面,那么Python3我们仍然安装在/usr/bin下面

扫描二维码关注公众号,回复: 6796931 查看本文章

mkdir /usr/bin/python3

4.编译Python3

./configure --prefix=/usr/bin/python3

注意:如果在此步骤时我们未安装过GCC编译器则会报错,在本机中没有安装编译器

configure: error: no acceptable C compiler found in $PATH

没有关系,我们可以通过yum先安装gcc,

执行命令:

yum install -y gcc

Linux一般都默认安装了yum功能,但是yum需要python2环境,因此就是开始时告知不要删除原Python2.

重新执行
./configure --prefix=/usr/bin/python3

5.依次执行如下安装命令:

make

make install

经过短暂的安装过程后,我们就看到Python3已经安装成功了,

OK,我们来试下,

执行命令

python

我靠!怎么还是Python2.6.6

Python的软连接指向了Python2,我们cd 到/usr/bin/下看看

cd /usr/bin

ls -l

果然如此

6.修改原软连接并重新建立软连接

修改原软连接

mv /usr/bin/python /usr/bin/python_bak

新建软连接

ln -s /usr/local/python3/bin/python3 /usr/bin/python

OK,这下终于成功了

7.配置成功后pip3用不了,那么需要配置下环境变量

PATH= P A T H : PATH: HOME/bin:

PATH= P A T H : PATH: HOME/bin:/usr/local/python3/bin

这下pip3也可以使用了,配置全部完成

附:安装时若报错:
在这里插入图片描述
解决方法:yum install libffi-devel
原文链接:https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul

原文:https://blog.csdn.net/qq_35304570/article/details/80302872
版权声明:本文为博主原创文章,转载请附上博文链接!

安装Scrapy报错:Could not find a version that satisfies the requirement Twisted>=13.1.0 (from Scrapy) (from versions: )
No matching distribution found for Twisted>=13.1.0 (from Scrapy)
解决方法: https://www.cnblogs.com/richerdyoung/p/8548175.html

猜你喜欢

转载自blog.csdn.net/qq_42306041/article/details/94571602