ValueError:在Pycharm中尝试非包中的相对导入

时间:2016-12-14 01:47:21

标签: python python-2.7 pycharm

我做了git clone https://github.com/bow/crimson.git我在PyCharm中遇到了以下错误:

/Users/lorencm/.virtualenvs/crimson/bin/python /Users/lorencm/projects/crimson/crimson/cli.py
Traceback (most recent call last):
  File "/Users/lorencm/projects/crimson/crimson/cli.py", line 14, in <module>
    from . import __version__
ValueError: Attempted relative import in non-package 

我也尝试用python -m crimson.cli -h运行它,但我没有得到任何输出或错误。这是项目结构:

 pwd
/Users/lorencm/projects/crimson
(crimson)SEF-EEB-123137:crimson lorencm$ tree
.
├── HISTORY.rst
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.rst
├── crimson
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── cli.py
│   ├── fastqc.py
│   ├── fastqc.pyc

我错过了什么?

MIC

1 个答案:

答案 0 :(得分:0)

问题是导入 from . import __version__ 及其随后的相对导入,

为避免这种情况,可以将模块导入为

from crimson import __version__