【问题标题】:OSError: [Errno 22] Invalid Argument: '\u202aC:/Users/.../Documents/Python/fish.jpg' [closed]OSError:[Errno 22] 无效参数:'\u202aC:/Users/.../Documents/Python/fish.jpg' [关闭]
【发布时间】:2018-08-02 23:49:55
【问题描述】:
File = "C:\Python\lib\site-packages\PIL\Image.py", line 2580, in open
    fp = builtins.open(filename, "rb")

此代码在我家运行良好,但在我学生的计算机上出现标题错误而失败。 Windows 10. 新安装 Python 3.7,使用命令提示符通过 pip 新安装 Pillow,使用插件“脚本”新安装 Atom。以前有人见过这种情况吗? (下面的代码是一个简单的图像混合示例)。

(...代表用户名文件夹,每台电脑不同。)

from PIL import Image

def main():

    size = width, height = 1080, 720

    imageOne = Image.open("C:/Users/.../Documents/Python/fish.jpg")
    imageTwo = Image.open("C:/Users/.../Documents/Python/tropicalfish.jpg")

    imageOne.thumbnail(size)
    imageTwo.thumbnail(size)

    imageOne.convert("RGB")
    imageTwo.convert("RGB")

    imageBlend = Image.blend(imageOne, imageTwo, .5)

    imageBlend.show()

    del imageOne, imageTwo, imageBlend

if (__name__ == "__main__"):

    main()

【问题讨论】:

    标签: python image python-imaging-library show


    【解决方案1】:

    你的路径中有 \u202a 字符。尝试删除一些首字母并手动重写。并尝试使用r'C:/Users/ 这样的语法。

    关于u202a - https://www.fileformat.info/info/unicode/char/202a/index.htm

    【讨论】:

    • 如果您使用正斜杠作为目录分隔符,则不需要使用原始文字。
    猜你喜欢
    • 2021-02-10
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多