python 与 pip安装使用

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 版本编译器构建工具cuDNNCUDA
tensorflow-2.1.02.7、3.5-3.7GCC 7.3.1Bazel 0.27.17.610.1
tensorflow-2.0.02.7、3.3-3.7GCC 7.3.1Bazel 0.26.17.410.0
tensorflow_gpu-1.14.02.7、3.3-3.7GCC 4.8Bazel 0.24.17.410.0
tensorflow_gpu-1.13.12.7、3.3-3.7GCC 4.8Bazel 0.19.27.410.0
tensorflow_gpu-1.12.02.7、3.3-3.6GCC 4.8Bazel 0.15.079
tensorflow_gpu-1.11.02.7、3.3-3.6GCC 4.8Bazel 0.15.079
tensorflow_gpu-1.10.02.7、3.3-3.6GCC 4.8Bazel 0.15.079
tensorflow_gpu-1.9.02.7、3.3-3.6GCC 4.8Bazel 0.11.079
tensorflow_gpu-1.8.02.7、3.3-3.6GCC 4.8Bazel 0.10.079
tensorflow_gpu-1.7.02.7、3.3-3.6GCC 4.8Bazel 0.9.079
tensorflow_gpu-1.6.02.7、3.3-3.6GCC 4.8Bazel 0.9.079
tensorflow_gpu-1.5.02.7、3.3-3.6GCC 4.8Bazel 0.8.079
tensorflow_gpu-1.4.02.7、3.3-3.6GCC 4.8Bazel 0.5.468
tensorflow_gpu-1.3.02.7、3.3-3.6GCC 4.8Bazel 0.4.568
tensorflow_gpu-1.2.02.7、3.3-3.6GCC 4.8Bazel 0.4.55.18
tensorflow_gpu-1.1.02.7、3.3-3.6GCC 4.8Bazel 0.4.25.18
tensorflow_gpu-1.0.02.7、3.3-3.6GCC 4.8Bazel 0.4.25.18

————————————————

tensorflownumpy
2.0.01.16.4
1.141.16.0
1.121.15.4
1.8.01.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)])

这是我个人写的笔记遇到问题我会进行补充,各位读者如果存在问题上面没有的,请联系我告诉我问题与解决方案,以便帮助更多人

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值