Python2.7在我的自定义库中有“找不到模块”的错误。虽然路径是正确的,目录是python包

时间:2018-02-16 20:14:40

标签: python pycharm

我正在使用pyChram来运行我的python。虽然我在Pycharm解释器上有一个正确的路径,但是我自己的模块显示错误“找不到模块”。

这个问题可能已经回答了几次而且显而易见但我无法找到正确的答案。 请参阅附有我的pyCharm设置的图片。我有主目录“python”作为root。

My pycharm setup

;with cte as
(select *
from accounts as e
cross apply (select newid()) as a(id)
)
select *, (select count(*)+1 from cte as c1 where c.id > c1.id) as rn
from cte as c
order by rn

错误:

python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/anaconda3/lib/python36.zip', '/anaconda3/lib/python3.6', '/anaconda3/lib/python3.6/lib-dynload', '/anaconda3/lib/python3.6/site-packages', '/anaconda3/lib/python3.6/site-packages/aeosa']

树;:目录“python”是根。 MacBook-HS-Pro:PycharmProjects $ tree

{code}
"$ python Test_run/Game_tic_tac_toe.py 
Traceback (most recent call last):
  File "Test_run/Game_tic_tac_toe.py", line 4, in <module>
    from functions.Tic_Tac_Toe import *
ImportError: No module named functions.Tic_Tac_Toe"[enter image description here][1]
{code}

1 个答案:

答案 0 :(得分:0)

从我发布的内容中我可以看到,您正在尝试使用Python / Test_Run / Game_tic_tac_toe.py中的python脚本来加载位于Python / functions的模块。您的sys.path中没有项目目录,因此导入submit无法找到功能模块。

您可能希望对模块使用相对导入或修复python路径。

您似乎试图在Game_tic_tac_toe.py脚本中更改python路径。我看到的问题是你使用了似乎是Windows路径来指定MacOSX上的目录。如果您使用的是Windows,请确保您具有正确的路径。如果您使用的是MacOSX,请从路径中删除<Button key="submit" type="submit">Create</Button> ,看看是否有效。