Working with Python under ArcMap forced me to understand how to add and use new modules and packages in order to improve my scripts. It’s an important question to solve (at least, for me), due to its implications: reuse code, more functionality, …
This questiona arised when I was trying to include a module I was developing with a few functions for a small project that I wanted to use in two different scripts, and I was always receiving the same messages from Python within ArcMap: “No module name ….”
The solution came on this website:
I took option 2 for Windows, just by creating a text file saved as a .pth extension, in which I list all dir paths that has modules I want to use. This file should be copied into the “site-packages” directory, but … where is it this path?
Let’s write the file with the path where I have the modules:
Locating the site-packages dir
In order to locate the “site-package” dir, let’s code a little bit in order to know what options we have available under Python for ArcMap: :
for i in sys.path:
The results is:
Here is what we are looking for. in my case c:\Python26\ArcGIS10.0\lib\site-packages
Now, let’s clse ArcMap and open it again, and let’s run the previous code again, listing all dirs included with Sys.path. The reader can observe a new dir is added at the end, and it’s exactly what we wrote in the .pth file we created before.
I hope it can be useful to you!