非常简单的导入在Python中不起作用
main.py:second.py
import second
from second import *
print(second.a)
:
a = "testA"
b = "testB"
错误:
AttributeError: module 'second' has no attribute 'a'
导入在更复杂的程序上没有工作。试图简单地测试它,并且它不起作用。
在项目文件夹中,还有其他.py
文件以及__ pycache __
文件夹
执行↓也不起作用:
from second import a, b
main.py:
import second
from second import *
print(second.a)
second.py:
a = "testA"
b = "testB"
Error:
AttributeError: module 'second' has no attribute 'a'
Importing wasn't working on a more complex program. Tried to test it simply and it's not working.
Inside the project folder, there are the other .py
files as well as a __pycache__
folder
Doing ↓ doesn't work either:
from second import a, b
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码也对我有用。我认为这可能是您以前运行代码的.pyc文件引起的。
在软件包中删除.pyc文件,然后重新运行代码。
或者,您可以尝试在新环境中运行代码。
Your code works for me as well. I think it maybe caused by your .pyc file which you run your code before.
Delete .pyc file in your package and rerun your code.
Or you can try running your code in a new environment.
我弄清楚了!
答案很简单,是创建虚拟环境。
以下帮助我:
video
yglwku_1kr_1kr0ln35vly41rxgsssssuekssuekryomdlkv8
I figured it out!
The answer was quite simple, and it was to create a virtual environment.
The following helped me:
VIDEO
STACK
I appreciate all the help!