Python的包搜索路径 - python 命令行执行exe

Python的包搜索路径
Python会在以下路径中搜索它想要寻找的模块:
1. 程序所在的文件夹
2. 标准库的安装路径
3. 操作系统环境变量PYTHONPATH所包含的路径

将自定义库的路径添加到Python的库路径中去,有如下两种方法:
1. 动态的添加库路径。在程序运行过程中修改sys.path的值,添加自己的库路径
import sys
sys.path.append(r'your_path') 
2. 在Python安装目录下的\Lib\site-packages文件夹中建立一个.pth文件,内容为自己写的库路径。示例如下
E:\\work\\Python\\http

python命令行执行exe

cmd = "start D:\software\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222 --user-data-dir='D:\selenium\ChromeProfile'"
os.system(cmd)

《Python 使用pyinstaller打包文件报错Fatal error in launcher: Unable to create process using 原因及解决方案》错误处理:

下载开发版pyinstaller

可以在cmd中使用命令

pip instal https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
也可以到github上
下载地址
https://github.com/pyinstaller/pyinstaller
下载 后解压得到pyinstaller文件并拷到python根目录下

然后进入pyinstaller目录下运行cmd 输入命令python setup.py build和python setup.py install

安装完成后可用pyinstaller -v查看版本信息

sqlite_web "D:\Python_prj\all.db" -r

WHERE board like "%K6UXCM%" AND alarm like "HARD_BAD" AND para like "%f%3%"

import sys
sys.path.append(r"D:\OneBox\PythonPrj\pythonProject1\utility")

import sys
from os import path
# 这里相当于把相对路径 .. 添加到pythonpath中
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值