简体   繁体   中英

How to run a file in pycharm?

I have a project that I imported into pycharm. It looks like this:

我在pycharm中的python项目的截图

The file grabber.py references class Fetcher within fetcher.py like this:

from grabber.fetcher import Fetcher

from the root folder Automaton I can run grabber.py from the command line with this command:

python -m grabber.grabber

But, I want to run grabber.py from pycharm. When I try I get this error:

Traceback (most recent call last):
  File "C:/Automaton/grabber/grabber.py", line 1, in <module>
    from grabber.fetcher import Fetcher
  File "C:\Automaton\grabber\grabber.py", line 1, in <module>
    from grabber.fetcher import Fetcher
ImportError: No module named 'grabber.fetcher'; 'grabber' is not a package

How do I get pycharm to run the file the same way I can from the command line?

My problem was pretty silly. I was having the problem because I had a package grabber and a file within it called grabber.py That name collision caused the problem. I renamed grabber.py and it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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