python 环境准备-centos7

python3环境搭建【本身centosyum底层也是py2.x实现的,装3.x的时候要实现多版本共存这里解决了这些问题】

安装编译环境
# yum -y groupinstall 'Development Tools'
# yum -y install zlib-devel bzip2-devel openssl-devel ncurese-devel

下载py3.7.3【版本号可以去https://www.python.org这里面去找,更改路径即可】
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz

3.编译安装
  解压xz:
  # xz -d Python-3.7.3.tar.xz

  解压tar:
  # tar xvf Python-3.7.3.tar

  切换到源码目录:
  # cd Python-3.7.3/

  编译、安装:
yum install libffi-devel -y【缺少这部:ModuleNotFoundError: No module named '_ctypes'】
  # ./configure && make && make install

zipimport.ZipImportError: can't decompress data
# yum -y install zlib*


4.建立Python3的软链接
# rm -f /usr/bin/python; ln -s /usr/local/bin/python3 /usr/bin/python

5.查看Python版本
# python --version

安装gcc/g++/gdb
yum install gcc
yum install gcc-c++
yum install gdb

查看是否成功安装【会出现安装的路径】
which gcc
which g++
which gdb

多版本环境下的py,设置python3.x为默认版本
查看 Python 的路径,在 /usr/bin 下面。可以看到 python 链接的是 python 2.7,所以,执行 python 就相当于执行 python 2.7
[root@VM_181_254_centos Python-3.6.1]# ls -al /usr/bin | grep python
lrwxrwxrwx 1 root root 7 Jun 2 14:10 python.bak -> python2
lrwxrwxrwx 1 root root 9 Jun 2 14:10 python2 -> python2.7
-rwxr-xr-x 1 root root 7136 Nov 6 2016 python2.7

将原来 python 的软链接重命名
# mv /usr/bin/python /usr/bin/python.bak

将 python 链接至 python3
# ln -s /usr/local/bin/python3 /usr/bin/python

这时,再查看 Python 的版本
# python -V
Python 3.6.1

#配置yum
# vi yum-config-manager
# vi /usr/bin/yum

# vi /usr/libexec/urlgrabber-ext-down #安装docker用到
vim /usr/bin/firewall-cmd #防火墙规则
里面的python修改成当前python2.x


对于没有权限的vim修改使用此命令:
w !sudo tee %

python常用库的安装
pip install requests
pip install Selenium #自动化测试工具
pip install aiohttp #提供异步web服务的库
pip install lxml #解析库html/xml支持xpath解析方式
pip install beautifulsoup4 #解析xml/html从网页提取数据
pip install pyquery #提供和jQuery类似语法解析html支持css选择器
pip install Flask #轻量级web服务框架
pip install tirnado #支持异步web框架
pip install mitmproxy #支持http,https的抓包框架
pip install pyspider #爬虫框架
pip install scrapyrt #提供调度http接口,不需要在执行scrapy命令,而是请求http来调度scrapy任务
pip install gerapy #gerapy是一个scrapy分布式管理模块


多版本下安装pyspider出现{
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "/tmp/pip-install-55pos95o/pycurl/setup.py", line 229, in configure_unix
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/usr/local/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'curl-config': 'curl-config'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-55pos95o/pycurl/setup.py", line 944, in <module>
ext = get_extension(sys.argv, split_extension_source=split_extension_source)
File "/tmp/pip-install-55pos95o/pycurl/setup.py", line 606, in get_extension
ext_config = ExtensionConfiguration(argv)
File "/tmp/pip-install-55pos95o/pycurl/setup.py", line 101, in __init__
self.configure()
File "/tmp/pip-install-55pos95o/pycurl/setup.py", line 233, in configure_unix
raise ConfigurationError(msg)
__main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory: 'curl-config': 'curl-config'
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-55pos95o/pycurl/
}
解决方法yum install curl-devel,再次pip install pyspider


安装mysql:
# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

# rpm -ivh mysql-community-release-el7-5.noarch.rpm

# yum install -y mysql mysql-server
# systemctl start mysqld #启动mysql

# systemctl stop mysqld #停止mysql
# syustemctl restart mysqld #重启mysql

mysql -uroot -p
使用密码登录mysql,其实这里会报错【我想用mongod,nosql类型比较适合大部分后台】
{
暂停mysql:systemctl stop mysqld
忽略检查权限方式启动:mysqld --skip-grant-tables &
应该要这条:mysqld --user=root --skip-grant-tables &
再次连接mysql:mysql -uroot
更新账号密码:
mysql5.7以下版本:UPDATE mysql.user SET Password=PASSWORD('123456') where USER='root';
mysql5.7版本:UPDATE mysql.user SET authentication_string=PASSWORD('123456') where USER='root';
刷新权限:flush privileges;
退出mysql:exit或quit
mysql -uroot -p
输入密码:123456
}


fro m flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
http://120.79.180.109:5000/
#在5000端口运行了web服务


import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
def get(self):
self.wirte("Hello World!")

def make_app():
return tornado.web.Application([(r"/",MainHandler),])

if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
http://120.79.180.109:8888/
#在8888端口运行了web服务


1.安装httpd
命令:yum -y install httpd

2.设置开机自动启动
命令:chkconfig httpd on
注意,CentOS7使用命令为“systemctl enable httpd”,而CentOS6命令为“chkconfig httpd on”,


3.启动apache服务器
命令:service httpd start
注意,CentOS7使用命令为“systemctl start httpd”,而CentOS6命令为“service httpd start”。

猜你喜欢

转载自www.cnblogs.com/liuruoqian/p/11308213.html