MayaCharm Import error

I’ve recently switched to PyCharm and I’ve installed the MayaCharm plugin, which I’ve been having problems with.

It runs fine with any default Python or Maya module i import, as well as any code i write. But I keep getting an ImportError: No modules named … whenever i import my own files.

My root folder is marked as source
Add contents roots to PYTHONPATH is checked
Add source roots to PYTHONPATH is checked

I can import my modules directly in Maya’s script editor, and load them in the python console for PyCharm.

I’m running this through the custom run/debug configuration that you setup for MayaCharm. I’m using ‘execute file’ to run which imports all my other modules.

If anyone had any suggestion, i would really appreciate it!

I honestly know nothing about pycharm myself, but @passerby is MayaCharm’s author, so he might be able to offer some insight.

So MayaCharm its self is having lots of problems with PyCharm 2019.3 which i have not been able to sort out yet.

but otherwise as long as what ever you are doing is in a place where Maya considers it part of its scripts path it should be fine. i tend to setup Maya modules that point to the paths where i am doing development for my Maya Scripts.

I’m currently using PyCharm 2019.2.5 Community Edition with Maya 2019.

I’m not sure what’s causing the problem, whats annoying is that it was working last week.

Hopefully i can find a solution, ill update the thread if i do. In case anyone else has the same problem

ok, so it’s now working.
The problem seemed to be with my import statements. I have a basic structure:


I’m relatively new to python as I’ve started using it at work. But i realised it was because of the difference between absolute and relative imports, and when MayaCharm runs my script python changes the name to main

So i have to write this in
from parent import coreB

instead of:
import coreB

This explains why i could run it directly in Maya and in the Python Console.

Although, explicit relative imports doesn’t work:
from . import coreB

Relative imports only work inside modules that are part of the same root package.
So in coreA you should be able to use from . import coreB if you are importing parent as a package, if however you’re attempting to run on its own, or if you’ve added parent to sys.path you’ll run into issues.