python2.7 之centos7 安装 pip, Scrapy

一、确定python版本在2.7及以上

强烈建议升级python2.7后再安装pip与setuptools,如果不这样操作会出现很多莫明的问题,让你酸爽到天明!!

 如果你是升级到python2.7,更大的可能性是全部通过python setup.py 编译安装,所需要的包含但不限于这些包

 
lxml,zope.interface,Twisted,characteristic,pyasn1-modules,service-identity,Scrapy

  PS:我一开始就是编译安装的,其中最多的问题是:

 
error: command  'gcc'  failed with  exit  status 1

   后来我发现,如果有这样的提示不是缺少devel包就是少某一个lib库文件;最令我哭笑不得是安装Scrapy 提示成功,但无法创建项目,测试样例都跑不了,最终我果断的换centos7了!

 

###################以下内容都是Centos 7上的操作,升级到python2.7的同学请绕行##############

二、确定安装了yum的epel最新库


三、如果系统中安装有audit这个包请先移除,它会影响到Scrapy的安装

 
#yum remove audit

四、安装Scarpy 所需要的开发包

 
#yum install -y python-devel gcc libffi-devel openssl-devel libxslt-devel libxml2-devel

五、安装pip与setuptools

#yum install python-pip -y
#pip install  setuptools
#pip install setuptools --upgrade

六、安装Scrapy

