简体   繁体   English

python3导入找不到模块

[英]python3 import not finding module

I'm trying to test out an example from a book and I'm getting an ImportError . 我正在尝试从书中测试一个示例,并且遇到了ImportError

The example starts out like: 该示例开始如下:

from tkinter import *
from PP4E.Gui.Tools.widgets import frame, button, entry

And if I put an import sys; print(sys.path) 如果我import sys; print(sys.path)一个import sys; print(sys.path) import sys; print(sys.path) at the beginning of the code, the output is 在代码开头import sys; print(sys.path) ,输出为

['/Users/aaa/Documents/workspace/programming-python/PP4E/Lang/Calculator', 
 '/usr/local/lib/python3.4/site-packages/setuptools-12.2-py3.4.egg',
 '/usr/local/lib/python3.4/site-packages/pip-6.0.8-py3.4.egg',
 '/User/aaa/Documents/workspace/programming-python',... ]

This is what a truncated version of my programming-python directory looks like: 这是我的programming-python目录的截断版本:

❯ tree
.
├── PP4E
│   ├── __init__.py
│   ├── Gui
│   │   ├── Tools
│   │   │   ├── __init__.py
│   │   │   └── widgets.py
│   │   └── __init__.py
│   ├── Lang
│   │   └── Calculator
│   │       ├── __init__.py
│   │       └── calc0.py
└── site-packages
    └── PP4E.pth

The error message I'm getting is: 我收到的错误消息是:

❯ python3 calc0.py                                                            

Traceback (most recent call last):
  File "calc0.py", line 2, in <module>
    from PP4E.Gui.Tools.widgets import frame, button, entry
ImportError: No module named 'PP4E'

Does anybody know what I have to do to get Python to find the PP4E module? 有人知道我需要做什么才能让Python查找PP4E模块吗? Thanks. 谢谢。

I had my PYTHONPATH wrong -- the root directory is /Users , not /User . 我的PYTHONPATH错误–根目录是/Users而不是/User Thanks. 谢谢。

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

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