Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 没有名为';基数';即使base.py存在_Python - Fatal编程技术网

Python 没有名为';基数';即使base.py存在

Python 没有名为';基数';即使base.py存在,python,Python,假设某个目录(您可以下载文件)。从我当前的目录中,我有一个名为checkerbot的目录,其中包含4个文件,即base.py,checkers.py,\uuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuupy和model.py In [1]: import checkerbot.checkers as ck -------------------------------

假设某个目录(您可以下载文件)。从我当前的目录中,我有一个名为
checkerbot
的目录,其中包含4个文件,即
base.py
checkers.py
\uuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuupy
model.py

In [1]: import checkerbot.checkers as ck                                        
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-d7411e2bfdb5> in <module>
----> 1 import checkerbot.checkers as ck

~/../main/checkerbot/checkers.py in <module>
----> 1 import base
      2 
      3 class Game:
      4         # Initializes the class.
      5         def __init__(self):

ModuleNotFoundError: No module named 'base'
假设我的当前目录是
main
,而
checkerbot
位于
main/
中。如果我运行
ipython
,然后从运行
。导入基数
然后我得到:

In [1]: from . import base                                                      
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-a8bda1f23f19> in <module>
----> 1 from . import base

ImportError: attempted relative import with no known parent package
[1]中的
:来自。进口基地
---------------------------------------------------------------------------
ImportError回溯(最近一次呼叫最后一次)
在里面
---->1来自。进口基地
ImportError:尝试在没有已知父包的情况下进行相对导入
另一个错误:

In [5]: from checkerbot import base                                             
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-3203dc774184> in <module>
----> 1 from checkerbot import base

~/../main/checkerbot/base.py in <module>
      1 import tensorflow as tf
      2 import numpy as np
----> 3 from model import model
      4 
      5 agent = tf.keras.models.Sequential()

ModuleNotFoundError: No module named 'model'
[5]中的
:来自checkerbot导入库
---------------------------------------------------------------------------
ModuleNotFoundError回溯(上次最近调用)
在里面
---->1来自checkerbot导入库
~/../main/checkerbot/base.py输入
1导入tensorflow作为tf
2作为np导入numpy
---->3从模型导入模型
4.
5 agent=tf.keras.models.Sequential()
ModuleNotFoundError:没有名为“model”的模块
改用这个

from . import base
编辑

考虑以下示例:

└── foo
    ├── __init__.py
    ├── module_bar.py
    └── module_foo.py

$ cat foo/module_bar.py 
from . import module_foo

print(module_foo.load())

$ cat foo/module_foo.py 
def load():
    print("module foo is loaded")

$ python
Python 3.8.2 (default, May  4 2020, 20:05:11) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo.module_bar
module foo is loaded
这意味着,无论何时从目录导入模块,目录中的导入都应以

开头,而应使用此选项

from . import base
编辑

考虑以下示例:

└── foo
    ├── __init__.py
    ├── module_bar.py
    └── module_foo.py

$ cat foo/module_bar.py 
from . import module_foo

print(module_foo.load())

$ cat foo/module_foo.py 
def load():
    print("module foo is loaded")

$ python
Python 3.8.2 (default, May  4 2020, 20:05:11) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo.module_bar
module foo is loaded

这意味着,无论何时从目录导入模块,目录中的导入都应以

开始。是否从checkbot目录运行脚本?如果您正在从父目录运行脚本,只需从中尝试
。从checkerbot导入库导入库


当前,python可能在父目录中搜索
base.py

是否从checkbot目录运行脚本?如果您正在从父目录运行脚本,只需从中尝试
。从checkerbot导入库导入库

目前python可能在父目录中搜索
base.py

使用

from . import base
这将在
checkerbot
包中提供
base
模块的相对导入

模型
模块也有类似的情况:

from .model import model
使用

这将在
checkerbot
包中提供
base
模块的相对导入

模型
模块也有类似的情况:

from .model import model

只需写下其中包含的文件夹的名称

例:

从pymouse.base导入PyMouseMeta、PyMouseEventMeta


只需写下其中包含的文件夹的名称

例:

从pymouse.base导入PyMouseMeta、PyMouseEventMeta



尝试
import.base
?你需要在python3+@greenmaffegy中添加
,我会更新我的问题。尝试
import.base
?你需要在python3+@greenmaffegy中添加
,我会更新我的问题。看看这个问题你的尝试没有回答我的问题我不知道我在哪里搞砸了,但在我的头脑中,这都是同一个问题。它不在checkerbot/中。它在main/中。main/包含checkerbot/。为什么你认为我把checkerbot.checkers作为ck导入了呢?你准备好修改你的答案了吗?看看这个问题你的尝试没有回答我的问题我不知道我哪里搞砸了,但在我的脑海里,这是一个问题。它不在checkerbot/中。它在main/中。main/包含checkerbot/。为什么你认为我把checkerbot.checkers作为ck导入了呢?你能修改你的答案吗?你可以下载我的模块。试试看。它似乎对我不起作用。你可以下载我的模块。试试看。这似乎对我不起作用