Unable to Pinpoint Script Error I've searched various forums for an answer to this, so I hope it hasn't been asked before.

I want to load a .obj file called "male.obj". Here's the code:

import bpy
from bpy import context
from math import sin, cos, radians

import os

# establish path to model directory
path_to_directory = os.path.join(
    '~/', 'Users', 'jackburker', 'Documents',
    'Code', 'Blender', 'base_models')

path_to_file = os.path.join(path_to_directory, "male.obj")

# Print paths for debug
print(path_to_directory)
print(path_to_file)

# Import correct-gender base model
bpy.ops.import_scene.obj(filepath=path_to_file)


When run from the scripting console, that last line causes an error. Commented out, the script runs (though with no output). Uncommented, I get the message "Python script fail, look in the console for now..."

In Blender 2.77, on OS X El Capitan, I can't find a system console to open. If I "open blender.app" from the terminal, it doesn't follow the process or give any output; it just opens the app.

I've checked the documentation and, as far as I can tell, I'm using the import_scene function correctly.

Any ideas? I'm profoundly stuck.
I find running scripts in blenders python console can be very helpful, this addon adds a menu to the console that lets you run a text block from the python console where you can see any print output as well as leaving variables set as they are at the end of the script so you can have a look at what the script was working with when it failed.

By looking at your code I expect the error is the filepath in path_to_directory. On *nix systems ~ is used to represent a users home folder, when used in a shell this gets expanded automatically but in python you need to use os.path.expanduser() to get the absolute path which you will find gets expanded to /Users/jackburker which you are already adding to your path.

So you want to either use

path_to_directory = os.path.join(
    '/', 'Users', 'jackburker', 'Documents',
    'Code', 'Blender', 'base_models')


or

path_to_directory = os.path.join(
    os.path.expanduser('~'), 'Documents',
    'Code', 'Blender', 'base_models')