简体   繁体   English

可以从 pycharm 运行脚本,但不能从终端运行。 导入错误:DLL 加载失败:找不到指定的模块

[英]Can run script from pycharm, but not from Terminal. ImportError: DLL load failed: The specified module could not be found

import PIL.ImageGrab

im = PIL.ImageGrab.grab()
im.show()

Works in Pycharm, does not form command line.在 Pycharm 中工作,不形成命令行。 Tried many things, can be seen below, not sure what else to change.尝试了很多东西,可以在下面看到,不确定还有什么要改变的。

C:\Users\a.b>C:\Users\a.b\AppData\Local\Continuum\anaconda3\python.exe C:\Users\a.b\PycharmProjects\emlekezteto\screenshot.py

C:\Users\a.b>C:\Users\a.b\AppData\Local\Continuum\anaconda3\python.exe C:\Users\a.b\PycharmProjects\emlekezteto\screenshot.py
Traceback (most recent call last):
  File "C:\Users\a.b\PycharmProjects\emlekezteto\screenshot.py", line 1, in <module>
    import PIL.ImageGrab
  File "C:\Users\a.b\AppData\Local\Continuum\anaconda3\lib\site-packages\PIL\ImageGrab.py", line 20, in <module>
    from . import Image
  File "C:\Users\a.b\AppData\Local\Continuum\anaconda3\lib\site-packages\PIL\Image.py", line 90, in <module>
    from . import _imaging as core
ImportError: DLL load failed: The specified module could not be found.


    from . import _imaging as core
ImportError: DLL load failed: The specified module could not be found.

Things I checked:我检查的东西:

1. Pycharm interpreter is same. 1. Pycharm 解释器是一样的。 In Pycharm, and command line:在 Pycharm 和命令行中:

C:\Users\a.b\AppData\Local\Continuum\anaconda3\python.exe 

2. Even when working directory is the same, ie putting below thing in code, still same issue. 2.即使工作目录相同,即把下面的东西放在代码中,仍然是同样的问题。 By default this is working directory in Pycharm when running form there.默认情况下,这是在 Pycharm 中运行表单时的工作目录。

os.chdir(r'C:\Users\a.b\PycharmProjects\emlekezteto') 

3. The sys.path was different, for Pycharm: 3. sys.path 不同,对于 Pycharm:

['C:\\Users\\a.b\\PycharmProjects\\emlekezteto', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pydev', 'C:\\Users\\a.b\\PycharmProjects\\emlekezteto', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pycharm_display', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\third_party\\thriftpy', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pydev', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\python37.zip', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\DLLs', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3', 'C:\\Users\\a.b\\AppData\\Roaming\\Python\\Python37\\site-packages', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pycharm_matplotlib_backend', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\a.b\\PycharmProjects\\emlekezteto', 'C:/Users/a.b/PycharmProjects/emlekezteto']

in cmd:在 cmd 中:

['', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\python37.zip', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\DLLs', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3', 'C:\\Users\\a.b\\AppData\\Roaming\\Python\\Python37\\site-packages', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin']

Even when I extend sys.path with all the Pycharm sys.path hardcoded in code, it still gives the same error.即使我使用代码中硬编码的所有 Pycharm sys.path 扩展 sys.path ,它仍然会给出相同的错误。

 import os
    print (os.getcwd())
    os.chdir(r'C:\Users\a.b\PycharmProjects\emlekezteto')
    print (os.getcwd())

    import sys; print(sys.path)

sys.path.extend(['C:\\Users\\a.b\\PycharmProjects\\emlekezteto', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pydev', 'C:\\Users\\a.b\\PycharmProjects\\emlekezteto', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pycharm_display', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\third_party\\thriftpy', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pydev', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\python37.zip', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\DLLs', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3', 'C:\\Users\\a.b\\AppData\\Roaming\\Python\\Python37\\site-packages', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin', 'C:\\Program Files\\JetBrains\\PyCharm 2019.3\\plugins\\python\\helpers\\pycharm_matplotlib_backend', 'C:\\Users\\a.b\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\a.b\\PycharmProjects\\emlekezteto', 'C:/Users/a.b/PycharmProjects/emlekezteto'])

    print (sys.path)
    import PIL.ImageGrab
    im = PIL.ImageGrab.grab()
    im.show()

Check these out if you haven't seen them, they seem similar/relevant:如果您还没有看到它们,请查看它们,它们看起来相似/相关:

https://github.com/python-pillow/Pillow/issues/2945 https://github.com/python-pillow/Pillow/issues/2945

PIL: DLL load failed: specified procedure could not be found PIL:DLL 加载失败:找不到指定的过程

This problem really annoyed me for a while.这个问题真的让我恼火了一段时间。 I runned my script normally in Pycharm.我在 Pycharm 中正常运行我的脚本。 But it reported this error when I runned it in terminal.但是当我在终端中运行它时它报告了这个错误。 The 2 packages which I imported that caused this error are:我导入的导致此错误的 2 个包是:

from ortools.linear_solver import pywraplp 
from pyscipopt import Model, quicksum

I tried all solutions online, but none of them worked.我在网上尝试了所有解决方案,但没有一个奏效。 Finally I solved it by importing pandas before importing the above packages:最后我通过在导入上述包之前导入pandas来解决它:

import pandas as pd

Them I can run the script normally in terminal.他们我可以在终端中正常运行脚本。 This works for me.这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入错误:DLL 加载失败:找不到指定的模块 - PyCharm - ImportError: DLL load failed: The specified module could not be found - PyCharm ImportError:DLL加载失败:在PyCharm中找不到指定的模块 - ImportError: DLL load failed: The specified module could not be found in PyCharm Pycharm:ImportError:DLL 加载失败:找不到指定的模块 - Pycharm: ImportError: DLL load failed: The specified module could not be found ImportError:DLL加载失败:找不到指定的模块。 在pycharm中导入cv2时 - ImportError: DLL load failed: The specified module could not be found. when importing cv2 in pycharm 在pycharm ImportError中:DLL加载失败:找不到指定的模块。 导入人脸识别时 - In pycharm ImportError: DLL load failed: The specified module could not be found. while importing facerecognition ImportError: DLL 在导入 cv2 时加载失败:在 pycharm 中找不到指定的模块,python 3.9 - ImportError: DLL load failed while importing cv2: The specified module could not be found in pycharm with python 3.9 from torch._C import * ImportError: DLL load failed: 找不到指定的模块 - from torch._C import * ImportError: DLL load failed: The specified module could not be found ver.2 PyGreSQL ERROR: from _pg import * ImportError: DLL load failed: The specified module could not be found - ver.2 PyGreSQL ERROR: from _pg import * ImportError: DLL load failed: The specified module could not be found from scipy.linalg import _fblas: ImportError: DLL load failed: 找不到指定的模块 - from scipy.linalg import _fblas: ImportError: DLL load failed: The specified module could not be found 从.cv2导入* ImportError:DLL加载失败:找不到指定的模块 - from .cv2 import * ImportError: DLL load failed: The specified module could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM