逐語https://www.dazhuanlan.com/2019/08/25/5d623abdb609d/
閉じる* .pycファイルドキュメント生成
ときに、他の輸入書類PY、文書には、次のロードを加速するのpyc PY保存されます。
しかし、テストのディレクトリ構造に影響を与えないようにするために閉鎖することができます。
import sys
sys.dont_write_bytecode = True
インストールピップ
1. easy_installをインストールします。
wget https://bootstrap.pypa.io/ez_setup.py --no-check-certificate
python ez_setup.py --insecure
2.インストールピップダウンロード: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
インストールPIP(依存自動統合が推奨する方法)
apt-get install python-pip # Ubuntu
yum install python-pip # RedHat
国内源の使用ピップ
%のHOMEPATH%pippip.iniで〜/ .pip / pip.conf、ウィンドウ内のLinuxドキュメント
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com
複数のソース(代替):
[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
中国は現在は、PyPI鏡があります。
http://pypi.douban.com/simple/ 豆瓣
http://mirrors.aliyun.com/pypi/simple/ 阿里云
ピップのパラメータを説明しました
# 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> 证书.
アナコンダcondaの使用
minicondaのインストール(公式ダウンロードアドレスします。https://conda.io/miniconda.html):
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
bash Miniconda2-latest-Linux-x86_64.sh
インストールscipyのダウンロード(清華元指定):
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r scipy
国内ソースのcondaを変更します。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
直接インストール:
conda install numpy
conda install scikit-learn
ニューラルネットワークの依存関係:
conda install numpy
conda install pandas
conda install scipy
Viewインストールリスト:
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マニュアルパッケージは、実行可能ファイルにコンパイル
窓はexeファイルにコンパイル
1. py2exeを使用して
setup.pyを確立
from distutils.core import setup
import py2exe
setup(console=['app.py'])
実行
python setup.py py2exe
2. pyInstallerの
実行
pyinstaller --distpath .dist_pyinstaller --workpath .build_pyinstaller -F app.py -n out.exe
実行可能ファイルにコンパイルLinuxでは、
同じ下のLinux、Windows、および使用時の1.pyinstallerサポートコンパイラパッケージ
pyinstaller --distpath ./dist_pyinstaller --workpath ./build_pyinstaller -F app.py -n out
Pythonの二次元コード認識ライブラリ
apt-get install python-qrtools
どのように使用するには:
Pythonの辞書を注文しました
Pythonの最もシンプルなWebサーバーを確立
python -m SimpleHTTPServer 8080
PHPで最も簡単なWebサーバーを確立します
Example #1 启动Web服务器 服务于当前目录
$ php -S localhost:8000
Example #2 启动时指定根目录
$ php -S localhost:8000 -t malu/
Example #3 使用路由(Router)脚本
$ php -S localhost:8000 router.php
エラー
ピップ一覧表示エラー例外:
[ 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
ソリューション:
やりました!
中国の文字化け3つの勧告
- あなたが運転テキストである場合、すべてのテキスト文字列は、むしろSTRよりも、ユニコードタイプのものでなければならないが、それは製造業のバグでは、あるタイプのSTR、です。
- あなたは、明示的な変換を変換したいときに。var.encode(符号化)と、バイトに符号化されたテキストから、var.decode(符号化)して、テキストに復号します。
- 外部からデータを読み出す場合は、デフォルトのバイトであり、その後、所望にテキストをデコードする;同じ、バイトの再送信を符号化するために、外部にテキストを送信したい場合。
一般的なPythonパッケージ
1、ピップフリーズ>名前と現在の環境パッケージのバージョンrequirements.txtテキストにエクスポート
2、その後、別の環境にインストールピップで-r requirements.txtをインストール
python3共通パッケージのインストール:
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