简体   繁体   English

使用pyinstaller使其成为可执行文件后,无法在Python中移动文件

[英]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.

相关问题 PyInstaller将我的python脚本构建为可执行文件,但是不起作用 - PyInstaller built my python scripts to executable file, but it doesn't work 用PyInstaller创建的Python可执行文件无法运行 - Python executable created with PyInstaller doesn't run PyInstaller:单文件可执行文件不起作用 - PyInstaller: Single-file executable doesn't work 我正在使用 pyinstaller 使我的 python 文件可执行。 我在文件中使用 tkvideo。 我在同一目录中有mp4。 它不起作用 - I'm using pyinstaller to make my python file executable. I am using tkvideo inside the file. I have the mp4 in the same directory. It doesn't work Python代码有效,但是可执行文件(使用py2exe创建)却无法执行 - Python code works but executable (made using py2exe) doesn't pyinstaller可执行文件未在Ubuntu 18.04.1中运行 - pyinstaller executable doesn't run in Ubuntu 18.04.1 使用pyinstaller体验可执行文件“Fatal python error:initfsencoding” - Executable made with pyinstaller experiences “Fatal python error: initfsencoding” Python转换为.exe(通过Pyinstaller)不起作用 - Python converted to .exe (via Pyinstaller) doesn't work 用pyinstaller打包后python中的程序不起作用 - Program in python doesn't work after packaging with pyinstaller 使用 pyinstaller 将其转换为 exe 后,带有单例的 python 脚本不起作用 - python script with singleton doesn't work after converting it to exe with pyinstaller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM