python找不到文件错误,cmd中没有错误

ᴄʀᴏᴢᴇᴛ

我为Windows制作了一个python脚本,以在目录中打印每个文件。为此,我使用了ghostscript和gsprint。

当我启动脚本时,出现错误 WindowsError: [error2] file not found

如果我在cmd中启动相同的命令行,则不会出现错误,并且会打印pdf ...

这是我的脚本:

for f_name in files_in_dir:
    fullpath_file = os.path.join(base_print, path_print_source, f_name)
    carrier = f_name.split('-')[0]
    new_path = os.path.join(base_print, carrier + '_printed')
    new_fullpath_file = os.path.join(new_path, f_name)

    print Tools.format_txt("traitement du fichier %s" % f_name)
    print Tools.format_txt("traitement du fichier %s" % f_name, carrier)

    p = subprocess.Popen(['gsprint', '-printer', printer,'-dPDFFitPage', fullpath_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    if out:
        print Tools.format_txt(out)
    if err:
        print Tools.format_txt(err, level="error")

    print Tools.format_txt("fichier %s envoyé pour impression" % f_name, carrier)

    if not os.path.exists(new_path):
        os.makedirs(new_path)
    os.rename(fullpath_file, new_fullpath_file)

该文件的生成路径为: C:\Users\GREG\Downloads\DHL-575555338523255087006833669.pdf

追溯 :

Traceback (most recent call last):
  File "python-print.py", line 95, in <module>
    sys.exit(main())  # si le script est utilis├® comme un module, on n'ex├®cute pas le script
  File "python-print.py", line 61, in main
    p = subprocess.Popen(['gsprint', '-printer', printer,'-dPDFFitPage', fullpath_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\Python27\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] Le fichier spÚcifiÚ est introuvable

我正在将Windows 10与python 2.7一起使用

ᴄʀᴏᴢᴇᴛ

经过多次尝试,我设法解决了这个问题:

c:\program files安装了Gsprint,然后将其移动并安装在c:\GSP没有空格的路径中,并且效果很好。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

QPDF在python中找不到文件错误

使用python的Untar文件没有错误/警告?

尝试编译 protoc 文件时出错:找不到文件或有错误

列表中项目的Python索引没有错误?

在Python中尝试直到没有错误

不同的缩进在Python中没有错误

在Python中中断循环而没有错误-Selenium

我的Java程序没有在.csv文件中写入任何内容,即使没有“找不到文件”错误

为什么这个程序有错误'找不到符号'

从cmd编译Java程序时,出现“错误:找不到符号”,但是在Eclipse中却没有

时事通讯电子邮件-找不到我的代码有什么问题。在Dreamweaver中也没有错误

Filewriter 在 IDE 中工作,但在 cmd 中不工作,尽管没有错误

找不到记录错误:找不到没有ID的列表

没有错误时的标准错误文件

虽然没有错误,但我的 python pyw 文件没有打开

python脚本后没有打印,没有错误

Python/MySQL,没有错误但没有插入数据

导入错误:python 用于 3.7 但在 2.7 中没有错误

在 selenium python 中自动搜索过程没有错误但没有输出

错误:找不到符号/没有拼写错误?

Python:写入文件失败且没有错误-获取空文件

Python错误:找不到指定的文件

Python导入错误,找不到某些文件

需要powerhsell命令以检查文件存储中是否存在文件而没有错误

需要powerhsell命令以检查文件存储中是否存在文件而没有错误

没有错误吗?

Django中找不到静态文件错误

在C#中找不到文件错误

错误:在Firebase文件存储中找不到