1. python配置
2. pip安装
3. pip设置使用国内源
# pip国内的一些镜像
http://mirrors.aliyun.com/pypi/simple/ #阿里云
https://pypi.mirrors.ustc.edu.cn/simple/ #中国科技大学
http://pypi.douban.com/simple/ #豆瓣(douban)
https://pypi.tuna.tsinghua.edu.cn/simple/ #清华大学
http://pypi.mirrors.ustc.edu.cn/simple/#中国科学技术大学
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx # 临时使用
nano ~/.pip/pip.conf # 永久设置源,创建文件并写入下面内容
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/ # 这里使用的是阿里云的镜像源
proxy=http://xxx.xxx.xxx.xxx:8080 # 替换出自己的代理地址
[install]
trusted-host=mirrors.aliyun.com # 信任阿里云的镜像源,否则会有警告
/
echo "[global]" > ~/.pip/pip.conf
echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> ~/.pip/pip.conf
Python创建虚拟环境
一、用命令创建虚拟环境
1. 安装虚拟环境的第三方包 virtualenv
pip install virtualenv
使用清华源安装:pip install virtualenv -i https://pypi.python.org/simple/
2. 创建虚拟环境
cd 到存放虚拟环境光的地址
virtualenv ENV 在当前目录下创建名为ENV的虚拟环境(如果第三方包virtualenv安装在python3下面,此时创建的虚拟环境就是基于python3的)
virtualenv -p /usr/local/bin/python2.7 ENV2 参数 -p 指定python版本创建虚拟环境
virtualenv --system-site-packages ENV 参数 --system-site-packages 指定创建虚拟环境时继承系统三方库
4. 激活/退出虚拟环境
cd ~/ENV 跳转到虚拟环境的文件夹
source bin/activate 激活虚拟环境
pip list 查看当前虚拟环境下所安装的第三方库
deactivate 退出虚拟环境
5. 删除虚拟环境
直接删除虚拟环境所在目录即可
python项目依赖并生成requirements.txt
pip freeze > requirements.txt # 配置虚拟环境使用即可
pip install pipreqs # 对项目目录的扫描使用了那些类库,自动生成依赖清单。
pipreqs ./ # 扫描./ 生成所有依赖清单requirements.txt,
pipreqs ./ --encoding=utf-8 # 若编码错误添加--encoding=utf-8
pipreqs ./ --encoding=utf-8 --force # 重复执行添加 --force
python可以模块包
Django python网站
PyInstaller生成可执行程序
pip install pyinstaller # out >>> Successfully installed pyinstaller-x.x.x
pyinstaller [选项] Python 源文件
-h,--help 查看该模块的帮助信息|
-F,-onefile 产生单个的可执行文件
-D,--onedir 产生一个目录(包含多个文件)作为可执行程序
-a,--ascii 不包含 Unicode 字符集支持
-d,--debug 产生 debug 版本的可执行文件
-w,--windowed,--noconsolc 指定程序运行时不显示命令行窗口(仅对 Windows 有效)
-c,--nowindowed,--console 指定使用命令行窗口运行程序(仅对 Windows 有效)
-o DIR,--out=DIR 指定 spec 文件的生成目录。如果没有指定,则默认使用当前目录来生成 spec 文件
-p DIR,--path=DIR 设置 Python 导入模块的路径(和设置 PYTHONPATH 环境变量的作用相似)。
也可使用路径分隔符(Windows 使用分号,Linux 使用冒号)来分隔多个路径
-n NAME,--name=NAME 指定项目(产生的 spec)名字。
如果省略该选项,那么第一个脚本的主文件名将作为 spec 的名字
远程调试python
# file: launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {"PYTHONPATH":"${workspaceRoot}"}
}
]
}
pip 常见问题
4. pip安装失败问题
## Python 3: ImportError “No Module named Setuptools”
#要setuptools在Debian上安装:
sudo apt-get install python-setuptools
#对于Python 3.x:
sudo apt-get install python3-setuptools
python 问题积累
tensorflow - 兼容性
版本 | Python 版本 | 编译器 | 构建工具 | cuDNN | CUDA |
---|---|---|---|---|---|
tensorflow-2.1.0 | 2.7、3.5-3.7 | GCC 7.3.1 | Bazel 0.27.1 | 7.6 | 10.1 |
tensorflow-2.0.0 | 2.7、3.3-3.7 | GCC 7.3.1 | Bazel 0.26.1 | 7.4 | 10.0 |
tensorflow_gpu-1.14.0 | 2.7、3.3-3.7 | GCC 4.8 | Bazel 0.24.1 | 7.4 | 10.0 |
tensorflow_gpu-1.13.1 | 2.7、3.3-3.7 | GCC 4.8 | Bazel 0.19.2 | 7.4 | 10.0 |
tensorflow_gpu-1.12.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.15.0 | 7 | 9 |
tensorflow_gpu-1.11.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.15.0 | 7 | 9 |
tensorflow_gpu-1.10.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.15.0 | 7 | 9 |
tensorflow_gpu-1.9.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.11.0 | 7 | 9 |
tensorflow_gpu-1.8.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.10.0 | 7 | 9 |
tensorflow_gpu-1.7.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.9.0 | 7 | 9 |
tensorflow_gpu-1.6.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.9.0 | 7 | 9 |
tensorflow_gpu-1.5.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.8.0 | 7 | 9 |
tensorflow_gpu-1.4.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.5.4 | 6 | 8 |
tensorflow_gpu-1.3.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.4.5 | 6 | 8 |
tensorflow_gpu-1.2.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.4.5 | 5.1 | 8 |
tensorflow_gpu-1.1.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.4.2 | 5.1 | 8 |
tensorflow_gpu-1.0.0 | 2.7、3.3-3.6 | GCC 4.8Bazel 0.4.2 | 5.1 | 8 |
————————————————
tensorflow | numpy |
---|---|
2.0.0 | 1.16.4 |
1.14 | 1.16.0 |
1.12 | 1.15.4 |
1.8.0 | 1.14.5 |
使用numpy 1.17.0+修复numpy警告
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
# tensorflow/python/framework/dtypes.py ## 516
# tensorflow_core/python/framework/dtypes.py ## 516
# , 1)]) 改为 )])
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
# _np_bfloat16 is defined by a module import.
# Custom struct dtype for directly-fed ResourceHandles of supported type(s).
np_resource = np.dtype([("resource", np.ubyte, 1)])
这是我个人写的笔记遇到问题我会进行补充,各位读者如果存在问题上面没有的,请联系我告诉我问题与解决方案,以便帮助更多人