CentOS 7 配置Python语言开发环境

CentOS 7 配置Python语言开发环境

初始化设置参考:http://blog.csdn.net/wh211212/article/details/52923673

安装Python 3.3

  • whOS7默认自带python2.7,无需卸载可直接新装Python3.3
# install from SCLo
[root@linuxprobe ~]# yum --enablerepo=whos-sclo-rh -y install python33
  • 设置环境变量
# load environment variables
[root@linuxprobe ~]# scl enable python33 bash
[root@linuxprobe ~]# python -V
Python 3.3.2
[root@linuxprobe ~]# which python
/opt/rh/python33/root/usr/bin/python

# 设置开机自启用环境变量设置
[root@linuxprobe ~]# vi /etc/profile.d/python33.sh
#!/bin/bash
source /opt/rh/python33/enable
export X_SCLS="`scl enable python33 'echo $X_SCLS'`"`

安装Python 3.3

  • whOS7默认自带python2.7,无需卸载可直接新装Python3.3
# install from SCLo
[root@linuxprobe ~]# yum --enablerepo=whos-sclo-rh -y install python34
  • 设置环境变量
# load environment variables
[root@linuxprobe ~]# scl enable python34 bash
[root@linuxprobe ~]# python -V
Python 3.4.2
[root@linuxprobe ~]# which python
/opt/rh/python34/root/usr/bin/python

# 设置开机自启用环境变量设置
[root@linuxprobe ~]# vi /etc/profile.d/python34.sh
#!/bin/bash
source /opt/rh/python34/enable
export X_SCLS="`scl enable python33 'echo $X_SCLS'`"`

安装Python 3.5

  • whOS7默认自带python2.7,无需卸载可直接新装Python3.5
# install from SCLo
[root@linuxprobe ~]# yum --enablerepo=whos-sclo-rh -y install python35
  • 设置环境变量
# load environment variables
[root@linuxprobe ~]# scl enable python35 bash
[root@linuxprobe ~]# python -V
Python 3.5.2
[root@linuxprobe ~]# which python
/opt/rh/python35/root/usr/bin/python

# 设置开机自启用环境变量设置
[root@linuxprobe ~]# vi /etc/profile.d/python35.sh
#!/bin/bash
source /opt/rh/python35/enable
export X_SCLS="`scl enable python33 'echo $X_SCLS'`"`

安装Django

  • 安装依赖包
# install from EPEL
[root@linuxprobe ~]# yum --enablerepo=epel -y install python-virtualenv
  • 使用普通用户wh在Virtualenv环境下安装Django
[wh@linuxprobe ~]$ virtualenv venv
New python executable in venv/bin/python
Installing Setuptools..............................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
[wh@linuxprobe ~]$ cd ~/venv
[wh@linuxprobe venv]$ source bin/activate
(venv)[wh@linuxprobe venv]$ pip install django
Downloading/unpacking django
  Downloading Django-1.11.tar.gz (7.9MB): 7.9MB downloaded
  Running setup.py egg_info for package django

    no previously-included directories found matching 'django/contrib/admin/bin'
    warning: no previously-included files matching '__pycache__' found anywhere in distribution
Downloading/unpacking pytz (from django)
  Downloading pytz-2017.2.zip (502kB): 502kB downloaded
  Running setup.py egg_info for package pytz

Installing collected packages: django, pytz
  Running setup.py install for django

    no previously-included directories found matching 'django/contrib/admin/bin'
    warning: no previously-included files matching '__pycache__' found anywhere in distribution
    changing mode of build/scripts-2.7/django-admin.py from 664 to 775
    changing mode of /home/wh/venv/bin/django-admin.py to 775
    Installing django-admin script to /home/wh/venv/bin
  Running setup.py install for pytz

Successfully installed django pytz
Cleaning up...
# the warning above is not a problem
(venv)[wh@linuxprobe venv]$ django-admin --version
1.11
(venv)[wh@linuxprobe venv]$ deactivate
[wh@linuxprobe venv]$
  • 创建测试项目
[wh@linuxprobe venv]$ cd ~/venv
[wh@linuxprobe venv]$ source bin/activate
(venv)[wh@linuxprobe venv]$ django-admin startproject testproject
(venv)[wh@linuxprobe venv]$ cd testproject
(venv)[wh@linuxprobe testproject]$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying sessions.0001_initial... OK
(venv)[wh@linuxprobe testproject]$  python manage.py createsuperuser
Username (leave blank to use 'wh'): wh
Email address: shaonbean@qq.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.  # 密码设置符合要求
This password is entirely numeric.
Password:
Password (again):
Superuser created successfully.
# 这里需要修改到创建的项目中去修改 setting.py 文件
---
> 改为: ALLOWED_HOSTS = ['*']
---
(venv)[wh@linuxprobe testproject]$ python manage.py runserver 10.1.1.53:8888
Performing system checks...

System check identified no issues (0 silenced).
April 12, 2017 - 14:20:32
Django version 1.11, using settings 'testproject.settings'
Starting development server at http://10.1.1.53:8888/
Quit the server with CONTROL-C.

- 客户端登录管理界面http://10.1.1.53:8888/admin

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏SpringBoot 核心技术

第二十七章:SpringBoot使用ApplicationEvent&Listener完成业务解耦

25340
来自专栏Java后端技术

Spring+SpringMvc+Mybatis框架集成搭建教程二(依赖配置及框架整合)

(3).在项目的resources文件夹下新建log4j.properties文件

12230
来自专栏杨建荣的学习笔记

goldengate学习-安装篇(71天)

goldengate算是数据同步的利器,可以在不同的库,平台间进行数据的同步,当然还是有一些bug的,不过还是优点大过缺点。 算是尝尝鲜,从官网下载了一个版本1...

451120
来自专栏JavaEE

springboot快速入门前言:一、springboot简介:二、springboot常用知识点:总结:

正所谓,天下武功,唯快不破,在当今生活节奏越来越快的时代,我们也要讲求效率,也要追求一个快字(不过有些方面还是不能快的,不要当快男哦)。springboot就是...

11010
来自专栏程序猿DD

Spring Cloud构建微服务架构:Hystrix监控面板【Dalston版】

前言 在上一篇《服务容错保护(hystrix断路器)》的介绍中,我们提到断路器是根据一段时间窗内的请求情况来判断并操作断路器的打开和关闭状态的。而这些请求情况的...

22670
来自专栏Java开发

jQuery ajax设置全局配置

29960
来自专栏JAVA技术站

log4j的使用配置 原

1.log4j.rootLogger = [level],appenderName,appenderName,...

10120
来自专栏散尽浮华

Linux下误删除后的恢复操作(ext3/ext4)

Linux是作为一个多用户、多任务的操作系统,文件一旦被删除是难以恢复的。尽管删除命令只是在文件节点中作删除标记,并不真正清除文件内容,但是其他用户和一些有写盘...

49170
来自专栏JackeyGao的博客

Django小技巧14: messages 框架

让用户知道应用程序发生了什么, 是个极好的用户体验。让应用程序和用户之间能够有个很好的『交流』是个不错的选择。

25340
来自专栏朱慕之的博客

Hello Hexo

Welcome to Hexo! This is your very first post. Check documentation for more info...

9210

扫码关注云+社区

领取腾讯云代金券