IOError:[Errno 1]不允许操作错误

时间:2020-01-15 14:13:04

标签: python macos os.path

我正在MacOS 10.15.2上的python2中使用os.path,并且无法从我的工作目录中打开图像。这是代码:

'''
# JDoe_JSmith_1_4_3: Change pixels in an image.
'''
import matplotlib.pyplot as plt
import os.path
import numpy as np  # "as" lets us use standard abbreviations

#Read the image data
# Get the directory of this python script
directory = os.path.dirname(os.path.abspath(__file__)) 
# Build an absolute filename from directory + filename
filename = os.path.join(directory, 'woman.jpg')
# Read the image data into an array
img = plt.imread(filename)

###
# Change a region if condition is True
###

height = len(img)
width = len(img[0])
for r in range(155):
    for c in range(width):
        if sum(img[r][c])>500: # brightness R+G+B goes up to 3*255=765
            img[r][c]=[255,0,255] # R + B = magenta
       # if sum(img[r][c])

###
# Show the image data
###

#Show the image data
# Create figure with 1 subplot
fig, ax = plt.subplots(1, 1)
# Show the image data in a subplot
ax.imshow(img, interpolation='none')
# Show the figure on the screen



fig.show()

任何解决方法还是我做错了什么?任何帮助都非常感谢。

以下是错误的图片,如果可能会帮助您: image of error

我还应该提到,这在Windows 10上完美运行;我只在MacOS上遇到错误。

0 个答案:

没有答案