linux中安装python

本文详细介绍了如何在Linux环境下安装Python 2.7、pip、robotframework及其Selenium2Library组件,解决了安装过程中的常见问题,如C编译器缺失、依赖包未安装等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载安装包:https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
2.安装python
[root@localhost mnt]# tar -xvzf Python-2.7.13.tgz
[root@localhost mnt]# cd Python-2.7.13
[root@localhost Python-2.7.13]# ./configure --prefix=/usr/local/python27
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux2
checking EXTRAPLATDIR...
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/mnt/Python-2.7.10':
configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

如上,出错了,解决方法:安装gcc

配置好本地yum源后,安装gcc

[root@localhost yum.repos.d]# yum install gcc

 

继续安装python

[root@localhost Python-2.7.10]# ./configure --prefix=/usr/local/python27

......

[root@localhost Python-2.7.10]# make && make install

参考文档:

https://docs.python.org/2/using/unix.html

 

二、安装pip

 

pip下载地址

https://pypi.python.org/pypi/pip

 

安装pip

[root@localhost mnt]# tar -xvzf pip-7.1.0.tar.gz

[root@localhost mnt]# cd pip-7.1.0

[root@localhost pip-7.1.0]# ls

AUTHORS.txt  docs         MANIFEST.in  pip.egg-info  README.rst  setup.py

CHANGES.txt  LICENSE.txt  pip          PKG-INFO      setup.cfg

[root@localhost pip-7.1.0]# python setup.py install

......

 

参考连接:

https://pip.pypa.io/en/latest/installing.html

 

三、安装robotframework

 

robotframework下载地址:

https://pypi.python.org/pypi/robotframework#downloads

 

安装robotframework

[root@localhost mnt]# chmod 755 robotframework-2.9.tar.gz

[root@localhost mnt]# tar -xvzf robotframework-2.9.tar.gz

[root@localhost mnt]# cd robotframework-2.9

[root@localhost robotframework-2.9]# python setup.py install

……

 

查看是否安装成功

[root@localhost robotframework-2.9]# pybot --version

Robot Framework 2.9 (Python 2.6.6 on linux2)

[root@localhost robotframework-2.9]#

参考连接:

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#python-installation

 

问题:robotframework都安装到哪里了?

[root@localhost robotframework-2.9]# find / -name robot

/usr/lib/python2.6/site-packages/robotframework-2.9-py2.6.egg/robot

/mnt/robotframework-2.9/src/robot

/mnt/robotframework-2.9/build/lib/robot

 

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html

 

四、安装robotframework-selenium2library

 

robotframework-selenium2library下载地址

https://pypi.python.org/pypi/robotframework-selenium2library/

 

[root@localhost mnt]# chmod 755 robotframework-selenium2library-1.7.3.tar.gz

[root@localhost mnt]# tar -xvzf robotframework-selenium2library-1.7.3.tar.gz

[root@localhost robotframework-selenium2library-1.7.3]# python setup.py install

[root@localhost mnt]# cd robotframework-selenium2library-1.7.3

。。。

Downloading https://pypi.python.org/packages/source/d/docutils/docutils-0.12.tar.gz#md5=4622263b62c5c771c03502afa3157768

error: MD5 validation failed for docutils-0.12.tar.gz; possible download problem?

 

出错了,咋办?解决方法:按提示,下载并安装docutils

 

docutils下载地址

https://pypi.python.org/pypi/docutils/

https://pypi.python.org/packages/source/d/docutils/docutils-0.12.tar.gz

 

安装docutils

[root@localhost mnt]# chmod 755 docutils-0.12.tar.gz

[root@localhost mnt]# tar -xvzf docutils-0.12.tar.gz

[root@localhost docutils-0.12]# python setup.py install

 

继续安装robotframework-selenium2library

[root@localhost mnt] cd robotframework-selenium2library-1.7.3

[root@localhost robotframework-selenium2library-1.7.3]# python setup.py  install

……

/usr/lib/python2.6/site-packages/robotframework_selenium2library-1.7.3-py2.6.egg

Processing dependencies for robotframework-selenium2library==1.7.3

Searching for selenium>=2.32.0

Reading http://pypi.python.org/simple/selenium/

 

到这里可能是网络原因,又卡住了,解决方法:下载并安装selenium

 

selenium下载地址

地址1:https://pypi.python.org/simple/selenium/

地址2:https://pypi.python.org/pypi/selenium/

 

安装selenium

[root@localhost mnt]# tar -xvzf selenium-2.47.1.tar.gz

[root@localhost mnt]# cd selenium-2.47.1

[root@localhost selenium-2.47.1]# python setup.py  install

 

继续安装robotframework-selenium2library

[root@localhost mnt]# cd robotframework-selenium2library-1.7.3

[root@localhost robotframework-selenium2library-1.7.3]# ls

build          demo         LICENSE.txt  README.rst              setup.py

BUILD.rst      dist         MANIFEST.in  selenium.bmp            src

CHANGES.rst    doc          PKG-INFO     SELENIUM_COPYRIGHT.txt

COPYRIGHT.txt  INSTALL.rst  README       setup.cfg

[root@localhost robotframework-selenium2library-1.7.3]# python setup.py install

……

Using /usr/lib/python2.6/site-packages/selenium-2.47.1-py2.6.egg

Finished processing dependencies for robotframework-selenium2library==1.7.3

 

检测Selenium2Library是否安装成功

[root@localhost robotframework-selenium2library-1.7.3]# python

Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import Selenium2Library

>>> 

 


在安装过程中出现如下错误:

[root@localhost MySQL-python-1.2.5]# python setup.py install

Traceback (most recent call last):

File "setup.py", line 7, in <module>

import setuptools

ImportError: No module named setuptools

字面意思是:没有setuptools的模块,说明python缺少这个模块;

解决方法如下:

下载setuptools包

#  wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz

解压setuptools包

# tar -xvf setuptools-0.6c11.tar.gz

# cd setuptools-0.6c11

编译setuptools

# python setup.py build

开始执行setuptools安装

# python setup.py install

安装完成;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值