Kivy unable to find modules in .kivy/mods directory

50 views
Skip to first unread message

Thomas Chen

unread,
Jun 28, 2016, 11:26:32 PM6/28/16
to Kivy users support
Hi,

I'm working in OSX and python3 with kivy 1.9.1.

I'm also compiling my own cython modules and putting them in the .kivy/mods directory.

After pip installing several packages, kivy has lost the ability to import modules from the mods directory.

My mods directory is located inside the kivy.app at:
/Applications/Kivy.app/Contents/Resources/.kivy/mods

If I start kivy, then add the mods directory to my sys.path, it will be able to import my modules, but I would very much like to avoid manually modifying my sys.path.

Does anyone know why kivy would lose the ability to import from mods?

Thanks,
Thomas

Thomas Chen

unread,
Jun 28, 2016, 11:51:02 PM6/28/16
to Kivy users support
I've also tried putting plain python files in the directory along with an __init__.py and cannot import that either.
Example:
mods
├── mymodule.py
└── __init__.py
>>> import mymod

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ImportError: No module named 'mymodule'

Alexander Taylor

unread,
Jun 29, 2016, 6:16:06 AM6/29/16
to Kivy users support
It sounds like the .mods directory just isn't in your pythonpath, you can check sys.path to see for sure. I don't know how the OS X distribution is set up and something may be broken if this used to work, but you can just add the dir to the pythonpath to have it work.

Thomas Chen

unread,
Jul 1, 2016, 7:22:08 PM7/1/16
to Kivy users support
Thanks Alexander.

It appears that is what happened. If I do a fresh kivy download and look at the sys.path:
>>> import sys
>>> for p in sys.path:
...     print(p)
...  
/Users/Thomas/temp/Kivy3.app/Contents/Resources/kivy
/Users/Thomas/temp/Kivy3.app/Contents/Resources
/Users/Thomas/temp/Kivy3.app/Contents/Frameworks/python/3.5.0/lib/python35.zip
/Users/Thomas/temp/Kivy3.app/Contents/Frameworks/python/3.5.0/lib/python3.5
/Users/Thomas/temp/Kivy3.app/Contents/Frameworks/python/3.5.0/lib/python3.5/plat-darwin
/Users/Thomas/temp/Kivy3.app/Contents/Frameworks/python/3.5.0/lib/python3.5/lib-dynload
/Users/Thomas/temp/Kivy3.app/Contents/Frameworks/python/3.5.0/lib/python3.5/site-packages
/Users/Thomas/temp/Kivy3.app/Contents/Resources/kivy/kivy/modules
/Users/Thomas/temp/Kivy3.app/Contents/Resources/.kivy/mods
>>> quit()


However, in my working copy, I get this:


>>> import sys
>>> for p in sys.path:
...     print(p)
...
/Applications/Quantum.app/Contents/Frameworks/python/3.5.0/lib/python3.5/site-packages/mogwai-0.7.7-py3.5.egg
/Applications/Quantum.app/Contents/Resources/kivy
/Applications/Quantum.app/Contents/Resources
/Applications/Quantum.app/Contents/Frameworks/python/3.5.0/lib/python35.zip
/Applications/Quantum.app/Contents/Frameworks/python/3.5.0/lib/python3.5
/Applications/Quantum.app/Contents/Frameworks/python/3.5.0/lib/python3.5/plat-darwin
/Applications/Quantum.app/Contents/Frameworks/python/3.5.0/lib/python3.5/lib-dynload
/Applications/Quantum.app/Contents/Frameworks/python/3.5.0/lib/python3.5/site-packages
>>>


I did not modify my script file so I'm unsure how this would happen. Does anyone know how the sys.path gets assigned when you import kivy? I would rather fix this where it broke rather than modifying the script file to force it in.

Reply all
Reply to author
Forward
0 new messages