Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Loading Python script - Not without problems!

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
FalconCrest
18528 Views, 9 Replies

Loading Python script - Not without problems!

I've received some wonderful help from some on this forum but none have been able to understand as to why I keep running into this on going problem when my environment variables are setup correctly. 

 

The previous problem I had was with a MEL script, up to this point, and I hope for good, has been resolved, as that problem had fixed its self. 

 

The new problem is with Python scripts and my environment variable, including Maya native script path unable to load the scripts at start up without the following error;

 

# Error: ImportError: file <maya console> line 1: No module named [scriptname] #

 

As I mentioned, many have helped diagnose my previous problem; the result was everything is setup correctly on my system.  With that being the case, why this problem, there shouldn't be a difference if it's a MEL script or a Python script loading from the environment variable ?

 

 

9 REPLIES 9
Message 2 of 10
santd
in reply to: FalconCrest

Hello,

 

Thank you for posting to The Area Forums.

 

I believe I remember seeing your previous post, but it has been sometime so don't really remember all of the information from that. Would you mind posting a link to your previous post or provide more information in regards to the environment variables you have set and where your are saving your Python scripts. Have you tested a simple python script to see if that loads?

 

I look forward to hearing back.

 

Cheers,




David Santos

Message 3 of 10
FalconCrest
in reply to: santd

Hi, this is the link to the previous post thread that relates to this post, which you also helped me with. I want to hopefully solve these scripting issues once and forall, but some odd reason, they keep occuring, yet there is no problems with my setup as was known in my last issue from my previous post. 

 

From my point of view I hope the loading MEL issue with regards to my environment variable is solved, fingers crossed, and it doesn't arise again Smiley Happy My new problem relates to Python Scripts, and getting them to load and run successfully.

 

This is the error I am recieving in Maya when I attempt to run a Python script that is placed within a folder, that must remain in the folder, which I hope shouldn't be a concern if it's placed in a folder or not ?

# Error: ImportError: file <maya console> line 1: No module named <folder name> #

 

This is the path that my environment variable should see all python scripts.
C:\Custom Program Settings\Maya_Resources\pythonscripts\


The folder with the python script(s) is also placed in Maya default scripts path, this was to test if there was something wrong with my environment variable as like my previous post read, although it didn't make a difference as the script folder / scripts didn't load from Maya default script folder anyhow.
C:\Users\<username>\Documents\maya\2015-x64\prefs\scripts\<script folder>\

 

This is the path set in my Maya.env environment variable file for all python scripts.
PYTHONPATH = C:\Custom Program Settings\Maya_Resources\pythonscripts\

 

It's all pretty straight forward and clear Smiley Happy, why it's giving me this grief I don't understand ! From what I recall, I haven't tested any python script to see if it loads, as in my last situation, the MEL script test worked but not the actual MEL script, that was before it worked, if it should so happen I do a python test script and it does work but the actual script loading and running doesn't work. 

 

 

Message 4 of 10
santd
in reply to: FalconCrest

 Hello,

 

Thanks for sending more details on the setup you currently have.

 

Do you have a PYTHONPATH variable set in your system environment variables? If you do, this will take presedence over the maya.env file.

 

I am not extremely familiar with running python files in Maya, but from the research I have done and from speaking with some of my colleagues it seems that it is necessary to "source" the python script by running the following inside of Maya:

 

import nameOfScript

 

Once you do that you should be able to then call your script. For instance with the attached script. Place it in your scripts folder then run the following in the Script Editor in a python tab:

 

import testScript

testScript.testScript()

 

The script will print "This Script is Working". So in your case it seems that you first need to import your script.

 

I hope that information is helpful.

 

Cheers,




David Santos

Message 5 of 10
FalconCrest
in reply to: santd

I have a Python Path in my system environment variable, although it's pointing at the Python Modules sub-folder, I hope that doesn't matter ?

 

I put the testScript.py file in the path which I have in the Maya environment file, unfortunately I got this error when running

 

"import testScript.py"

"testscript.testscript()"

 

# Error: line 1: invalid syntax #
import testScript.py
testscript.testscript()

# Error: line 1: ImportError: file <maya console> line 1: No module named testScript.py #

 

With regards to the script, not your test script, the other script.  I get a syntax error when run as such;

"import <scriptname>"

"import <absolute file path\<scriptname>"

Message 6 of 10
santd
in reply to: FalconCrest

The syntax error is definitely strange. I noticed that you are running "testscript.testscript()" as opposed to "testScript.testScript()" with the capital "S" in script, I just wanted to verify that you were running that correctly as it will produce an error if it is not capitalized.

 

The PYTHONPATH set in your system variables could possibly be causing an issue. Just to be on the safe side I would recommend adding your custom directory to that variable as well. Take whatever value is already there and at the end of it if add a semi colon ";" followed by your path for example:

 

pre\existing\python\path;your\custom\python\path

 

Also if the issue continues, try putting the script I sent you, in the following directory:

 

C:\Users\USERNAME\documents\maya\VERSION\scripts

 

To see if Maya picks it up from there and that it actually works.

 

Let me know what results.

 

Cheers,




David Santos

Message 7 of 10
FalconCrest
in reply to: santd

It works, the script that wasn't working works. As you suggested adding my custom folder to the environment variable worked. As you mentioned the environment variable has priority over the maya environment file, it was consistency being ignored.

Thank You so much !
Message 8 of 10

Mine’s not working! If you could show a tutorial on this it would be so helpful.

Message 9 of 10

What is not working for you ?

Message 10 of 10

Hello, Plant 3D user here doing python scripting.  I have been making pipe and fittings using python scripting but am having trouble getting a "support/pipe hanger" script to register.  I have basically taken a copy of a previous script that works great,  (pipe flange), changed the name of the .PY file, changed the name of the component within the script, and when I run the "plantregistercustomscripts" command, I get an error stating "No module named Support.  If you are wanting to create new pipe support, like a clamp, what would you need to do different to the script to make it come through to Spec Editor?  Thanks in advance.

 

Please see attached screen shots showing my script as well as the error when trying to register my custom script.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report