简体   繁体   中英

how to run a python file in a package from Idle?

I have a folder (python package):

app/
   __init__.py
   bases.py
   store.py

in store.py I have a the the code

from .bases import BaseStore

class Store(BaseStore):
    # .. class 

Everything works when I run the full project.
How can I run the store.py file itself? Running the file with Idle gives an import error.
How can I run a script in idle which will be aware to its package?

I am pretty sure that this is not an IDLE issue but one of the interaction between relative imports, sys.path, the current working directory, and how you start python. To find out for sure, add the following at the top of store.py .

import os, sys
print(os.getcwd())
print(sys.path)

Then run your code the two different ways. Also add, at a command line

python /path/to/app/store.py

This list is the equivalent of how IDLE runs your code.

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