<?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: Python module not importing in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7553792#M17272</link>
    <description>&lt;P&gt;Nicely orchestrated Kris!&amp;nbsp; &amp;nbsp;That worked and&amp;nbsp;I was also able&amp;nbsp; to figured out my original problem using relative references which is not worth describing here.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You for you quick response!&amp;nbsp; &amp;nbsp;Bill&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2017 18:27:02 GMT</pubDate>
    <dc:creator>balunist</dc:creator>
    <dc:date>2017-11-17T18:27:02Z</dc:date>
    <item>
      <title>Python module not importing</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7537867#M17267</link>
      <description>&lt;P&gt;I'm having trouble getting the numpy module to work with a python script I've been working on for Fusion 360.&amp;nbsp; I looked around the forum and I didn't see any other posts with this particular problem.&amp;nbsp; I even tried running a script that did nothing but try to import the module with no luck.&amp;nbsp; I've gone so far as to completely uninstall python from my computer except for what comes in Fusion 360.&amp;nbsp; I ran pip to install numpy into that python installation and then copied that numpy folder into my script folder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've setup my folder structure exactly as is shown in the help documentation linked below&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-743C88FB-CA3F-44B0-B0B9-FCC378D0D782#Additional Python Modules" target="_blank"&gt;http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-743C88FB-CA3F-44B0-B0B9-FCC378D0D782#Additional Python Modules&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Command:&lt;/P&gt;&lt;P&gt;from .Modules import numpy as np&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error Message:&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; Traceback (most recent call last):&lt;BR /&gt;File "C:/Users/Eric/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/Test\Modules\__init__.py", line 126, in &amp;lt;module&amp;gt;&lt;BR /&gt;from numpy.__config__ import show as show_config&lt;BR /&gt;ImportError: No module named 'numpy'&lt;/P&gt;&lt;P&gt;During handling of the above exception, another exception occurred:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:/Users/Eric/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/Test/Test.py", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;from .Modules import numpy as np&lt;BR /&gt;File "C:/Users/Eric/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/Test\Modules\__init__.py", line 131, in &amp;lt;module&amp;gt;&lt;BR /&gt;raise ImportError(msg)&lt;BR /&gt;ImportError: Error importing numpy: you should not try to import numpy from&lt;BR /&gt;its source directory; please exit the numpy source tree, and relaunch&lt;BR /&gt;your python interpreter from there.&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand why I'm getting this error since the script is not located in the numpy directory.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 01:53:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7537867#M17267</guid>
      <dc:creator>esm7b</dc:creator>
      <dc:date>2017-11-13T01:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python module not importing</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7540055#M17268</link>
      <description>&lt;P&gt;You're not the first to try &lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/how-to-install-numpy/m-p/7423420" target="_blank"&gt;(link) &lt;/A&gt;- they never followed up so I assume they did not succeed. After my brief investigation the problem is that even if you get it working it won't be re-distributable as numpy is largely a C library that gets compiled for your machine on install. The numpy source has some interesting checks in it to detect if it is running from the installer, or running as a lib, I suspect this is the code path you are seeing (numpy cant find its compiled c code or maybe it's something as simple as a flag / env var is not set). Take a look at the &lt;A href="https://github.com/numpy/numpy" target="_blank"&gt;numpy source&lt;/A&gt; and work from there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good luck, if you figure it out be sure to post how you did it so others can too!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 17:47:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7540055#M17268</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-13T17:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python module not importing</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7544320#M17269</link>
      <description>&lt;P&gt;I was able to fix my problem.&amp;nbsp; I took the installed numpy folder and moved it to one of the folders in my 'sys.path' list and changed the call from "from .Modules import numpy as np" to just "import numpy as np" and now everything works.&amp;nbsp; I thought that I had tried installing it in the "..\Autodesk\webdeploy\production\&amp;lt;bunch of numbers&amp;gt;\Python\lib\site-packages" folder with no luck, but when I moved it back in there it ran without any problems.&amp;nbsp; It doesn't explain the error I was getting when I was trying to import it from the "Modules" folder, but it works now so I'm not complaining.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:28:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7544320#M17269</guid>
      <dc:creator>esm7b</dc:creator>
      <dc:date>2017-11-14T22:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python module not importing</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7548258#M17270</link>
      <description>&lt;P&gt;I am not able to include the package svgwrite with my script plugin.&amp;nbsp; The package, which is python only and no native code, is contain in the subdirectory svgwrite and includes a __init__.py file.&amp;nbsp; I've included this package directory in the save directory as my script.&amp;nbsp; Executing my python module outside Fusion only requires me to include "import svgwrite" and all works.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Creating a directory Modules and moving the package under Modules as suggested.&amp;nbsp; This did not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Located the&amp;nbsp;&lt;STRONG&gt;/Users/xxx/Library/Application Support/Autodesk/webdeploy/production/&amp;lt;bunch of numbers&amp;gt;/Api/Python/packages &lt;/STRONG&gt;and copying package here&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;and this didn't work either.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Creating a plugin without&amp;nbsp;a way to create or use packages is crazy.&amp;nbsp; &amp;nbsp;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Bill&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 02:27:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7548258#M17270</guid>
      <dc:creator>balunist</dc:creator>
      <dc:date>2017-11-16T02:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python module not importing</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7551322#M17271</link>
      <description>&lt;P&gt;For normal, self contained dependent modules, you would normally only need to copy the dependent modules or packages into a path relative to your script (such as a 'Modules' subfolder), and import with a relative import statement.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;from .Modules import submodule&lt;/PRE&gt;
&lt;P&gt;But some packages make assumptions that they or their dependencies are located in the system path.&amp;nbsp; In that case, if you attempt to import the module or package, it will import dependencies or it's own modules with absolute imports (instead of relative imports), and that will fail if the parent folder of the module/package is is not in the system path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, you have two options.&amp;nbsp; The first is to edit the module/package code so that it uses relative imports on its sub/dependent module imports.&amp;nbsp; In some cases this is relatively easy.&amp;nbsp; But in many cases it is non trivial, and in cases of compiled modules it may be impossible without rebuilding it.&amp;nbsp; The second option is to modify the system path to include your 'Modules' subfolder before importing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If possible, modifying the module/package to use relative imports would be preferable.&amp;nbsp; Modifying the system path is simpler, but it can affect the module resolution behavior of other addins or scripts (because they are all sharing the same runtime).&amp;nbsp; If multiple scripts/addins import a module/package with the same name using an absolute import with a modified system path, they will collide&amp;nbsp;and cause failures for one of them (if they are not the same module/package or the same version).&amp;nbsp; So if you do modify the system path, do so only around the import (or around any calls that may result in an import that expects it if there are inlined imports).&amp;nbsp; Make sure to revert your changes to the system path before returning control to the runtime.&amp;nbsp; For example, I was able to import svgwrite by copying it and the pyparsing.py module into a 'Modules' subfolder in a script and importing it with the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;modules = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Modules')
sys.path.insert(0, modules)
from .Modules import svgwrite
popped = sys.path.pop(0)
assert(popped == modules)&lt;/PRE&gt;
&lt;P&gt;Kris&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 22:29:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7551322#M17271</guid>
      <dc:creator>KrisKaplan</dc:creator>
      <dc:date>2017-11-16T22:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python module not importing</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7553792#M17272</link>
      <description>&lt;P&gt;Nicely orchestrated Kris!&amp;nbsp; &amp;nbsp;That worked and&amp;nbsp;I was also able&amp;nbsp; to figured out my original problem using relative references which is not worth describing here.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You for you quick response!&amp;nbsp; &amp;nbsp;Bill&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 18:27:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-module-not-importing/m-p/7553792#M17272</guid>
      <dc:creator>balunist</dc:creator>
      <dc:date>2017-11-17T18:27:02Z</dc:date>
    </item>
  </channel>
</rss>

