pythonbz2
linux系統中安裝python包括以下三個步驟:
❷ python腳本如何解壓bz2文件並解壓到指定文件夾下(不是tar.bz2文件)。文件格式是DAT.bz2結尾的
PersistenceConfig(持久層配置)
我們想要一個配置了所有可用倉庫的MONGODB配置。在這個簡單的應用中我們只用了一個倉庫,所以配置也非常的簡單:
@Configuration
class PersistenceConfig {
@Bean
public AccountRepository accountRepository() throws UnknownHostException {
return new MongoAccountRepository(mongoTemplate());
❸ Python+Pandas入門2——導出csv
1、to_csv()
1、path_or_buf =None: string or file handle, default None
File path or object, if None is provided the result is returned as a string.
字元串或文件句柄,默認無文件
路徑或對象,如果沒有提供,結果將返回為字元串。
2、sep : character, default 『,』
Field delimiter for the output file.
默認字元 『 ,』
輸出文件的欄位分隔符。
3、na_rep : string, default 『』
Missing data representation
字元串,默認為 『』
浮點數格式字元串
4、float_format : string, default None
Format string for floating point numbers
字元串,默認為 None
浮點數格式字元串
5、columns : sequence, optional Columns to write
順序,可選列寫入
6、header : boolean or list of string, default True
Write out the column names. If a list of strings is given it is assumed to be aliases for the column names
字元串或布爾列表,默認為true
寫出列名。如果給定字元串列表,則假定為列名的別名。
7、index : boolean, default True
Write row names (index)
布爾值,默認為Ture
寫入行名稱(索引)
8、index_label : string or sequence, or False, default None
*Column label for index column(s) if desired. If None is given, and header and index are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex. If False do not print fields for index names. Use index_label=False for easier importing in R
字元串或序列,或False,默認為None
如果需要,可以使用索引列的列標簽。如果沒有給出,且標題和索引為True,則使用索引名稱。如果數據文件使用多索引,則應該使用這個序列。如果值為False,不列印索引欄位。在R中使用 index_label=False 更容易導入索引.
9、encoding : string, optional
編碼:字元串,可選
表示在輸出文件中使用的編碼的字元串,Python 2上默認為「ASCII」和Python 3上默認為「UTF-8」。
10、compression : string, optional
字元串,可選項
表示在輸出文件中使用的壓縮的字元串,允許值為「gzip」、「bz2」、「xz」,僅在第一個參數是文件名時使用。
11、line_terminator : string, default 『
』
字元串,默認為 『
』
在輸出文件中使用的換行字元或字元序列
12、quoting : optional constant from csv mole
*CSV模塊的可選常量
輸出是否用引號,默認參數值為0,表示不加雙引號,參數值為1,則每個欄位都會加上引號,數值也會被當作字元串看待
13、quotechar : string (length 1), default 『」』
*字元串(長度1),默認"
當quoting=1可以指定引號字元為雙引號"或單引號'
14、doublequote : boolean, default True
布爾,默認為Ture
控制一個欄位內的quotechar
15、escapechar : string (length 1), default None
字元串(長度為1),默認為None
在適當的時候用來轉義sep和quotechar的字元
16、chunksize : int or None
int或None
一次寫入行
17、tupleize_cols : boolean, default False
布爾值 ,默認為False
從版本0.21.0中刪除:此參數將被刪除,並且總是將多索引的每行寫入CSV文件中的單獨行
(如果值為false)將多索引列作為元組列表(如果TRUE)或以新的、擴展的格式寫入,其中每個多索引列是CSV中的一行。
18、date_format : string, default None
字元串,默認為None
字元串對象轉換為日期時間對象
19、decimal : string, default 『.』
字元串,默認』。』
字元識別為小數點分隔符。例如。歐洲數據使用 』,』
20、mode : str
模式:值為『str』,字元串
Python寫模式,默認「w」
❹ ubuntu下怎麼build一個完整的python
我們需要一個一個編譯這些包:
1. common.sh:這個文件里包含一些基礎設置,比如選用的GCC,CFLAGS和LDFLAGS如何配置。
[plain] view plain
export NDKDIR="/你的NDK路徑比如/android-ndk-r10c"
# GCC 版本選用,目前有4.6,4.8,4.9,選用時也注意Linux系統的類型,這里x86_64是六十四位
export COMPILER="$NDKDIR/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin"
export CC="$COMPILER/arm-linux-androideabi-gcc"
export CXX="$COMPILER/arm-linux-androideabi-g++"
export CPP="$COMPILER/arm-linux-androideabi-cpp"
export LD="$COMPILER/arm-linux-androideabi-ld"
export AS="$COMPILER/arm-linux-androideabi-as"
export AR="$COMPILER/arm-linux-androideabi-ar"
export STRIP="$COMPILER/arm-linux-androideabi-strip"
export OBJCOPY="$COMPILER/arm-linux-androideabi-obj"
export OBJDUMP="$COMPILER/arm-linux-androideabi-objmp"
export RANLIB="$COMPILER/arm-linux-androideabi-ranlib"
export NM="$COMPILER/arm-linux-androideabi-nm"
export STRINGS="$COMPILER/arm-linux-androideabi-strings"
export READELF="$COMPILER/arm-linux-androideabi-readelf"
# 選擇要編譯文件在哪個Android版本上使用,這里案例是在Android 4.2上使用,就是android 17;2.2對應Android 8,5.0對應Android 21
export ANDROID="$NDKDIR/platforms/android-17/arch-arm/usr"
# 配置系統頭文件和庫文件位置
export CFLAGS="-I$ANDROID/include --sysroot=$ANDROID"
export CXXFLAGS="-I$ANDROID/include --sysroot=$ANDROID"
export CPPFLAGS="-I$ANDROID/include"
export LDFLAGS="-L$ANDROID/lib"
2. 編譯openssl:
[plain] view plain
tar zxf openssl-1.0.1j.tar.gz
cd openssl-1.0.1j
mkdir dist
source common.sh
MACHINE=armv7 SYSTEM=android ./config -fPIC --prefix=./dist
# 在Makefile里做一些補丁,以防error
sed -i "s|-m64||" Makefile
sed -i "s|-Wall|-Wall --sysroot=$ANDROID|" Makefile
# 編譯並安裝
make
make install
3. 編譯ncurses,readline,sqlite
仿照openssl的方法,編譯另外三個庫;其實還有一個zlib需要編譯,當然後面不讓python支持bz2就可以忽略。
注意readline編譯最好選擇--with-curses,然後把編譯好的ncurses鏈接上。庫類文件編譯,盡量都加-fPIC,這是什麼,不從匯編說還真說不清楚,還是大家自己去看官方文檔吧。
對於localeconv的問題,大家最好改寫下那個locale.h,在裡面把localeconv的struct里fix放上你要的字元,比如decimal_point是".",這樣後面都不會出這類locale的問題了。
這里給出快捷的解決方案就是把localeconv幹掉,直接hardcode:
[plain] view plain
# 在ncurses編譯之前,需要打的補丁
sed -i "s/#define isDecimalPoint(c) .*/#define isDecimalPoint(c) ((c) == '.')/" form/fty_num.c
sed -i "s/localeconv()/NULL/" form/fty_num.c
[plain] view plain
# 編譯ncurses
./configure --prefix=/YourPath --disable-home-terminfo --without-ada
make
make install
[plain] view plain
# 編譯readline
./configure --prefix=/YourPath --host=arm-linux --build=x86_64-linux \
--enable-static --enable-shared --with-curses
make
make install
[plain] view plain
# 編譯sqlite
./configure --host=arm-linux --build=x86_64-linux
make
make install
4. 編譯Python:
其實過程整體和openssl沒有什麼區別,細節上有一些注意事項。
- configure文件是需要手動fix的,打開文件,搜索 ac_cv_file__dev_ptmx 和 ac_cv_file__dev_ptc;刪除對這兩個變數的自動判斷。手動去Android查看/dev文件夾里有沒有ptmx和ptc設備,有就設置為yes沒就no:
[plain] view plain
ac_cv_file__dev_ptmx=yes
ac_cv_file__dev_ptc=no
- 打開Moles/Setup.dist文件,把需要的python模塊前面的#去掉,比如#_socket socketmole.c timemole.c,要python支持網路socket介面,需要把#去掉;建議盡量多加一些包;實在編譯不過的包不要,有些模塊需要額外下載開源軟體庫編譯,就不只openssl,ncurses,readline,sqlite了。
這樣就可以configure 了:
[plain] view plain
./configure --host=arm-unknown-linux-gnu --build=x86_64-unknown-linux-gnu \
--enable-ipv6
- 有一段編譯會報錯,仔細檢查,發現python需要編譯一個程序,這個程序跑在host上,但gcc是arm的,host linux是x86_64的,所以我們需要復制一份解壓好的python代碼,然後用本地原有的gcc編譯;當然編譯時直接./configure && make就可以了,直到Parser文件夾下出現了pgen這個可執行文件;把它拿出來,復制到另一個python源碼的Parser文件夾中,修改Makefile:
[plain] view plain
sed -i "s|\$(PGEN):.*|\$(PGEN):|" Makefile
sed -i "s|\$(CC) \$(OPT) \$(LDFLAGS) \$(PGENOBJS) \$(LIBS) -o \$(PGEN)|echo \"fake Parser/pgen\"|" Makefile
- 解決locale的問題,還有一些常量問題,笨方法hardcode:
[plain] view plain
sed -i "s|.*localeconv().*||" Objects/stringlib/localeutil.h
sed -i "s|locale_data->grouping|\"\"|" Objects/stringlib/localeutil.h
sed -i "s|locale_data->thousands_sep|\"\"|" Objects/stringlib/localeutil.h
sed -i "s|.*localeconv().*||" Objects/stringlib/formatter.h
sed -i "s|locale_data->grouping|\"\"|" Objects/stringlib/formatter.h
sed -i "s|locale_data->thousands_sep|\"\"|" Objects/stringlib/formatter.h
sed -i "s|locale_data->decimal_point|\".\"|" Objects/stringlib/formatter.h
sed -i "s|.*localeconv().*||" Python/pystrtod.c
sed -i "s|locale_data->decimal_point|\".\"|" Python/pystrtod.c
sed -i "s|I_PUSH|0x5302|" Moles/posixmole.c
sed -i "s|p->pw_gecos|\"\"|" Moles/pwdmole.c
- Moles/socketmole.c: 需要去掉一些#if,不然頭文件里沒有定義,或者直接去$ANDROID的include文件夾把相應.h文件補充完整也可以。
[cpp] view plain
...
Py_BEGIN_ALLOW_THREADS
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_acquire_lock(netdb_lock, 1);
#endif
h = gethostbyaddr(ap, al, af);
Py_END_ALLOW_THREADS
ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr), af);
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(netdb_lock);
#endif
return ret;
...
make然後make -i install,好啦,python編譯出來啦!
下面就是放到android上跑了。
需要Android是root的,不root也可以,就是得找個地方放。
需要把python編譯好的文件夾打包放到android上,還有sqlite里的那個so文件。
root的話可以在/system/bin里軟鏈接一個python。當然,sqlite.so.3要放在/system/lib里。
其實sqlite是可以不編譯的,但是我們的Django需要它,所以還是弄出來吧,ssl也可以不用,但是為了伺服器支持https,還是編譯下吧。
這樣就可以運行python了。
[html] view plain
# python
>>> 1+2
3
然後下載setuptools (https://pypi.python.org/pypi/setuptools/7.0) 和 pip (https://pypi.python.org/pypi/pip/1.5.6) 解壓並安裝:
[plain] view plain
gzip -d setuptools-7.0.tar.gz
tar xf setuptools-7.0.tar
cd setuptools-7.0
python setup.py build
python setup.py install
gzip -d pip-1.5.6.tar.gz
tar xf pip-1.5.6.tar
cd pip-1.5.6
python setup.py build
python setup.py install
把pip軟鏈接到/system/bin。好了,python有了pip,哈哈,隨心安裝包吧。先來個pip install virtualenv
接下去可以安裝django django-sslserver,把django-admin軟鏈接到/system/bin,就可以寫網站啦:
[plain] view plain
django-admin startproject test001
cd test001
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
不安裝django也可以直接對一個文件夾提供http服務:
[plain] view plain
python -m SimpleHTTPServer
有了server,在家庭里就可以搭建平台啦,如果有多個手機,連上wifi,就可以不用接線,完成無線分布式伺服器,趕快練習loadbalance吧。
嗯嗯,看看需不需要用手機伺服器隨時監控家裡的活動,然後插上SIM卡還能自動給我發簡訊,嘿嘿。
後面我們來想像怎麼解決pip install有時需要編譯c文件的問題。其實有團隊已經解決了這個問題。
下載Droid for GCC plugin的apk:http://www.liqucn.com/rj/228351.shtml (這個不是官網,最好去google play下載)
把apk解壓,然後找到gcc的壓縮包,裡面就有gcc了,把它放到Android上:
[plain] view plain
#include <stdio.h>
int main() {
printf("hello world!\n");
return 0;
}
然後gcc -o test test.c,並運行./test,完美輸出hello world。趕緊軟鏈接到/system/bin里吧。
好了,這樣numpy都可以編譯安裝了。還可以編譯下erl,把rabbitmq編譯下,弄個分布式也不是問題。最好移植一下lxc,然後把raspberry里的arm版java搬過來就無敵啦。買個USBminiB轉RJ45的頭就可以插網線了。
總體來說,可以搭建移動伺服器了,以後寫一些網頁版小應用,想用的時候android開個熱點,電腦一連,開始enjoy!
❺ Windows 版本 Python 2.7.10 怎麼安裝bz2 這個模塊。
你直接去pypi去下載bz2的包,然後解壓並cd到解壓目錄,用Python setup.py install去安裝,Python所有的包都這么安最方便快捷。如果是windows系統,安裝時需要依賴包的話,缺什麼就下什麼,然後一洋的方式安裝,Ubuntu會直接下載依賴。
❻ python 如何導入bz2模塊 ubuntu
bz2是python自帶的標准庫,直接import就可以了,不過你既然提問了,應該是遇到問題了。
如果python是你自己編譯的,需要安裝bzip2-devel後再編譯,否著bz2無法使用。
如果解決了您的問題請採納!
如果未解決請繼續追問
❼ linux安裝python環境
放到自己准備好的文件夾
2.解壓
命令: # tar -zxvf Python-3.8.5.tgz
解壓到准備好的文件內
3.進入解壓後的目錄,編譯安裝。
cd Python-3.8.5
./configure --prefix=/usr/local/python3
可能會See config.log' for more details出現See config.log' for more details錯誤,需要安裝gcc環境
命令: yum install -y gcc
4.安裝:
安裝依賴環境:
首先: sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
然後: make
最後: make install
完成 make install實際上是把生成的執行文件拷貝到之前configure命令指定的目錄/usr/local/python3下。
到這里安裝已經結束
5.創建軟鏈接
ln -s /usr/tools/Python3/bin/python3 /usr/tools/python3
6.加入環境變數:
vim /etc/profile
增加: export PATH=$PATH:/usr/tools/Python/bin
:wq 退出
source /etc/profile
總結:完成上面的步驟,就完成了python在linux環境的配置。基礎知識只能滿足你60%的學習需求,剩下的40%就要在實戰中補足,我要做的就是補充你剩下的40%。OK,這次分享就到這里了,有什麼疑問可以隨時留言溝通,互相學習進步!
歡迎加入QQ群:547349021
小提示:群名雖然叫selenium+unittest,但是我們不限任何測試領域的溝通交流和學習,讓我們一起補足缺失的40%吧!
❽ CentOS+nginx+uwsgi+Python 多站點環境搭建
轉自 Xiongpq
http://www.cnblogs.com/xiongpq/p/3381069.html
略有補充(可能出現錯誤及解決辦法)
環境:
CentOS X64 6.4
nginx 1.5.6
Python 2.7.5
正文:
一:安裝需要的類庫及Python2.7.5
安裝必要的開發包
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
CentOS 自帶Python2.6.6,但我們可以再安裝Python2.7.5:
cd ~
wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
tar xvf Python-2.7.5.tar.bz2
cd Python-2.7.5
./configure --prefix=/usr/local
make && make altinstall
安裝完畢後,可是使用」python2.7」命令進入python2.7的環境。
二:安裝Python包管理
easy_install包 https://pypi.python.org/pypi/distribute
方便安裝Python的開發包
cd ~
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz
tar xf distribute-0.6.49.tar.gz
cd distribute-0.6.49python2.7 setup.py install
easy_install --version
紅色部分必須是「python2.7」,否則將安裝到默認的2.6環境內。
pip包 https://pypi.python.org/pypi/pip
安裝pip的好處是可以pip list、pip uninstall 管理Python包, easy_install沒有這個功能,只有uninstall
easy_install pip
pip --version
三:安裝uwsgi
uwsgi: https://pypi.python.org/pypi/uWSGI
uwsgi參數詳解: http://uwsgi-docs.readthedocs.org/en/latest/Options.html
pip install uwsgi
uwsgi --version
測試uwsgi是否正常:
新建test.py文件,內容如下:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
然後在終端運行:
uwsgi --http :8001 --wsgi-file test.py
在瀏覽器內輸入: http://你購買的雲主機公網ip:8001 ,看是否有「Hello World」輸出,若沒有輸出,請檢查你的安裝過程。
四:安裝django
pip install django
測試django是否正常,運行:
django-admin.py startproject demosite
cd demositepython2.7 manage.py runserver 0.0.0.0:8002
在瀏覽器內輸入: http://1 你購買的雲主機公網 :8002,檢查django是否運行正常。
五:安裝nginx
cd ~
wget http://nginx.org/download/nginx-1.5.6.tar.gz
tar xf nginx-1.5.6.tar.gz
cd nginx-1.5.6
./configure --prefix=/usr/local/nginx-1.5.6 \
--with-http_stub_status_mole \
--with-http_gzip_static_mole
make && make install
安裝Nginx時報錯
錯誤提示:
./configure: error: the HTTP rewrite mole requires the PCRE library.
安裝pcre-devel與openssl-devel解決問題
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx
make
make install
六:配置uwsgi
uwsgi支持ini、xml等多種配置方式,但個人感覺ini更方便:
在/ect/目錄下新建uwsgi9090.ini,添加如下配置:
[uwsgi]
socket =
master = true //主進程
vhost = true //多站模式
no-stie = true //多站模式時不設置入口模塊和文件
workers = 2 //子進程數
reload-mercy = 10
vacuum = true //退出、重啟時清理文件
max-requests = 1000
limit-as = 512
buffer-sizi = 30000
pidfile = /var/run/uwsgi9090.pid //pid文件,用於下面的腳本啟動、停止該進程
daemonize = /website/uwsgi9090.log
設置uwsgi開機啟動,在/etc/init.d/目錄下新建uwsgi9090文件,內容如下:
uwsgi9090
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'
### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the uwsgi web server
# Description: starts uwsgi using start-stop-daemon
### END INIT INFO
# Author: licess
# website: http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi9090
DAEMON=/usr/local/bin/uwsgi
CONFIGFILE=/etc/$NAME.ini
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON $CONFIGFILE || echo -n "uwsgi already running"
}
do_stop() {
$DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
rm -f $PIDFILE
echo "$DAEMON STOPED."
}
do_reload() {
$DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload"
}
do_status() {
ps aux|grep $DAEMON
}
case "$1" in
status)
echo -en "Status $NAME: \n"
do_status
;;
start)
echo -en "Starting $NAME: \n"
do_start
;;
stop)
echo -en "Stopping $NAME: \n"
do_stop
;;
reload|graceful)
echo -en "Reloading $NAME: \n"
do_reload
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2
exit 3
;;
esac
exit 0
uwsgi9090
然後在終端執行:
-- 添加服務
chkconfig --add uwsgi9090
-- 設置開機啟動
chkconfig uwsgi9090 on
七:設置nginx
找到nginx的安裝目錄/usr/local/nginx,打開conf/nginx.conf文件,修改server配置
server {
listen 80;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass ; //必須和uwsgi中的設置一致
index index.html index.htm;
client_max_body_size 35m;
}
}
注意 :安裝django這步中startproject的demosite路徑,需要和nginx.conf中 uwsgi_param UWSGI_CHDIR /demosite;對應上。
設置nginx開機啟動,在/etc/init.d/目錄下新建nginx文件,內容如下:
nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/opt/nginx-1.5.6/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/opt/nginx-1.5.6/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
nginx
然後在終端執行:
-- 添加服務
chkconfig --add nginx
-- 設置開機啟動
chkconfig nginx on
八:測試
OK,一切配置完畢,在終端運行
service uwsgi9090 start
service nginx start
錯誤1:
[root@VM_23_251_centos nginx-1.5.6]# service uwsgi9090 start
env: /etc/init.d/uwsgi9090: Permission denied
[root@VM_23_251_centos nginx-1.5.6]# service nginx start
env: /etc/init.d/nginx: Permission denied
解決辦法1:把可執行勾選上
錯誤2:
[root@VM_23_251_centos ~]# sudo service nginx start
env: /etc/init.d/nginx: No such file or directory
解決辦法1:
Be careful what text editors you use on your local Windows computer. Some create Windows-style line endings (\r\n, CR-LF), which cause problems like this on Unix-like systems such as Linux or Mac OS X.
If you use such an editor, adjust its settings so that it creates files with Unix-style line endings. If the editor has no such setting, you should not be using it at all.
文本格式由windows 改為unix版
錯誤3:
*** WARNING: Can't find section "uwsgi" in INI configuration file /etc/uwsgi9090.ini ***
解決辦法3:
在瀏覽器輸入: http:// 雲主機公網ip,恭喜你可以看到django的「It work」了~
九:多站配置
我採用運行多個uwsgi服務的方法來實現多個站點。
重復第六步,創建uwsgi9091.ini,並相應修改文件中的
socket = 127.0.0.1:9091
pidfile = /var/run/uwsgi9091.pid
daemonize = /website/uwsgi9091.log
並創建服務uwsgi9091,設置開機啟動。
然後修改nginx的配置文件為:
nginx
然後我們就可以通過 http://127.0.0.1:1300 來訪問新的網站了。
十:其他配置
防火牆設置
CentOS默認關閉外部對80、3306等埠的訪問,所以要在其他計算機訪問這台伺服器,就必須修改防火牆配置,打開/etc/sysconfig/iptables
在「-A INPUT –m state --state NEW –m tcp –p –dport 22 –j ACCEPT」,下添加:
-A INPUT -m state --state NEW -m tcp -p -dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
然後保存,並關閉該文件,在終端內運行下面的命令,刷新防火牆配置:
service iptables restart
安裝Mysqldb
yum -y install mysql-develeasy_install-2.7 MySQL-python
注意紅色部分,easy_install-2.7,否則它將默認安裝到Python2.6環境內。
------------------------------------------------------------------------------------------------------------------
2014年12月02日添加:
CentOS 7中默認使用Firewalld做防火牆,所以修改iptables後,在重啟系統後,根本不管用。
Firewalld中添加埠方法如下:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
❾ python 讀取CSV 文件
讀取一個CSV 文件
最全的
一個簡化版本
filepath_or_buffer : str,pathlib。str, pathlib.Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)
可以是URL,可用URL類型包括:http, ftp, s3和文件。對於多文件正在准備中
本地文件讀取實例:://localhost/path/to/table.csv
**sep **: str, default 『,』
指定分隔符。如果不指定參數,則會嘗試使用逗號分隔。分隔符長於一個字元並且不是『s+』,將使用python的語法分析器。並且忽略數據中的逗號。正則表達式例子:' '
**delimiter **: str, default None
定界符,備選分隔符(如果指定該參數,則sep參數失效)
delim_whitespace : boolean, default False.
指定空格(例如』 『或者』 『)是否作為分隔符使用,等效於設定sep='s+'。如果這個參數設定為Ture那麼delimiter 參數失效。
在新版本0.18.1支持
header : int or list of ints, default 『infer』
指定行數用來作為列名,數據開始行數。如果文件中沒有列名,則默認為0,否則設置為None。如果明確設定header=0 就會替換掉原來存在列名。header參數可以是一個list例如:[0,1,3],這個list表示將文件中的這些行作為列標題(意味著每一列有多個標題),介於中間的行將被忽略掉。
注意:如果skip_blank_lines=True 那麼header參數忽略注釋行和空行,所以header=0表示第一行數據而不是文件的第一行。
**names **: array-like, default None
用於結果的列名列表,如果數據文件中沒有列標題行,就需要執行header=None。默認列表中不能出現重復,除非設定參數mangle_pe_cols=True。
index_col : int or sequence or False, default None
用作行索引的列編號或者列名,如果給定一個序列則有多個行索引。
如果文件不規則,行尾有分隔符,則可以設定index_col=False 來是的pandas不適用第一列作為行索引。
usecols : array-like, default None
返回一個數據子集,該列表中的值必須可以對應到文件中的位置(數字可以對應到指定的列)或者是字元傳為文件中的列名。例如:usecols有效參數可能是 [0,1,2]或者是 [『foo』, 『bar』, 『baz』]。使用這個參數可以加快載入速度並降低內存消耗。
as_recarray : boolean, default False
不贊成使用:該參數會在未來版本移除。請使用pd.read_csv(...).to_records()替代。
返回一個Numpy的recarray來替代DataFrame。如果該參數設定為True。將會優先squeeze參數使用。並且行索引將不再可用,索引列也將被忽略。
**squeeze **: boolean, default False
如果文件值包含一列,則返回一個Series
**prefix **: str, default None
在沒有列標題時,給列添加前綴。例如:添加『X』 成為 X0, X1, ...
**mangle_pe_cols **: boolean, default True
重復的列,將『X』...』X』表示為『X.0』...』X.N』。如果設定為false則會將所有重名列覆蓋。
dtype : Type name or dict of column -> type, default None
每列數據的數據類型。例如 {『a』: np.float64, 『b』: np.int32}
**engine **: {『c』, 『python』}, optional
Parser engine to use. The C engine is faster while the python engine is currently more feature-complete.
使用的分析引擎。可以選擇C或者是python。C引擎快但是Python引擎功能更加完備。
converters : dict, default None
列轉換函數的字典。key可以是列名或者列的序號。
true_values : list, default None
Values to consider as True
false_values : list, default None
Values to consider as False
**skipinitialspace **: boolean, default False
忽略分隔符後的空白(默認為False,即不忽略).
skiprows : list-like or integer, default None
需要忽略的行數(從文件開始處算起),或需要跳過的行號列表(從0開始)。
skipfooter : int, default 0
從文件尾部開始忽略。 (c引擎不支持)
skip_footer : int, default 0
不推薦使用:建議使用skipfooter ,功能一樣。
nrows : int, default None
需要讀取的行數(從文件頭開始算起)。
na_values : scalar, str, list-like, or dict, default None
一組用於替換NA/NaN的值。如果傳參,需要制定特定列的空值。默認為『1.#IND』, 『1.#QNAN』, 『N/A』, 『NA』, 『NULL』, 『NaN』, 『nan』`.
**keep_default_na **: bool, default True
如果指定na_values參數,並且keep_default_na=False,那麼默認的NaN將被覆蓋,否則添加。
**na_filter **: boolean, default True
是否檢查丟失值(空字元串或者是空值)。對於大文件來說數據集中沒有空值,設定na_filter=False可以提升讀取速度。
verbose : boolean, default False
是否列印各種解析器的輸出信息,例如:「非數值列中缺失值的數量」等。
skip_blank_lines : boolean, default True
如果為True,則跳過空行;否則記為NaN。
**parse_dates **: boolean or list of ints or names or list of lists or dict, default False
infer_datetime_format : boolean, default False
如果設定為True並且parse_dates 可用,那麼pandas將嘗試轉換為日期類型,如果可以轉換,轉換方法並解析。在某些情況下會快5~10倍。
**keep_date_col **: boolean, default False
如果連接多列解析日期,則保持參與連接的列。默認為False。
date_parser : function, default None
用於解析日期的函數,默認使用dateutil.parser.parser來做轉換。Pandas嘗試使用三種不同的方式解析,如果遇到問題則使用下一種方式。
1.使用一個或者多個arrays(由parse_dates指定)作為參數;
2.連接指定多列字元串作為一個列作為參數;
3.每行調用一次date_parser函數來解析一個或者多個字元串(由parse_dates指定)作為參數。
**dayfirst **: boolean, default False
DD/MM格式的日期類型
**iterator **: boolean, default False
返回一個TextFileReader 對象,以便逐塊處理文件。
chunksize : int, default None
文件塊的大小, See IO Tools docs for more information on iterator and chunksize.
compression : {『infer』, 『gzip』, 『bz2』, 『zip』, 『xz』, None}, default 『infer』
直接使用磁碟上的壓縮文件。如果使用infer參數,則使用 gzip, bz2, zip或者解壓文件名中以『.gz』, 『.bz2』, 『.zip』, or 『xz』這些為後綴的文件,否則不解壓。如果使用zip,那麼ZIP包中國必須只包含一個文件。設置為None則不解壓。
新版本0.18.1版本支持zip和xz解壓
thousands : str, default None
千分位分割符,如「,」或者「."
decimal : str, default 『.』
字元中的小數點 (例如:歐洲數據使用』,『).
float_precision : string, default None
Specifies which converter the C engine should use for floating-point values. The options are None for the ordinary converter, high for the high-precision converter, and round_trip for the round-trip converter.
指定
**lineterminator **: str (length 1), default None
行分割符,只在C解析器下使用。
**quotechar **: str (length 1), optional
引號,用作標識開始和解釋的字元,引號內的分割符將被忽略。
quoting : int or csv.QUOTE_* instance, default 0
控制csv中的引號常量。可選 QUOTE_MINIMAL (0), QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or QUOTE_NONE (3)
doublequote : boolean, default True
雙引號,當單引號已經被定義,並且quoting 參數不是QUOTE_NONE的時候,使用雙引號表示引號內的元素作為一個元素使用。
escapechar : str (length 1), default None
當quoting 為QUOTE_NONE時,指定一個字元使的不受分隔符限值。
comment : str, default None
標識著多餘的行不被解析。如果該字元出現在行首,這一行將被全部忽略。這個參數只能是一個字元,空行(就像skip_blank_lines=True)注釋行被header和skiprows忽略一樣。例如如果指定comment='#' 解析『#empty a,b,c 1,2,3』 以header=0 那麼返回結果將是以』a,b,c'作為header。
encoding : str, default None
指定字元集類型,通常指定為'utf-8'. List of Python standard encodings
dialect : str or csv.Dialect instance, default None
如果沒有指定特定的語言,如果sep大於一個字元則忽略。具體查看csv.Dialect 文檔
tupleize_cols : boolean, default False
Leave a list of tuples on columns as is (default is to convert to a Multi Index on the columns)
error_bad_lines : boolean, default True
如果一行包含太多的列,那麼默認不會返回DataFrame ,如果設置成false,那麼會將改行剔除(只能在C解析器下使用)。
warn_bad_lines : boolean, default True
如果error_bad_lines =False,並且warn_bad_lines =True 那麼所有的「bad lines」將會被輸出(只能在C解析器下使用)。
**low_memory **: boolean, default True
分塊載入到內存,再低內存消耗中解析。但是可能出現類型混淆。確保類型不被混淆需要設置為False。或者使用dtype 參數指定類型。注意使用chunksize 或者iterator 參數分塊讀入會將整個文件讀入到一個Dataframe,而忽略類型(只能在C解析器中有效)
**buffer_lines **: int, default None
不推薦使用,這個參數將會在未來版本移除,因為他的值在解析器中不推薦使用
compact_ints : boolean, default False
不推薦使用,這個參數將會在未來版本移除
如果設置compact_ints=True ,那麼任何有整數類型構成的列將被按照最小的整數類型存儲,是否有符號將取決於use_unsigned 參數
use_unsigned : boolean, default False
不推薦使用:這個參數將會在未來版本移除
如果整數列被壓縮(i.e. compact_ints=True),指定被壓縮的列是有符號還是無符號的。
memory_map : boolean, default False
如果使用的文件在內存內,那麼直接map文件使用。使用這種方式可以避免文件再次進行IO操作。
ref:
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html