2

I did git clone https://github.com/bow/crimson.git and I got the below error in 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 

I also tried to run it with python -m crimson.cli -h, but I did not get any output or error. This is the project structure:

 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

What did I miss?

Mic

user977828
  • 7,259
  • 16
  • 66
  • 117
  • It's a quirk of PyCharm that I don't know a work around for. (I'd love to know if someone else has one). Somewhere in the project structure there's a relative import . Something like `from .foo import bar`. But doing relative imports requires you to run as module, which is what the `-m` flag is doing. PyCharm runs scripts, so the relative imports won't work. Read the ridiculously good answer [here](http://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time). – Batman Dec 14 '16 at 02:15
  • I also tried to run it with `python -m crimson.cli -h`, but I did not get any output or error. – user977828 Dec 14 '16 at 02:25
  • Right. Because you used the `-m` flag. If you try without the flag you'll see it. – Batman Dec 14 '16 at 02:26
  • Without `-m` I got `python: can't open file 'crimson.cli': [Errno 2] No such file or directory` – user977828 Dec 14 '16 at 04:06

1 Answers1

0

The issue is the import from . import __version__ and the relative imports that follows,

To avoid this, the module could be imported as

from crimson import __version__
All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111