Python returning module error when running script, but its listed as installed when I look at modules list

huangapple go评论58阅读模式
英文:

Python returning module error when running script, but its listed as installed when I look at modules list

问题

我想从命令行调用一个脚本,但Python一直给我一个模块错误,说它找不到脚本中的某个模块。我用pip list查看了模块列表,发现它被列为已安装的模块。我不明白为什么会出现这个错误。我尝试使用python和python3命令调用脚本,以查看是否可能混淆了版本(在过去曾经这样做过,而且解决了问题),但仍然得到相同的结果。

C:\Users\me\Documents\website scritp\scripts>python3.10 image_viewer.py
Traceback (most recent call last):
  File "C:\Users\me\Documents\website scritp\scripts\image_viewer.py", line 8, in <module>
    from Pillow import Image
ModuleNotFoundError: No module named 'Pillow'

C:\Users\me>pip list
Package            Version
------------------ -----------
anyio              3.6.2
async-generator    1.10
attrs              22.1.0
beautifulsoup4     4.11.1
certifi            2022.12.7
cffi               1.15.1
charset-normalizer 3.0.1
colorama           0.4.6
decorator          4.0.11
exceptiongroup     1.0.4
h11                0.12.0
httpcore           0.15.0
httpx              0.23.0
idna               3.4
imageio            2.1.2
InstagramAPI       1.0.2
install            1.3.5
moviepy            0.2.3.2
numpy              1.24.2
oauthlib           3.2.2
outcome            1.2.0
Pillow             9.4.0  -HERE
pip                23.0.1
praw               7.6.1
prawcore           2.3.0
proxy-scraper      1.8
pycparser          2.21
pypandoc           1.10
PySimpleGUI        4.60.4
PySocks            1.7.1
pystyle            2.9
pywin32            305
requests           2.28.2
requests-oauthlib  1.3.1
requests-toolbelt  0.7.0
rfc3986            1.5.0
selenium           4.7.2
sklearn            0.0.post1
sniffio            1.3.0
sortedcontainers   2.4.0
soupsieve          2.3.2.post1
tqdm               4.11.2
trio               0.22.0
trio-websocket     0.9.2
tweepy             4.12.1
update-checker     0.18.0
urllib3            1.26.13
websocket-client   1.5.1
wsproto            1.2.0

C:\Users\me>pip3 list
Package            Version
------------------ -----------
anyio              3.6.2
async-generator    1.10
attrs              22.1.0
beautifulsoup4     4.11.1
certifi            2022.12.7
cffi               1.15.1
charset-normalizer 3.0.1
colorama           0.4.6
decorator          4.0.11
exceptiongroup     1.0.4
h11                0.12.0
httpcore           0.15.0
httpx              0.23.0
idna               3.4
imageio            2.1.2
InstagramAPI       1.0.2
install            1.3.5
moviepy            0.2.3.2
numpy              1.24.2
oauthlib           3.2.2
outcome            1.2.0
Pillow             9.4.0  -HERE
pip                23.0.1
praw               7.6.1
prawcore           2.3.0
proxy-scraper      1.8
pycparser          2.21
pypandoc           1.10
PySimpleGUI        4.60.4
PySocks            1.7.1
pystyle            2.9
pywin32            305
requests           2.28.2
requests-oauthlib  1.3.1
requests-toolbelt  0.7.0
rfc3986            1.5.0
selenium           4.7.2
sklearn            0.0.post1
sniffio            1.3.0
sortedcontainers   2.4.0
soupsieve          2.3.2.post1
tqdm               4.11.2
trio               0.22.0
trio-websocket     0.9.2
tweepy             4.12.1
update-checker     0.18.0
urllib3            1.26.13
websocket-client   1.5.1
wsproto            1.2.0

C:\Users\me\Documents\website scritp\scripts>python
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

为什么Python突然停止注册我安装的模块?它还给我同样的错误,当我安装任何其他新模块时(显示它们在列表中,但Python找不到它们)。这只是今天在我更新了Python之后才开始发生的,所以可能是因为这个原因?

英文:

I want to call a script from the command line, but python keeps giving me a module error saying it can't find a certain module in the script. I looked at the module list with pip -list, and i saw it listed as an installed module. I don't understand why it's giving me this error. I tried calling the script with both python & python3 commands to see if maybe it was just mixing up the versions(its done this in the past & that solved it), but it still gives me the same result

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

