[英]import a file from different folder in python
I am trying to import a .py
from a different folder in my project but got the Module not found error
.我正在尝试从我的项目中的不同文件夹导入
.py
,但得到Module not found error
。 Please help.请帮忙。
this is my project tree.这是我的项目树。
PROJECT_name
+trnsvr
|
\--trn_db.py
+websvr
|
\--instance
|
--config.py
\--app
|
--__init__.py
in trn_db.py
I did import websvr.instance.config as conf
在
trn_db.py
我确实import websvr.instance.config as conf
but got the ModuleNotFoundError
as follow.但得到
ModuleNotFoundError
如下。
ModuleNotFoundError: No module named 'websvr'
how do I resolve this?我该如何解决这个问题? thank you
谢谢你
Try to specify the file path... c:/MicrosoftVSCode/randomthings1.py
.尝试指定文件路径...
c:/MicrosoftVSCode/randomthings1.py
。 When not right next to it (in the same folder), python has sometimes problems accessing a file.如果不在它旁边(在同一个文件夹中),python 有时会在访问文件时出现问题。 Also, make sure antimalware software isn't blocking python's access.
此外,请确保反恶意软件不会阻止 python 的访问。 <- That actually happened to me.
<-这实际上发生在我身上。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.