【发布时间】:2020-07-26 02:59:53
【问题描述】:
我正在努力导入一个包含许多我需要使用的引擎的文件夹。我从main_file.py 导入。
所以我想我可以使用-from engines import qr_code_gen,但我需要导入一个名为_QRCode_的类,所以我尝试使用-from .engines.qr_code_gen import _QRCode_,但它说“找不到模块引擎”。
结构:
Server/start.sh
Server/wsgi.py
Server/application/main_file.py
Server/application/engines/qr_code_gen.py
Server/application/engines/__init__.py
...
我在main_file.py 中使用了sys.path,我得到了 -
['C:\Users\Dzitc\Desktop\winteka2', 'C:\Users\Dzitc\AppData\Local\Programs\Python\Python37\Scripts\flask.exe', 'c:\users\dzitc\appdata\local\programs\python\python37\python37.zip', 'c:\users\dzitc\appdata\local\programs\python\python37\DLLs', 'c:\users\dzitc\appdata\local\programs\python\python37\lib', 'c:\users\dzitc\appdata\local\programs\python\python37', 'C:\Users\Dzitc\AppData\Roaming\Python\Python37\site-packages', 'c:\users\dzitc\appdata\local\programs\python\python37\lib\site-packages', 'c:\users\dzitc\appdata\local\programs\python\python37\lib\site-packages\win32', 'c:\users\dzitc\appdata\local\programs\python\python37\lib\site-packages\win32\lib', 'c:\users\dzitc\appdata\local\programs\python\python37\lib\site-packages\Pythonwin']
【问题讨论】:
-
您的
application目录中有__init__.py文件吗? -
@AzamatGalimzhanov 是的
-
winteka2你的应用在哪里? -
如果你只是
import engines,你会得到什么? -
lmao,我将名称 - 'engines' 更改为 - 'engine',将文件夹移动到
Server/application/api/并使用此导入 -from application.api.engine.qr_code_gen import _QRCode_,现在它可以工作了
标签: python