美文网首页
Ubuntu16.04 Python开发环境搭建

Ubuntu16.04 Python开发环境搭建

作者: 进击的欧阳 | 来源:发表于2018-05-31 16:27 被阅读0次

    一、使用U盘安装Ubuntu16.04操作系统

       1.下载.iso的系统镜像文件 ,这是下载链接:http://ftp.sjtu.edu.cn/ubuntu-cd/16.04.4/ubuntu-16.04.4-desktop-amd64.iso
    
       2.使用rufus-2.18工具在Windows7系统下,使用系统镜像文件,制作U盘启动工具
    
       3.将做好的U盘启动工具插入到需要装Ubuntu系统的电脑,配置好一些启动项,触发U盘启动
    

    二、Ubuntu16.04 系统的使用配置

    1.设置root用户的初始密码

       1.命令行输入: sudo passwd
      
       2.根据提示,输入两次相同密码,root用户的密码即生效
    

    2.安装Vim文本编译器(系统自带的Vim-tiny,使用上可能存在一些问题)

       1.卸载旧版vim: sudo apt-get remove vim-common
    
       2.安装新版full版vim: sudo apt-get install vim
    

    3.将系统默认的python2.7版本切换到python3.5

       1.删除之前的2.7版本引用: sudo rm /usr/bin/python
    
       2.创建3.5版本的快捷方式: sudo ln -s /usr/bin/python3.5 /usr/bin/python
    
       3.测试python版本: python -V
    

    4.下载安装pycharm IDE工具

       1.进入pycharm官网,下载专业版
    
       2.下载完成后,解压缩,并在解压缩的文件夹下面执行shell安装命令: sh ./pycharm.sh
    
       3.如果出现JDK错误,就需要安装JDK,下面命令一次执行: 
       sudo add-apt-repository ppa:webupd8team/java
       sudo apt-get update
       sudo apt-get install oracle-java8-installer
    
       4.重新运行安装pycharm命令:sh ./pycharm
    
       5.破解2018.1.3版本,先进入 /etc目录下,然后 sudo vim hosts
       在文件最后加上一行:
       0.0.0.0 account.jetbrains.com
       然后 在填入授权码的地方填入:
       K71U8DBPNE-eyJsaWNlbnNlSWQiOiJLNzFVOERCUE5FIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IkZvciBlZHV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SrRigMw4/+wuC5EtZBfvdl4HT/8vzMW/oUlIP4YCvA0XKyBaCJ2iX+ZCDKoPfiYXiaSiH+HxAPV6J79vvouxKrWg2XV6ShFtPLP+0gPdGq3x9R3+kJbmAm8w+FOdlWqAfJrLvpzMGNeDU14YGXiZ9bVzmIQbwrBA+c/F4tlK/DV07dsNExihqFoibnqDiVNTGombaU2dDup2gwKdL81ua8EIcGNExHe82kjF4zwfadHk3bQVvbfdAwxcDy4xBjs3L4raPLU3yenSzr/OEur1+jfOxnQSmEcMXKXgrAQ9U55gwjcOFKrgOxEdek/Sk1VfOjvS+nuM4eyEruFMfaZHzoQiuw4IqgGc45ohFH0UUyjYcuFxxDSU9lMCv8qdHKm+wnPRb0l9l5vXsCBDuhAGYD6ss+Ga+aDY6f/qXZuUCEUOH3QUNbbCUlviSz6+GiRnt1kA9N2Qachl+2yBfaqUqr8h7Z2gsx5LcIf5kYNsqJ0GavXTVyWh7PYiKX4bs354ZQLUwwa/cG++2+wNWP+HtBhVxMRNTdVhSm38AknZlD+PTAsWGu9GyLmhti2EnVwGybSD2Dxmhxk3IPCkhKAK+pl0eWYGZWG3tJ9mZ7SowcXLWDFAk0lRJnKGFMTggrWjV8GYpw5bq23VmIqqDLgkNzuoog==  
    

    5.Ubuntu16.04 安装pip工具

       1.执行:sudo apt-get install python3-pip
    
       2.创建pip3的快捷方式: sudo ln -s /usr/bin/pip3 /usr/bin/pip
    

    6.Ubuntu16.04 安装MySQL

       1.执行:sudo apt-get install mysql-server
    
       2.mysql默认编码查看: show variables like  'character%';
    
       3.如果有一些不是utf8的,则需要手动设置一下:vim /etc/mysql/mysql.conf.d/mysqld.cnf  
       在[mysqld]标签下,加入:character-set-server=utf8 ,这是服务端,客户端的编码设置方          
       式为:vim /etc/mysql/conf.d/mysql.cnf ,在[mysql]标签下添加一行:default-character-set=utf8,然后重启mysql服务:service mysql restart  
    
       4.添加远程访问权限:
       grant all on *.* to root@'%' identified by '123456';
       flush privileges;
    

    7.使用Pycharm工具进行依赖库的安装

    进入pycharm的setting界面,找到Project Interpreter菜单,选择有效的Project Interpreter(根据python指令的目录,我这里是/usr/bin/python3.5),以下,一个个安装,这里记录一下:

       1.tensorflow 1.4.1
    
       2.Django 2.0.5
    
       3.pymysql 0.8.1
    
       4.qrcode 6.0
       
       5.pycryptodome 2.6.1
    
       6.scipy 1.1.0
    

    8.Django项目上线部署(现成的项目)配置

       1. 同步数据库:
       python manage.py makemigrations
       python manage.py migrate
    
       2. 安装nginx 和 uWSGI
       sudo apt-get install nginx
       sudo pip install uwsgi
    
       3. uWSGI 和 nginx的文件配置
        uWSGI配置:
        在工程目录下创建uWSGI的配置文件 /项目绝对路径/uwsgi.ini
    
        # uwsgi.ini 文件内容
        [uwsgi]
        socket = 127.0.0.1:8000
        chdir=/项目绝对路径
        module=项目名称.wsgi
        master = true
        workers=2
        vacuum=true
        thunder-lock=true
        enable-threads=true
        harakiri=30
        post-buffering=4096
        daemonize =/项目绝对路径/uwsgi.log
    
        stats=%(chdir)/uwsgi.status
        pidfile=%(chdir)/uwsgi.pid
    
        nginx 配置:
        vi /etc/nginx/nginx.conf
        在http{}内添加server字段信息:
         
        server { 
                listen 8080; 
                server_name 服务器IP地址/或者域名; 
                charset utf-8; 
                access_log /项目绝对路径/nginx_access.log; 
                error_log /项目绝对路径/nginx_error.log;
                client_max_body_size 75M; 
                location /static {  
                        alias /项目绝对路径/static; 
                } 
                location / { 
                        include /etc/nginx/uwsgi_params; 
                        uwsgi_pass 127.0.0.1:8000; 
                } 
        }
    
    
       4.启动uWSGI 和 nginx
         sudo uwsgi --ini /项目绝对路径/uwsgi.ini
         nginx -c /etc/nginx/nginx.conf
    
         备注:启动的时候注意端口占用问题
         查询某一个进程的运行情况使用: ps aux | grep 服务名
         例如:
         ps aux |  grep uwsgi
         ps aux |  grep nginx
         停止uwsgi 可直接使用:killall -9 uwsgi
         停止nginx 可使用: nginx -s stop
    

    相关文章

      网友评论

          本文标题:Ubuntu16.04 Python开发环境搭建

          本文链接:https://www.haomeiwen.com/subject/godqsftx.html