[英]Moving files in Python doesn't work once made executable using pyinstaller
I have a script in Python that works fine, it creates about 1000 files once the script is ran. 我有一个Python脚本,可以很好地运行,一旦脚本运行,它将创建约1000个文件。
So I implemented some code to move the files to a new folder once the script is ran. 因此,执行脚本后,我实现了一些代码将文件移动到新文件夹。
import glob, os, shutil
source_dir = 'C:/Users/george/Desktop/my aemo app/a'
dst = 'C:/Users/george/Desktop/my aemo app/b'
files = glob.iglob(os.path.join(source_dir, "*.csv"))
for file in files:
if os.path.isfile(file):
shutil.copy2(file, dst)
This works fine when I run it in idle, however once made executable and I send the program to someone else, it doesn't move the files for them? 当我在空闲状态下运行该程序时,它可以很好地工作,但是一旦将其设置为可执行文件并将其发送给其他人,它不会为他们移动文件吗?
I imagine the problem with sending to another user is that their username probably isn't "george" and therefore their file structure is different than what your program is looking for. 我认为发送给另一个用户的问题在于他们的用户名可能不是“ george”,因此他们的文件结构与您的程序所寻找的不同。 I would try using environment variables or relative pathways to move files around on a program that is to be distributed.
我会尝试使用环境变量或相对路径在要分发的程序上移动文件。 os documentation: https://docs.python.org/2/library/os.html#process-parameters
操作系统文档: https : //docs.python.org/2/library/os.html#process-parameters
relative pathways would be something like ../../file/deepFile/whatYoureLookingFor
if you want to go up 2 directories from where you run the program and then dive down another path into file
如果要从运行程序的位置上
../../file/deepFile/whatYoureLookingFor
两个目录,然后向下钻入file
相对路径,则相对路径应类似于../../file/deepFile/whatYoureLookingFor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.