Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

3ds max python import module problem

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
har1sf0x
5893 Views, 4 Replies

3ds max python import module problem

Hello there,

 

I am new to Python. In my need to learn more I am using pycharm to create a very simple project with two packages (tools and main). Both folders have __init__.py. Tools (the name is not actually 'Tools') has a .py file which has a def foo() which print 'something' and main has a .py file that imports Tools and runs Tools.foo(). In PyCharm everything works fine but when i run the main.py in max (using "python.executefile") it gives an error:
<type 'exception.ImportError'> No module named Tools

 

I have done a lot of internet research but i did not managed to find an answer. Any clue?

 

 

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: har1sf0x

is the package or module directory location of  "Tools" in the environment PYTHONPATH so that 3dsmax can know its available?

You can check by saying:

 

import sys
for x in sys.path:
   print x

if it isn't, then add it in your windows environment variables.(preferred)

or temporarily you can test it and say

 

import sys
sys.path.append( r'C:/Location/Of/Tools' )

Also, i believe max2017 doesn't rely on running python through maxscript anymore, so you can do it directly in the Python environment.

Message 3 of 5
har1sf0x
in reply to: Anonymous

Hello there,

 

Thnx a lot for your useful advise. It worked BUT:

 

I have to import all my packages as paths in 3ds max sys.path and if i do so I will have problem with name scope since i could have Tools01.main and Tools02.main. Is there a work around except of using unique names in a single or multiple packages? I think that this destroys the power of python using packages.

 

Thnx in advance

 

P.S. relative import unfortunately does not work (from .Tools01 import main etc.) error 'Attempted relative import in non-package'

Message 4 of 5
har1sf0x
in reply to: har1sf0x

It seams that you have to append the parent folder (project folder ) and then the import works fine. The only think is that you have to reload all modules if you use 3ds max interpreter... THNX A LOT DDelapena
Message 5 of 5
Anonymous
in reply to: har1sf0x

Yes, if you append the root path, then your namespaces will work fine. 

 

Your welcome.

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

Post to forums  

Autodesk Design & Make Report