# pip install Scrapy
Collecting Scrapy
   Using cached Scrapy-1.0.3-py2-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9  in  /usr/lib/python2 .7 /site-packages  (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib  in  /usr/lib/python2 .7 /site-packages  (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL  in  /usr/lib/python2 .7 /site-packages  (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.8.0  in  /usr/lib/python2 .7 /site-packages  (from Scrapy)
Collecting lxml (from Scrapy)
   Using cached lxml-3.4.4. tar .gz
Collecting Twisted>=10.0.0 (from Scrapy)
   Using cached Twisted-15.4.0. tar .bz2
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2  in  /usr/lib/python2 .7 /site-packages  (from Scrapy)
Collecting service-identity (from Scrapy)
   Using cached service_identity-14.0.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): cryptography>=0.7  in  /usr/lib64/python2 .7 /site-packages  (from pyOpenSSL->Scrapy)
Collecting zope.interface>=3.6.0 (from Twisted>=10.0.0->Scrapy)
   Using cached zope.interface-4.1.3. tar .gz
Collecting characteristic>=14.0.0 (from service-identity->Scrapy)
   Using cached characteristic-14.3.0-py2.py3-none-any.whl
Collecting pyasn1-modules (from service-identity->Scrapy)
   Using cached pyasn1_modules-0.0.8-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): pyasn1  in  /usr/lib/python2 .7 /site-packages  (from service-identity->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): idna>=2.0  in  /usr/lib/python2 .7 /site-packages  (from cryptography>=0.7->pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools  in  /usr/lib/python2 .7 /site-packages  (from cryptography>=0.7->pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): enum34  in  /usr/lib/python2 .7 /site-packages  (from cryptography>=0.7->pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): ipaddress  in  /usr/lib/python2 .7 /site-packages  (from cryptography>=0.7->pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cffi>=1.1.0  in  /usr/lib64/python2 .7 /site-packages  (from cryptography>=0.7->pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): pycparser  in  /usr/lib/python2 .7 /site-packages  (from cffi>=1.1.0->cryptography>=0.7->pyOpenSSL->Scrapy)
Installing collected packages: lxml, zope.interface, Twisted, characteristic, pyasn1-modules, service-identity, Scrapy
   Running setup.py  install  for  lxml
   Running setup.py  install  for  zope.interface
   Running setup.py  install  for  Twisted
Successfully installed Scrapy-1.0.3 Twisted-15.4.0 characteristic-14.3.0 lxml-3.4.4 pyasn1-modules-0.0.8 service-identity-14.0.0 zope.interface-4.1.3

七、创建项目

 
[root@localhost workspace] # scrapy startproject tutorial
2015-10-15 21:54:24 [scrapy] INFO: Scrapy 1.0.3 started (bot: scrapybot)
2015-10-15 21:54:24 [scrapy] INFO: Optional features available: ssl, http11
2015-10-15 21:54:24 [scrapy] INFO: Overridden settings: {}
New Scrapy project  'tutorial'  created  in :
     /workspace/tutorial
 
You can start your first spider with:
     cd  tutorial
     scrapy genspider example example.com

八、目录结构

 
[root@localhost workspace] # tree
.
└── tutorial
     ├── scrapy.cfg
     └── tutorial
         ├── __init__.py
         ├── items.py
         ├── pipelines.py
         ├── settings.py
         └── spiders
             └── __init__.py
 
3 directories, 6 files
### 回答1: 1. 首先,需要下载Python 2.7的源代码包,可以从官网下载或者使用以下命令下载: ``` wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz ``` 2. 解压源代码包: ``` tar -zxvf Python-2.7.18.tgz ``` 3. 进入解压后的目录: ``` cd Python-2.7.18 ``` 4. 配置安装选项: ``` ./configure --prefix=/usr/local/python2.7 ``` 这里将Python 2.7安装到了/usr/local/python2.7目录下,可以根据自己的需要修改。 5. 编译并安装: ``` make && make install ``` 6. 配置环境变量: ``` vi /etc/profile ``` 在文件末尾添加以下内容: ``` export PATH=$PATH:/usr/local/python2.7/bin ``` 保存并退出,执行以下命令使配置生效: ``` source /etc/profile ``` 7. 验证安装: ``` python -V ``` 如果输出Python 2.7.x,则表示安装成功。 注意:CentOS 7默认安装Python 2.7,如果需要安装其他版本的Python,可以使用类似的方法安装。 ### 回答2: 在CentOS 7中安装Python 2.7非常简单,只需要执行一些命令,以下是详细步骤: 1.首先,需要确认系统已经安装了gcc和make工具。如果没有安装,可以通过命令apt-get install gcc make安装。 2.然后需要下载并安装Python 2.7的源代码。可以在Python官方网站(https://www.python.org/downloads/) 下载Python 2.7版本的源代码。也可以使用wget命令在终端中下载: wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz 3.在下载完成后,需要解压刚刚下载的源代码包: tar -zxvf Python-2.7.18.tgz 4.接下来,需要进入到Python的源代码目录中,执行以下命令: cd Python-2.7.18 ./configure --prefix=/usr/local ./configure参数说明: --prefix=/usr/local意味着我们将Python 2.7安装在/usr/local/bin目录下。 5.在所有配置都设置好之后,开始编译和安装Python 2.7: make && make altinstall make altinstall安装Python 2.7的时候,不会覆盖系统自带的Python 2.7。不同的地方在于,使用make install命令会覆盖系统自带的Python 2.7,这可能会导致不必要的麻烦。 6.接下来,在终端中输入Python命令测试Python 2.7是否已经安装成功: python2.7 如果已经成功安装,终端将会显示Python 2.7.x版本的信息。 总结 以上就是在CentOS 7上安装Python 2.7的详细步骤。安装过程相对来说非常简单,只需要注意一些细节问题就行了。如果遇到问题,可以参考Linux运维社区中的相关问题和解决方案。 ### 回答3: CentOS 7操作系统自带Python 2.7,但是默认的版本是Python 2.7.5,而有些应用程序需要更新的Python 2.7版本才能正常工作。本文介绍了CentOS 7如何安装Python 2.7的步骤。 第一步:安装必要的开发工具 我们需要安装一些开发工具,包括: Yum-utils:提供yum-config-manager实用程序。 Development Tools:GNU C / C++编译器、make工具以及用于构建和编译软件包所需的其他工具等。 在终端中运行以下命令以安装开发工具: ``` sudo yum install yum-utils sudo yum groupinstall development ``` 第二步:添加SCL存储库 在CentOS 7上,Python 2.7存储在Software Collections库(SCL)中,必须将其添加到系统中。 ``` sudo yum install centos-release-scl ``` 第三步:安装Python 2.7 现在,我们可以安装Python 2.7了。 ``` sudo yum install rh-python36 ``` 第四步:设置Python 2.7作为默认版本 安装后,默认情况下不会替换系统的Python版本。要在CentOS 7上使用Python 2.7作为默认解释器,请更新一些系统默认设置。 ``` scl enable rh-python36 bash echo 'source scl_source enable rh-python36' >> ~/.bashrc ``` 我们已将Python 2.7配置为在CentOS 7上运行时使用的默认解释器。 第五步:验证Python版本 要验证安装Python版本,请在终端中运行以下命令: ``` python --version ``` 如果输出的版本为Python 2.7.x,我们已成功安装Python 2.7
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值