我是python新手,正在尝试开发解决方案。下面是我目前陷入困境的场景
我有两个文件都在同一个目录中
actualcode.py
userInformation.py
userInformation.py
有一些用户可以手动更改的数据。
actualcode.py
从userInformation.py
加载数据并对其进行处理并给出输出
执行将以这种方式进行,用户在userInformation.py
中输入数据并保存它,然后运行actualcode.py
并获得输出
我想为actualcode.py
创建一个可执行文件,我可以使用命令:pyinstaller --onefile actualcode.py
但是,在构建exe时,pyinstaller也会加载userInformation.py
文件并将其与可执行文件捆绑在一起,因此现在即使用户对userInformation.py
文件进行了更改,在运行actualcode.py
时也不会加载/反映这些更改,因为该文件已加载到exe中
我想知道有没有更好的办法
将数据加载到dotenv文件而不是userInformation.py
会解决我的问题吗
或者pyinstaller中是否有任何参数可以帮助我在actualcode.py上构建可执行文件并仍然从userInformation.py加载数据
还有没有一种方法可以用python构建一个参数化的exe?在这种情况下,我会用数据参数调用exe,而不是使用其他文件
如果不想使用JSON,就不必使用JSON。您只需更改userInformation.py脚本即可将所有信息保存在.txt文件中。并更改actualcode.py脚本以从.txt文件中获取信息。您必须创建两个.exe文件。一个用于操纵用户信息和实际文件,以执行某些操作
希望有帮助
例如,使用JSON,而不是使用python脚本本身作为数据存储的手段
这里有一些你可以玩的示范
文件输出:
读取结果:
要添加,如果您计划使用带有
onefile
标志的PyInstaller,则在执行时会得到一个打包的exe,该exe将解压缩到临时目录这使得工作目录变成临时目录。如果是这样的话,所有的相对路径都将被打断
这是问题的实际原因,即在
userInformation.py
上所做的更改没有反映出来-因为每次运行onefile exe时,都会在临时目录下解压其中的userInformation.py
如果要使用onefile选项,则需要如下更改工作目录:
通过这种方式,您的脚本将找到放置在exe文件中的文件,但不会找到总是在所谓的"import time"上导入的模块
相关问题 更多 >
编程相关推荐