【发布时间】:2021-05-20 21:12:35
【问题描述】:
这是我的第一个问题(我正在尝试学习 Python 作为编程的起点)
我正在上第二节 Python 基础课,但作业有问题。
我在“图像处理”一章中,我正在尝试运行以下命令: #我有一个运行 Big Sur 11.3.1 的 MAC
import image
p = image.Pixel(45, 76, 200)
print(p.getRed())
p.setRed(66)
print(p.getRed())
p.setBlue(p.getGreen())
print(p.getGreen(), p.getBlue())
我必须安装“image”和“PIL”(一开始我无法导入它们)
我运行以下(安装它们)
python3 -m pip install image
python3 -m pip install PIL
我尝试导入图像模块(之后)
我试过了:
import image
还有:
from PIL import Image
但是当我尝试以下操作时,我不断收到错误消息:
bash-3.2$ python3
Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec 7 2020, 12:10:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import image
>>> p = image.Pixel(45, 76, 200)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'image' has no attribute 'Pixel'
>>>
或者,
bash-3.2$ python3
Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec 7 2020, 12:10:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> p = image.Pixel(45, 76, 200)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'image' is not defined
>>>
我不确定我是否没有正确安装/上传模块
我一直在尝试在线查找此内容,但运气不佳。
任何帮助/协助将不胜感激。
【问题讨论】:
标签: python-3.x import