( SOLVED ) Mayapy can't import maya.standalone

Hi guys, i’m trying to get Maya stand alone to work and from what I can tell after looking everywhere it should

I’ve got a simple python script that I run in command line

mayapy.exe “C:\Users\shadowst17\PycharmProjects\untitled\maya.py”

try:
import maya.standalone
maya.standalone.initialize()
except:
print ‘****’

But I get this error:

NameError: name ‘maya’ is not defined

Environment wise i’ve got one in PATH for maya bin folder

I printed the sys paths in the script it runs through mayapy and it seems correct?:

[‘C:\Users\shadowst17\PycharmProjects\untitled’,
‘C:\Program Files\Autodesk\Maya2016.5\bin\python27.zip’,
‘C:\Program Files\Autodesk\Maya2016.5\Python\DLLs’,
‘C:\Program Files\Autodesk\Maya2016.5\Python\lib’,
‘C:\Program Files\Autodesk\Maya2016.5\Python\lib\plat-win’,
‘C:\Program Files\Autodesk\Maya2016.5\Python\lib\lib-tk’,
‘C:\Program Files\Autodesk\Maya2016.5\bin’,
‘C:\Users\shadowst17\AppData\Roaming\Python\Python27\site-packages’,
‘C:\Program Files\Autodesk\Maya2016.5\Python’,
‘C:\Program Files\Autodesk\Maya2016.5\Python\lib\site-packages’]

is there any chance your pycharm project includes empty stubs for Maya? It’s at the top of your path…

Otherwise, what happens if you run this in an interactive session?

 > mayapye.exe
 >>> import sys
 >>> print sys.executable
1 Like

Interesting, moved the py file to a different folder and it worked! It didn’t occur to me that having a script run from pycharm project folder would cause these issues.

Thanks for your help!