Verbatim https://www.dazhuanlan.com/2019/08/25/5d623abdb609d/
Close * .pyc document generation
py when other import documents, the document will be saved py a pyc accelerate the next load.
But in order not to affect the test directory structure can be closed:
import sys
sys.dont_write_bytecode = True
Installation pip
1. Install easy_install
wget https://bootstrap.pypa.io/ez_setup.py --no-check-certificate
python ez_setup.py --insecure
2. Install pip Download: https://pypi.python.org/pypi/pip
解压,安装.
wget https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz#md5=3823d2343d9f3aaab21cf9c917710196
tar -zxvf pip-7.1.2.tar.gz
cd pip-7.1.2
python setup.py install
Installation PIP (method recommended by the automatic integration dependent)
apt-get install python-pip # Ubuntu
yum install python-pip # RedHat
pip use of domestic sources
linux documentation in ~ / .pip / pip.conf, windows in% HOMEPATH% pippip.ini
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com
A plurality of sources (alternate):
[global]
timeout=40
index-url = http://mirrors.aliyun.com/pypi/simple/
extra-index-url = http://pypi.douban.com/simple/
[install]
trusted-host=
mirrors.aliyun.com
pypi.douban.com
China currently has pypi Mirror:
http://pypi.douban.com/simple/ 豆瓣
http://mirrors.aliyun.com/pypi/simple/ 阿里云
pip parameters explained
# pip --help
Usage:
pip <command> [options]
Commands:
install 安装软件.
uninstall 卸载软件.
freeze 按着一定格式输出已安装软件列表
list 列出已安装软件.
show 显示软件详细信息.
search 搜索软件,类似yum里的search.
wheel Build wheels from your requirements.
zip 不推荐. Zip individual packages.
unzip 不推荐. Unzip individual packages.
bundle 不推荐. Create pybundles.
help 当前帮助.
General Options:
-h, --help 显示帮助.
-v, --verbose 更多的输出,最多可以使用3次
-V, --version 现实版本信息然后退出.
-q, --quiet 最少的输出.
--log-file <path> 覆盖的方式记录verbose错误日志,默认文档:/root/.pip/pip.log
--log <path> 不覆盖记录verbose输出的日志.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--timeout <sec> 连接超时时间 (默认15秒).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
--cert <path> 证书.
Use of Anaconda conda
miniconda installation (official download address: https: //conda.io/miniconda.html):
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
bash Miniconda2-latest-Linux-x86_64.sh
Installation scipy (Tsinghua source specified):
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r scipy
Modify conda for domestic source:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
Direct installation:
conda install numpy
conda install scikit-learn
Neural Network dependencies:
conda install numpy
conda install pandas
conda install scipy
View installation list:
conda list
# packages in environment at /root/miniconda2:
#
cffi 1.9.1 py27_0
conda 4.3.13 py27_0
conda-env 2.6.0 0
cryptography 1.7.1 py27_0
enum34 1.1.6 py27_0
idna 2.2 py27_0
ipaddress 1.0.18 py27_0
libffi 3.2.1 1
libgfortran 3.0.0 1
mkl 2017.0.1 0
numpy 1.12.0 py27_0
openssl 1.0.2k 0
pip 9.0.1 py27_1
pyasn1 0.1.9 py27_0
pycosat 0.6.1 py27_1
pycparser 2.17 py27_0
pyopenssl 16.2.0 py27_0
python 2.7.13 0
readline 6.2 2
requests 2.12.4 py27_0
ruamel_yaml 0.11.14 py27_1
scikit-learn 0.18.1 <pip>
scipy 0.18.1 np112py27_1
setuptools 27.2.0 py27_0
six 1.10.0 py27_0
sklearn 0.0 <pip>
sqlite 3.13.0 0
tk 8.5.18 0
wheel 0.29.0 py27_0
yaml 0.1.6 0
zlib 1.2.8 3
py documentation package compiled into an executable file
windows compiled into exe
1. Using py2exe
Establish setup.py
from distutils.core import setup
import py2exe
setup(console=['app.py'])
carried out
python setup.py py2exe
2. Use pyinstaller
carried out
pyinstaller --distpath .dist_pyinstaller --workpath .build_pyinstaller -F app.py -n out.exe
Linux, compiled into an executable file
1.pyinstaller support compiler package under linux, windows and use under the same
pyinstaller --distpath ./dist_pyinstaller --workpath ./build_pyinstaller -F app.py -n out
Python dimensional code recognition library
apt-get install python-qrtools
Instructions:
python ordered dictionary
Establish the most simple web server with Python
python -m SimpleHTTPServer 8080
Establish the most simple web server with PHP
Example #1 启动Web服务器 服务于当前目录
$ php -S localhost:8000
Example #2 启动时指定根目录
$ php -S localhost:8000 -t malu/
Example #3 使用路由(Router)脚本
$ php -S localhost:8000 router.php
error
pip list display error exception:
[ root@0d4c1b027902:~ ]$ pip list
argparse (1.2.1)
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 80, in run
self.run_listing(options)
File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 142, in run_listing
self.output_package_listing(installed_packages)
File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 151, in output_package_listing
if dist_is_editable(dist):
File "/usr/lib/python2.7/dist-packages/pip/util.py", line 366, in dist_is_editable
req = FrozenRequirement.from_dist(dist, [])
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 286, in from_dist
assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
Storing debug log for failure in /root/.pip/pip.log
Solution:
Done!
Chinese garbled 3 recommendations
- All text string should be unicode type, rather than str, if you are in operation text, but it is the type str, that is, in the manufacturing bug.
- When you want to convert, explicit conversion. Decodes into text, with var.decode (encoding), from the text encoded into bytes, with var.encode (encoding).
- When reading data from the outside, it is the default byte, and then decode the text into the desired; the same, when it is desired to send a text to the outside, to encode byte retransmission.
Common Python package
1, pip freeze> requirements.txt the name and version of the current environment package exported to text
2, then in another environment installed pip install -r requirements.txt
Python3 common package installation:
apt-get install -y libcurl4-openssl-dev libsmbclient-dev python-pip python3-pip
pip3 install pysimplesoap
pip3 install -r requirements.txt
[ root@base:~ ]$ cat requirements.txt
altgraph==0.15
asn1crypto==0.24.0
beautifulsoup4==4.6.0
binwalk==2.1.0
bs4==0.0.1
cached-property==1.4.2
certifi==2018.1.18
chardet==2.3.0
configparser==3.5.0
crcelk==1.1
cryptography==2.1.4
cssselect==1.0.1
cycler==0.10.0
Cython==0.26.1
decorator==4.0.11
docker-pycreds==0.3.0
dockerpty==0.4.1
docopt==0.6.2
future==0.16.0
hashID==3.1.4
html5lib==0.999999999
httplib2==0.9.2
idna==2.6
inflect==0.2.5
jaraco.itertools==2.1
jsonschema==2.6.0
keyring==10.6.0
keyrings.alt==3.0
louis==1.3
lxml==4.1.1
macholib==1.9
matplotlib==2.0.0
more-itertools==4.0.1
numpy==1.12.1
olefile==0.45.1
pefile==2017.11.5
Pillow==4.0.0
pyasn1==0.1.9
pycrypto==2.6.1
pycurl==7.43.0
pygobject==3.26.1
PyInstaller==3.3.1
pymongo==3.1.1
PyOpenGL==3.1.0
pyparsing==2.1.10
pyqtgraph==0.10.0
pyquery==1.3.0
pyserial==3.2.1
PySimpleSOAP==1.16.2
pysmbc==1.0.15.6
python-dateutil==2.5.3
python-debian==0.1.30
python-debianbts==2.6.1
pytz==2016.7
pyxdg==0.25
PyYAML==3.12
requests==2.12.4
scipy==0.18.1
SecretStorage==2.3.1
selenium==3.7.0
six==1.10.0
smoke-zephyr==1.0.2
ssh-import-id==5.7
termineter==0.2.6
texttable==0.9.1
urllib3==1.19.1
webencodings==0.5
websocket-client==0.48.0
xmltodict==0.11.0