[Bf-python] questions about best practice

Sybren A. Stüvel sybren at stuvel.eu
Wed Dec 3 22:19:52 CET 2014


On Wed, Dec 03, 2014 at 12:53:33PM -0700, Dan Eicher wrote:
>> Secondly, when I open a script in the Blender Text Editor to run, and I'm
>> using an external module or package, how do I add that module / package to
>> the path? Right now, in my script, `import foo` just gets me `No module
>> named foo`.

This is due to the current working directory being set to Blender's
directory, and not the directory of the .blend file.

> I tend to use sys.path.append() a lot since fedora doesn't have
> /usr/local/lib in python's default path but you can also drop the
> module in blender's addon module directory too. Not really sure how
> it works when python is bundled with blender though...

Loading your script as an add-on gives the added advantage that you
can press F8 to reload it. However, usually I want to put my .blend
file and Python scripts in the same directory. If you want to do that
too, take a look at the approach I describe at
http://stuvel.eu/blog/203/reloading-your-code-in-blender This gives
you a setup that allows you to load modules from the same directory as
your .blend file, and easily reload your code. The reloading isn't
flawless, but it works most of the time ;-)


-- 
Sybren A. Stüvel

http://stuvelfoto.nl/
http://stuvel.eu/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20141203/706f9f93/attachment.sig>


More information about the Bf-python mailing list