0

I am using Eclipse and PyDev to develop for the Python library called Kivy.

I ran through the proper setup instructions, and developing and running from Eclipse works perfect.

However, when I, or more namley, my project-mates, try to run the file that contains the main method OUTSIDE of eclipse (via kivy cmd prompt), it comes up with the following error:

   File "C:\MyProject\code\main.py", line 8, in <module>
     from code import engine
 ImportError: cannot import name engine

The file code is basically:

from kivy.app import App
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager
from code import engine

class MyApp(App):
    def build(self):
        pass

if __name__ == '__main__':
    MyApp.run()

I took a look in my project files. I have a bunch of init.py files

code/
    __init__.py
    main.py
    engine.py
    system1/
        __init__.py
        my_system.py
etc...

but all the init.py files are empty! Am I supposed to construct them manually? Eclipse must be doing it at some point, can I have PyDev do it automatically?

4

1 回答 1

1

The empty __init__.py files are needed by Python (up to version 3.2) ideintify a directory as a Python package - and its contents as modules/sub-packages.

If you did not create them, PyDev created them for you - and they need not contain anything.

If your mates can't import code.engine asstated, it ismore likely the directory containing code itself is not part of Python's path (PYTHONPATH environment variable) - so it can't find from where do descend into the code package.

于 2013-03-08T19:57:09.193 回答