Hi,
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 main.py which imports all my other modules.
If anyone had any suggestion, i would really appreciate it!
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 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 coreA.py: 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 coreA.py on its own, or if you’ve added parent to sys.path you’ll run into issues.