开发者

Refer to a Module within the Module in Python

开发者 https://www.devze.com 2023-02-09 17:32 出处:网络
I have a directory structure for a module like the following: - foo - __init__.py - gui.py I use the foo module from other places. Now I want to use something from the foo module in gui.py, but whe

I have a directory structure for a module like the following:

- foo
   - __init__.py
   - gui.py

I use the foo module from other places. Now I want to use something from the foo module in gui.py, but when I try to, I get this:

jsternberg@aquila:~$ python foo/gui.py 
Traceback (most recent call last):
  File "foo/gui.py", line 3, in <module>
    import foo
ImportError: No module named foo

How do I get the foo module from ins开发者_Python百科ide of it?


The directory containing foo/ isn't in sys.path when you invoke it that way.

python -m foo.gui
0

精彩评论

暂无评论...
验证码 换一张
取 消