python - Python 可执行文件 - 创建目录和文件访问
问题描述
我创建了一个简单的 Python 脚本test.py,它应该检查目录是否存在,如果不存在,则创建它。
代码如下:
import os
def crete_dir(dir_name):
if not os.path.exists(dir_name):
os.makedirs(dir_name)
crete_dir("test_dir")
我在 Mac 上使用 PyCharm 编写和测试我的代码。
只要我在 PyCharm 中运行该脚本,它就会按预期工作,但是一旦我将它变成可执行文件(使用 pyinstaller:pyinstaller --onefile --clean --windowed test.py)并运行它,它就不起作用(不创建目录,即使它不存在)。与可执行文件一起打开的终端窗口不会返回任何文件访问权限或其他错误。
我应该怎么做才能使可执行文件正常工作?非常感谢。
解决方案
推荐阅读
- python - argparse:打开多个文件,如果一个文件不存在则忽略错误?
- android - 旧应用程序版本在 Play 商店中发布,而新的更新正在审查中
- pandas - 如何使此数据框更新更有效?
- reactjs - 在我的情况下,我应该如何使用 OAuth 2.0 授权授权(React 前端,Spring Boot 后端)
- apache-spark - Dataproc 笔记本无法导入或导出到 BigQuery:找不到类异常
- python - 由于没有互联网连接而未执行 django 查询时如何捕获异常
- swift - 如何在 SwiftUI WatchOS App 中更改列表的行背景颜色
- fabricjs - fabricjs 对象的所有可能类型是什么?
- angular - 将初始状态对象初始化为空对象而不是 undefined
- iis - 出站重写规则中的重写提供程序错误