在 .py 文件中导入 openpyxl 时修复模块未找到错误? [英] fixing Module Not found Error when importing openpyxl in .py file?

查看:118
本文介绍了在 .py 文件中导入 openpyxl 时修复模块未找到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 openpyxl 与 python 3.7 一起使用,但是在我的 Windows shell 中启动我的 .py 文件时,我得到了 ModuleNotFoundError.

I am trying to use openpyxl with python 3.7, but when starting my .py file in my windows shell I got the ModuleNotFoundError.

这有点奇怪,因为如果我在 python 解释器中编写代码(可以创建和保存 .xlsx 文件),我不会收到此错误

It is kinda weird as i don't get this error if I write my code in the python interpreter (can create and save .xlsx files)

我尝试通过 pip3 和/或以管理员身份运行 shell(pip 已更新)再次卸载和安装.我不使用许多其他模块(os、wx、csv 和日历),所以它不应该干扰.我重命名了我的 .py 文件,所以我确定没有名称冲突.

I tried uninstalling and installing again via pip3 and/or running shell as admin (pip is updated). I don't use many other modules (os, wx, csv and calendar) so it shouldn't interfere. I renamed my .py file so i'm sure there is no name conflict.

import openpyxl
#from openpyxl import Workbook (doesn't work either)

你知道这可能来自哪里吗?

Do you have an idea where this may coming from ?

问候,

克莱姆

推荐答案

我想我找到了解决方案,因为我不再遇到错误.

I think I found a solution, as I don't get the error anymore.

我在 .py 文件的开头添加了编码和语言解释器

I added the encoding and language interpreter at the beginning of my .py file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from openpyxl import Workbook

希望有帮助:)

这篇关于在 .py 文件中导入 openpyxl 时修复模块未找到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