<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sourcing Python in Maya Error in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171112#M16137</link>
    <description>Hello,&lt;BR /&gt;&lt;BR /&gt;Thanks again for the reply. I am not using a non-US computer or language pack. No apostrophe in my folder names or login ID either. Hmm....&lt;BR /&gt;&lt;BR /&gt;This is the result of typing the above command:&lt;BR /&gt;import sys&lt;BR /&gt;sys.path.prepend("/Users/borders/Library/Preferences/Autodesk/maya/scripts")&lt;BR /&gt;# Error: 'list' object has no attribute 'prepend'&lt;BR /&gt;# Traceback (most recent call last):&lt;BR /&gt;#   File "&amp;lt;maya console&amp;gt;", line 2, in &amp;lt;module&amp;gt;&lt;BR /&gt;# AttributeError: 'list' object has no attribute 'prepend' # &lt;BR /&gt;&lt;BR /&gt;Any ideas?  &lt;BR /&gt;&lt;BR /&gt;Yes, I did find the pythonScripts script which lives in /Applications/Autodesk/maya2009/devkit/devkit/other/PyQtScripts and yes you are correct I have seen it. My userSetup.py is in this directory and "import maya.cmds as cmds" is on the top line yet when I open maya and type cmds.sphere() I get an error which says "# Error: name 'cmds' is not defined&lt;BR /&gt;# Traceback (most recent call last):&lt;BR /&gt;#   File "&amp;lt;maya console&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;# NameError: name 'cmds' is not defined # " &lt;BR /&gt;&lt;BR /&gt;This should work but I don't understand why my userSetup.py is not being read in correctly.&lt;BR /&gt;&lt;BR /&gt;However, if I type in the script editor &lt;BR /&gt;import maya.cmds as cmds&lt;BR /&gt;cmds.sphere()&lt;BR /&gt;there is no problem and that works fine. It would be nice to know that my userSetup.py was working properly and that I could add more commands to this file.  Thoughts?&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
    <pubDate>Mon, 25 Oct 2010 13:52:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-10-25T13:52:12Z</dc:date>
    <item>
      <title>Sourcing Python in Maya Error</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171107#M16132</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I am a new Maya user (running on OSX 10.5.8) and am learning about the capabilities of using Python in Maya. I do have Python experience. I am able to enter Python commands in the script editor under the Python tab however, I am unable to actually source a Python script.&lt;BR /&gt;&lt;BR /&gt;For example, I created a simple Hello World script called helloworld1.py. The script looks like this:&lt;BR /&gt;# helloworld1.py: The very first Hello World Python script for Maya&lt;BR /&gt;&lt;BR /&gt;print "Hello World!"&lt;BR /&gt;&lt;BR /&gt;When I go to File --&amp;amp;gt; Source Script, then I select the Python script I get this error:&lt;BR /&gt;// Error: # helloworld1.py: The very first Hello World Python script for Maya // &lt;BR /&gt;// Error: invalid directive // &lt;BR /&gt;&lt;BR /&gt;I am also unable to type pySource helloworld1.py:&lt;BR /&gt;pySource helloworld1.py&lt;BR /&gt;# Error: ('invalid syntax', ('&amp;lt;maya console&amp;gt;', 2, 20, 'pySource helloworld1.py\n'))&lt;BR /&gt;#   File "&amp;lt;maya console&amp;gt;", line 1&lt;BR /&gt;#      pySource helloworld1.py&lt;BR /&gt;#                         ^&lt;BR /&gt;#  SyntaxError: invalid syntax #  &lt;BR /&gt;&lt;BR /&gt;How do I get this to compile correctly? Also, I am unsure of where to place my userSetup.py file. Currently I have placed it in: &lt;BR /&gt;/Users/borders/Library/Preferences/Autodesk/maya/2009/scripts  however, there seems to be some sort of linking problem (I've also tried using this directory /Applications/Autodesk/maya2009/devkit/devkit/other/PyQtScripts/qt)&lt;BR /&gt;&lt;BR /&gt;My userSetup.py file contains this:&lt;BR /&gt;import maya.cmds as cmds&lt;BR /&gt;import maya.OpenMaya as openMaya&lt;BR /&gt;import sys&lt;BR /&gt;&lt;BR /&gt;import maya.utils as utils&lt;BR /&gt;utils.executeDeferred ('import pythonScripts; pythonScripts.pythonScripts()')&lt;BR /&gt;sys.path.append( '/Users/borders/Library/Preferences/Autodesk/maya/2009/scripts' )&lt;BR /&gt;&lt;BR /&gt;However, when I try something like cmds.sphere() the script editor does not know that cmds is already loaded so I know that Maya is not reading in my userSetup.py file.  &lt;BR /&gt;&lt;BR /&gt;Thank you for your time and any help you can provide getting Maya to compile a Python script not entered in the command line.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Tiffany</description>
      <pubDate>Tue, 28 Sep 2010 17:42:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171107#M16132</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-09-28T17:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sourcing Python in Maya Error</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171108#M16133</link>
      <description>I don't have a mac if front of me, but you are close with &lt;BR /&gt;/Users/borders/Library/Preferences/Autodesk/maya/2009/scripts&lt;BR /&gt;can you try &lt;BR /&gt;/Users/borders/Library/Preferences/Autodesk/maya/scripts&lt;BR /&gt;&lt;BR /&gt;Also, in a python tab execute the following to print out a list of paths where you might put your userSetup.py and pythonScripts.py in order for Maya to find them.&lt;BR /&gt;(the path to the devkit is NOT in the paths, it is intentionally out of the way, as a usable example, but to use it you need to copy the scripts into your path.)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;import os&lt;BR /&gt;for pat in os.path:&lt;BR /&gt;    print pat&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;Wherever you end up putting your scripts, if you use the pythonScripts script, you can organise your scripts in folders, and they will appear as nested cascading menus beneath the pythonScripts menu.&lt;BR /&gt;&lt;BR /&gt;About sourcing, you don't source python scripts, sourcing is a MEL thing&lt;BR /&gt;&lt;BR /&gt;you import a python module (the name of the script without the py)&lt;BR /&gt;&lt;BR /&gt;so, like the bit in your pythonScripts script&lt;BR /&gt;&lt;BR /&gt;import helloworld1&lt;BR /&gt;&lt;BR /&gt;should fire off your script&lt;BR /&gt;but try it a second time, and it won't&lt;BR /&gt;import only works the first time you import, subsequent imports do not cost anything in terms of cpu and don't do anything.&lt;BR /&gt;&lt;BR /&gt;instead, you'd need to &lt;BR /&gt;reload(helloworld1)&lt;BR /&gt;(pythonScripts does this reload by default to help people while they are building scripts, if you ended up with a script that took a long time to reload (unlikely) and wasn't changing anymore, you might comment out the reload bit)&lt;BR /&gt;&lt;BR /&gt;Also, you could put your lines in a function named the same as your module, &lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;def helloworld1():&lt;BR /&gt;    print ('Hello World')&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;and then do&lt;BR /&gt;&lt;BR /&gt;import helloworld1 &lt;BR /&gt;&lt;BR /&gt;helloworld1.helloworld1 ()&lt;BR /&gt;&lt;BR /&gt;everytime you'd like to use that function.&lt;BR /&gt;(or use the pythonScripts menu to do the same thing, or put it in a python shelf button)</description>
      <pubDate>Wed, 29 Sep 2010 06:21:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171108#M16133</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-09-29T06:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sourcing Python in Maya Error</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171109#M16134</link>
      <description>Thank you so much for the reply!  I managed to miss the email that I actually received a reply so I apologize for not getting back to this response.&lt;BR /&gt;&lt;BR /&gt;- I stuck my helloworld1.py script in /Users/borders/Library/Preferences/Autodesk/maya/scripts&lt;BR /&gt;&lt;BR /&gt;- When I type the command you've suggested this is what happens:&lt;BR /&gt;&lt;BR /&gt;import os&lt;BR /&gt;for pat in os.path:&lt;BR /&gt;     print pat# Traceback (most recent call last):&lt;BR /&gt;#   File "/Applications/Autodesk/maya2009/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.5/site-packages/maya/app/python.py", line 17, in formatException&lt;BR /&gt;#     result = stringBuffer.getvalue().decode('utf8')&lt;BR /&gt;#   File "/Applications/Autodesk/maya2009/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.5/encodings/utf_8.py", line 16, in decode&lt;BR /&gt;#     return codecs.utf_8_decode(input, errors, True)&lt;BR /&gt;# UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position 59: unexpected code byte&lt;BR /&gt;&lt;BR /&gt;- Is this the output I should receive? &lt;BR /&gt;&lt;BR /&gt;- I copied my Usersetup.py file to /Applications/Autodesk/maya2009/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.5/site-packages/maya/app however, I am still having the same problem that when I type cmds.sphere( ) I get an error saying that 'cmd's is not defined (even though my userSetup.py says import maya.cmds as cmds.&lt;BR /&gt;&lt;BR /&gt;- Could explain to me what's the pythonScripts script? Where is the pythonScript menu? Is this in the Script Editor?  &lt;BR /&gt;&lt;BR /&gt;- The great news is that for the first time I was able to type 'import helloworld1' and it worked!  I tried it a second time and used the reload(helloworld1) and that worked as well.  I was also able to use the function.  Excellent!  I really appreciated the help on that one.  Now I just need to get my Usersetup.py file reading in correctly...&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Tiffany</description>
      <pubDate>Mon, 18 Oct 2010 17:42:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171109#M16134</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-18T17:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sourcing Python in Maya Error</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171110#M16135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;- I stuck my helloworld1.py script in &lt;BR /&gt;- When I type the command you've suggested this is what happens:&lt;BR /&gt;&lt;BR /&gt;import os&lt;BR /&gt;for pat in os.path:&lt;BR /&gt;     print pat# Traceback (most recent call last):&lt;BR /&gt;#   File "/Applications/Autodesk/maya2009/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.5/site-packages/maya/app/python.py", line 17, in formatException&lt;BR /&gt;#     result = stringBuffer.getvalue().decode('utf8')&lt;BR /&gt;#   File "/Applications/Autodesk/maya2009/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.5/encodings/utf_8.py", line 16, in decode&lt;BR /&gt;#     return codecs.utf_8_decode(input, errors, True)&lt;BR /&gt;# UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position 59: unexpected code byte&lt;BR /&gt;&lt;BR /&gt;- Is this the output I should receive? &lt;BR /&gt;&lt;BR /&gt;- Could explain to me what's the pythonScripts script? Where is the pythonScript menu?&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;That's an error, Are you using a non-us computer or language pack, do you have odd letters (maybe japanese or European or maybe using an appostrophe possibly?) in your folder names or loginID? &lt;BR /&gt; &lt;BR /&gt;let's try a prepend on the sys.path in the scriptEditor and see if that helps.&lt;BR /&gt;&lt;PRE&gt;import sys&lt;BR /&gt;sys.path.prepend("/Users/borders/Library/Preferences/Autodesk/maya/scripts")&lt;/PRE&gt;&lt;BR /&gt;To see if that works, put a new script in that location and see if you can import it and use its functions.&lt;BR /&gt;&lt;BR /&gt;pythonScripts script is in the devkit/other/pyqtScripts folder (or something like that, you mentioned it before, so I thought you might have seen it.)&lt;BR /&gt;It looks in the folder it is in, and in the folders beneath and builds another menu at the end of the menuBar in maya with each of your scripts available as menuItems.&lt;BR /&gt;&lt;BR /&gt;But that's not going to help, if you can't get &lt;BR /&gt;&lt;PRE&gt;import maya.cmds as cmds&lt;/PRE&gt;&lt;BR /&gt;to work, so tell me what it outputs in the script editor when you try to execute that.&lt;BR /&gt;if just a newline, &lt;BR /&gt;that's a good sign, try your &lt;BR /&gt;&lt;PRE&gt;cmds.sphere()&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Oct 2010 07:27:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171110#M16135</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-21T07:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sourcing Python in Maya Error</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171111#M16136</link>
      <description>Ok, well that makes sense at least, that path is not on your paths list...&lt;BR /&gt;&lt;BR /&gt;guess I'm thinking of another list like object.&lt;BR /&gt;You can prepend like this...&lt;BR /&gt;&lt;PRE&gt;&amp;gt;&amp;gt;&amp;gt; a = &lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; a.reverse()&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; a.append(1)&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; a.reverse()&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; print a&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;You should probably do the above prepend(reverse,append,reverse) to your path and then put your scripts in there.&lt;BR /&gt;&lt;BR /&gt;(you could try with an append and see if that works first...)</description>
      <pubDate>Fri, 22 Oct 2010 22:45:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171111#M16136</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-22T22:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sourcing Python in Maya Error</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171112#M16137</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;Thanks again for the reply. I am not using a non-US computer or language pack. No apostrophe in my folder names or login ID either. Hmm....&lt;BR /&gt;&lt;BR /&gt;This is the result of typing the above command:&lt;BR /&gt;import sys&lt;BR /&gt;sys.path.prepend("/Users/borders/Library/Preferences/Autodesk/maya/scripts")&lt;BR /&gt;# Error: 'list' object has no attribute 'prepend'&lt;BR /&gt;# Traceback (most recent call last):&lt;BR /&gt;#   File "&amp;lt;maya console&amp;gt;", line 2, in &amp;lt;module&amp;gt;&lt;BR /&gt;# AttributeError: 'list' object has no attribute 'prepend' # &lt;BR /&gt;&lt;BR /&gt;Any ideas?  &lt;BR /&gt;&lt;BR /&gt;Yes, I did find the pythonScripts script which lives in /Applications/Autodesk/maya2009/devkit/devkit/other/PyQtScripts and yes you are correct I have seen it. My userSetup.py is in this directory and "import maya.cmds as cmds" is on the top line yet when I open maya and type cmds.sphere() I get an error which says "# Error: name 'cmds' is not defined&lt;BR /&gt;# Traceback (most recent call last):&lt;BR /&gt;#   File "&amp;lt;maya console&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;# NameError: name 'cmds' is not defined # " &lt;BR /&gt;&lt;BR /&gt;This should work but I don't understand why my userSetup.py is not being read in correctly.&lt;BR /&gt;&lt;BR /&gt;However, if I type in the script editor &lt;BR /&gt;import maya.cmds as cmds&lt;BR /&gt;cmds.sphere()&lt;BR /&gt;there is no problem and that works fine. It would be nice to know that my userSetup.py was working properly and that I could add more commands to this file.  Thoughts?&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Mon, 25 Oct 2010 13:52:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/sourcing-python-in-maya-error/m-p/4171112#M16137</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-25T13:52:12Z</dc:date>
    </item>
  </channel>
</rss>