C:\Users\me\Documents\website scritp\scripts&gt;python3.10 image_viewer.py
Traceback (most recent call last):
File &quot;C:\Users\me\Documents\website scritp\scripts\image_viewer.py&quot;, line 8, in &lt;module&gt;
from Pillow import Image
ModuleNotFoundError: No module named &#39;Pillow&#39;
C:\Users\me&gt;pip list
Package            Version
------------------ -----------
anyio              3.6.2
async-generator    1.10
attrs              22.1.0
beautifulsoup4     4.11.1
certifi            2022.12.7
cffi               1.15.1
charset-normalizer 3.0.1
colorama           0.4.6
decorator          4.0.11
exceptiongroup     1.0.4
h11                0.12.0
httpcore           0.15.0
httpx              0.23.0
idna               3.4
imageio            2.1.2
InstagramAPI       1.0.2
install            1.3.5
moviepy            0.2.3.2
numpy              1.24.2
oauthlib           3.2.2
outcome            1.2.0
Pillow             9.4.0  -HERE
pip                23.0.1
praw               7.6.1
prawcore           2.3.0
proxy-scraper      1.8
pycparser          2.21
pypandoc           1.10
PySimpleGUI        4.60.4
PySocks            1.7.1
pystyle            2.9
pywin32            305
requests           2.28.2
requests-oauthlib  1.3.1
requests-toolbelt  0.7.0
rfc3986            1.5.0
selenium           4.7.2
sklearn            0.0.post1
sniffio            1.3.0
sortedcontainers   2.4.0
soupsieve          2.3.2.post1
tqdm               4.11.2
trio               0.22.0
trio-websocket     0.9.2
tweepy             4.12.1
update-checker     0.18.0
urllib3            1.26.13
websocket-client   1.5.1
wsproto            1.2.0
C:\Users\me&gt;pip3 list
Package            Version
------------------ -----------
anyio              3.6.2
async-generator    1.10
attrs              22.1.0
beautifulsoup4     4.11.1
certifi            2022.12.7
cffi               1.15.1
charset-normalizer 3.0.1
colorama           0.4.6
decorator          4.0.11
exceptiongroup     1.0.4
h11                0.12.0
httpcore           0.15.0
httpx              0.23.0
idna               3.4
imageio            2.1.2
InstagramAPI       1.0.2
install            1.3.5
moviepy            0.2.3.2
numpy              1.24.2
oauthlib           3.2.2
outcome            1.2.0
Pillow             9.4.0  -HERE
pip                23.0.1
praw               7.6.1
prawcore           2.3.0
proxy-scraper      1.8
pycparser          2.21
pypandoc           1.10
PySimpleGUI        4.60.4
PySocks            1.7.1
pystyle            2.9
pywin32            305
requests           2.28.2
requests-oauthlib  1.3.1
requests-toolbelt  0.7.0
rfc3986            1.5.0
selenium           4.7.2
sklearn            0.0.post1
sniffio            1.3.0
sortedcontainers   2.4.0
soupsieve          2.3.2.post1
tqdm               4.11.2
trio               0.22.0
trio-websocket     0.9.2
tweepy             4.12.1
update-checker     0.18.0
urllib3            1.26.13
websocket-client   1.5.1
wsproto            1.2.0

<!-- end snippet -->

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

also the output for my python version on command prompt
C:\Users\me\Documents\website scritp\scripts&gt;python
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt;

<!-- end snippet -->

why has python stopped registering modules I install all of a sudden? It's also giving me this same error with any other new modules I install(shows them listed, but python can't find them). This only started happening today after I updated my python btw, so maybe its because of that?

答案1

得分: 1

这叫做PIL而不是pillow:

from PIL import Image

阅读更多信息:https://pillow.readthedocs.io/en/stable/reference/Image.html

英文:

Its Called PIL not pillow:

from PIL import Image

read more at: https://pillow.readthedocs.io/en/stable/reference/Image.html

答案2

得分: -1

可能您正在使用来自不同安装的 pip。为了确保您使用相同的 pip 和 python,以模块方式运行 pip:

python3.10 -m pip list
英文:

It's possible you're using the pip from a different installation. To guarantee that you're using the same pip and python, run pip as a module:

python3.10 -m pip list

huangapple
  • 本文由 发表于 2023年2月24日 10:00:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75551990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定