简体   繁体   English

Python,无法从另一个文件夹导入文件

[英]Python, can't import file from another folder

Structure:结构:

folder "a":
     __init__.py
     car.py
folder "b":
     tad.py

And I do in tad.py:我在 tad.py 中做:

from a.car import *


ModuleNotFoundError: No module named 'a'

What can I do??我能做什么?? EDIT: I added init to the top level folder, and now throws this error:编辑:我将 init 添加到顶级文件夹,现在抛出此错误:

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x000031bc (most recent call first):
<no Python frame>

You should try你应该试试

from .a.car import *

The leading dot goes one directory up in folder hierarchy.前导点在文件夹层次结构中向上移动一个目录。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM