Python Path

Python Path

billbedford
Advocate Advocate
625 Views
8 Replies
Message 1 of 9

Python Path

billbedford
Advocate
Advocate

How do I set the Python path in VS Code, and which one would be the best to use?

 

I have been trying to run a script in code, but there is this error message:

 

Home@Lincoln Bolt % "/Users/Home/Library/Application Support/Autodesk/webdeploy/production/2448aa8b3276a952725a8bb01f628b79
7da18a2a/Autodesk Fusion.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python"

"/Users/Home/Library/Application Support/Autodesk/webdeploy/production/2448aa8b3276a952725a8bb01f628b797da18a2a/Autodesk Fusion.app/Contents/Libraries/0Neutron/Python/Samples/Bolt/Bolt.py"

Traceback (most recent call last):
File "/Users/Home/Library/Application Support/Autodesk/webdeploy/production/2448aa8b3276a952725a8bb01f628b797da18a2a/Autodesk Fusion.app/Contents/Libraries/Neutron/Python/Samples/Bolt/Bolt.py", line 1, in <module>
import adsk.core, adsk.fusion, traceback
ModuleNotFoundError: No module named 'adsk'
Home@Lincoln Bolt %

 

 

0 Likes
626 Views
8 Replies
Replies (8)
Message 2 of 9

Jorge_Jaramillo
Advisor
Advisor

Hi,

 

On every Fusion project I always have the following configuration:

 

1. In file ".env" :

PYTHONPATH=C:/Users/<USER>/AppData/Local/Autodesk/webdeploy/production/<CURRENT_FUSION_ID_VERSION>/Api/Python/packages

 

2. In file ".vscode/settings.json" :

{
"python.autoComplete.extraPaths": ["C:/Users/<USER>/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Python/defs"],
"python.analysis.extraPaths": ["C:/Users/<USER>/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Python/defs"],
"python.pythonPath": "C:/Users/<USER>/AppData/Local/Autodesk/webdeploy/production/<CURRENT_FUSION_ID_VERSION>/Python/python.exe"
}

 

This is for a Windows environment.

Note: Replace <USER> and <CURRENT_FUSION_ID_VERSION> with user name and Fusion version accordingly.

 

On my environment (which is up-to-date) the CURRENT_FUSION_ID_VERSION is "4bca736941837d3e42bba21bb36b9891e34b2fce" for version # 2702.1.58.

Yours is "2448aa8b3276a952725a8bb01f628b797da18a2a"; are you sure you have the latest Fusion version installed? And how are you running your code?

 

I hope this can help you.

 

Regards,

Jorge Jaramillo

Software Developer

 

Message 3 of 9

billbedford
Advocate
Advocate

Thanks Jorge

 

First, I'm running Fusion on an Intel Mac, so I would imagine the CURRENT_FUSION_ID_VERSION to be different to yours. 

 

I'm trying out a new add-in in VS Code. 

 

The three files listed in ".vscode/settings.json" are

{

"python.autoComplete.extraPaths": ["/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Python/defs"],
"python.analysis.extraPaths": ["/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Python/defs"],
"python.defaultInterpreterPath": "/Users/Home/Library/Application Support/Autodesk/webdeploy/production/2448aa8b3276a952725a8bb01f628b797da18a2a/Autodesk Fusion.app/Contents/Frameworks/Python.framework/Versions/Current/bin/Python"
}
 
And in ".env"
PYTHONPATH=/Users/Home/Library/Application Support/Autodesk/webdeploy/production/2448aa8b3276a952725a8bb01f628b797da18a2a/Autodesk Fusion/
Contents/Api/Python/packages
 
They appear to be equivalent to the ones you posted. 
0 Likes
Message 4 of 9

Jorge_Jaramillo
Advisor
Advisor

Hi,

 

So, let's check from inside Fusion if you can import the adsk package and check internal python environment:

 

From the TEXT COMMANDS palette (at the bottom of the Fusion main screen with any project opened) and make sure "Py" is selected in the right-bottom corner, like in the following image:

Jorge_Jaramillo_1-1779925538830.png

 

1.  type "import adsk"

You should get nothing, meaning it was imported correctly.

 

2. Then type the following three commands and post the result:

import sys

print(sys.path)

print(sys.executable)

 

One final question: when you said in the first message "(...) I have been trying to run a script in code (...)": can you explain how are you trying to run the script step-by-step?  Are you running it from inside Fusion or from Code? 

 

Regards,

Jorge Jaramillo

Software Developer

 

0 Likes
Message 5 of 9

billbedford
Advocate
Advocate

I've used the TEXT COMMANDS and get these results

 

Import adsk: no return

Import sys: no return

print(sys.path): 

['/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/MacOS', '/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.14/site-packages', '/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python314.zip', '/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.14', '/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.14/lib-dynload', '/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/Libraries/Neutron/', '/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/Libraries/Neutron/nspylib.zip', '/Users/Home/Library/Application Support/Autodesk/webdeploy/production/a706025f86435b2ccd17930d01721ef22d0fd507/Autodesk Fusion.app/Contents/Api/Python/packages', '/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/MyScripts/', '/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/MyScripts/Autorun/', '/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/MyScripts/Samples/', '/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/MyScripts/ProgramData/', '/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/MyScripts/AppData/', '/Users/Home/Library/Application Support/Autodesk/Autodesk Fusion 360/MyScripts/ManuallyInstalled/']

 

import(sys.executable): invalid syntax (<string>, line 1)

 

I was originally running the script inside Code by pressing Run. This produced:ModuleNotFoundError: No module named 'adsk'. 

I've tried running the script in Fusion, but I only get the start and finish notifications. 

 

 

0 Likes
Message 6 of 9

rosie_lucas1
Autodesk
Autodesk

Hi @billbedford , 

Just circling back 😊 Were you able to figure this out, or do you still need a hand? Let us know by giving us an update on where you are at so the community can help guide you with next steps if possible. 

If you did solve it, it’d be awesome if you could share what worked so others can learn from it too. 

Best, 
 

Let us know how we did on Trustpilot.


Rosie
Community Manager
0 Likes
Message 7 of 9

billbedford
Advocate
Advocate

Hi

 

I've got some way with this, but I've run into this error:

 

from . import commands
ImportError: attempted relative import with no known parent package

So somewhere one of the setup inputs is not right.  

0 Likes
Message 8 of 9

Jorge_Jaramillo
Advisor
Advisor

Hi @billbedford ,

 

Sorry being late to provide a feedback to your answers from May-28th message, but I didn't get an email message notification for it.

 

I believe that in the last message you provide the answer to the original problem: python scripts that use Fusion's API should run ONLY within Fusion and never from an external environment like Code in you case.

Also notice that the configuration in code point to "2448aa8b3276a952725a8bb01f628b79" Fusion version, and the values you provide to my questions that run inside Fusion point to "a706025f86435b2ccd17930d01721ef22d0fd507", which means you have a misconfiguration in you Code project environment.

 

Regarding the error you get with "from . import commands", check that your local project have a commands directory, which is use in the AddIn examples to place the scripts to load the different commands you need in your AddIn.

 

I hope this can help somehow.

 

Regards,

Jorge Jaramillo

 

 

0 Likes
Message 9 of 9

karnapanik
Observer
Observer

I'd be interested to know what the solution here is as well. import adsk.core from the TEXT COMMAND box works, but running from inside VSCode does not. I've mimicked @billbedford and @Jorge_Jaramillo config settings but remain stuck at:

import adsk.core, adsk.fusion, traceback
ModuleNotFoundError: No module named 'adsk'

 

settings.json

{
	"python.autoComplete.extraPaths":	["C:/Users/user/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Python/defs"],
	"python.analysis.extraPaths":	["C:/Users/user/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Python/defs"],
	"python.defaultInterpreterPath": "C:/Users/user/AppData/Local/Autodesk/webdeploy/production/9c5312dfff2e4569cd1d269973ddf11cb999f782/Python/python.exe",
	"python-envs.defaultEnvManager": "ms-python.python:system"
}

.env

PYTHONPATH=C:/Users/user/AppData/Local/Autodesk/webdeploy/production/9c5312dfff2e4569cd1d269973ddf11cb999f782/Api/Python/packages

 

EDIT:

I figured it out. The Run or Debug button to the right of the file tabs does not work. Going to Run and Debug (Ctrl-Shift-D) on the left side which pops out a frame and then running the Start Debugging button does. Not sure why VSCode loads environments properly in one and not the other though.

0 Likes