系統:
RHEL6.5
版本說明:
Python-3.5.0
Django-1.10.4
virtualenv:爲每一個項目創建不一樣的/獨立的Python環境,你將爲每一個項目安裝全部須要的軟件包到它們各自獨立的環境中。python
yum install openssl-devel gcc zlib -y
wget http://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
mkdir /usr/local/python3
解壓編譯安裝:sql
tar -xzvf Python-3.5.0.tgz cd Python-3.5.0 ./configure --prefix=/usr/local/python3 make && make install
安裝完後面會顯示:數據庫
...... Collecting setuptools Collecting pip Installing collected packages: setuptools, pip Successfully installed pip-7.1.2 setuptools-18.2
在3.5裏面,就不用再手動去安裝pip和setuptools了,自動安裝django
mv /usr/bin/python /usr/bin/python2
創建新版本的python連接和pip連接:bootstrap
ln -s /usr/local/python3/bin/python3 /usr/bin/python ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
[root@django2 ~]# python -V Python 3.5.0
引起的問題
yum使用報錯:vim
[root@django2 ~]# yum install vim -y File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax
解決方案
修改/usr/bin/yum
第一行以下:api
#!/usr/bin/python2
pip install virtualenv
[root@django2 ~]# virtualenv ~/pythonproject/virtualenv/blog --no-site-packages Using base prefix '/usr/local/python3' New python executable in /root/pythonproject/virtualenv/blog/bin/python3.5 Also creating executable in /root/pythonproject/virtualenv/blog/bin/python Installing setuptools, pip, wheel...done.
[root@django2 bin]# pwd /root/pythonproject/virtualenv/blog/bin [root@django2 bin]# source activate (blog) [root@django2 bin]#
出現前面的(blog)則運行成功!瀏覽器
(blog) [root@django2 ~]# pip install django
(blog) [root@django2 blog]# pwd /root/pythonproject/virtualenv/blog (blog) [root@django2 blog]# django-admin startproject cherry04 (blog) [root@django2 blog]# cd cherry04/ (blog) [root@django2 cherry04]# django-admin startapp blog
cherry04:項目名
blog:應用名session
(blog) [root@django2 cherry04]# python manage.py runserver ....... File "/root/pythonproject/virtualenv/blog/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/root/pythonproject/virtualenv/blog/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 39, in <module> raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc) django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
出現如上報錯,沒有sqlite3這個模塊app
(blog)[root@django2 bin]# pwd /root/pythonproject/virtualenv/blog/bin (blog) [root@django2 bin]# deactivate [root@django2 Python-3.5.0]# pwd /root/Python-3.5.0 [root@django2 Python-3.5.0]# ./configure --prefix=/usr/local/python3 [root@django2 Python-3.5.0]# make && make install
這個錯誤若是能在一開始避免最好,後面就不用再從新編譯安裝了
注:
sqlite
:是很是著名的開源嵌入式數據庫軟件,它能夠嵌入到其餘程序中使用,而且提供SQL接口用來查詢,很是方便
pysqlite
: 是一個 sqlite 爲 Python 提供的 api 接口,它讓一切對於 sqlite 的操做都變得異常簡單
可是從python2.5版本之後,pysqlite就已經被包含到標準庫中,只須要安裝sqlite3便可,但以前的版本則須要兩個都安裝,不然會報錯
[root@django2 bin]# pwd /root/pythonproject/virtualenv/blog/bin [root@django2 bin]# source activate (blog) [root@django2 cherry04]# python manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. December 18, 2016 - 20:43:42 Django version 1.10.4, using settings 'cherry04.settings' Starting development server at http://127.0.0.1:8000/
python manage.py runserver 0.0.0.0:8000
環境配置至此完成!Good luck!
本文爲原創,轉載請註明出處