After adding python social auth to my installed apps, i.e.
INSTALLED_APPS = (
...
'social.apps.django_app.default',
...
)
and then trying a
python manage.py makemigrations
I get an unsurprising permissions error
Migrations for 'default':
0002_auto_20150217_2053.py:
- Alter field user on usersocialauth
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management /__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 124, in handle
self.write_migration_files(changes)
File "/usr/lib/python2.7/site-packages/django/core/management/commands /makemigrations.py", line 153, in write_migration_files
with open(writer.path, "wb") as fh:
IOError: [Errno 13] Permission denied: u'/usr/lib/python2.7/site-packages/social/apps/django_app/default/migrations/0002_auto_20150217_2053.py'
It makes sense that I can not write to system wide package installation directories.
There are some obvious ways around this, like changing the permissions on the site-packages/social directories. However, is this the only way of doing this, or am I missing something?
As stated in your question, changing the permissions on the directories would be a solution. Yet, another way to do this is to create an isolated Python environment for your Django project using virtualenv. Or, more conveniently, the extension virtualenvwrapper.
Install the later like this:
$ pip install virtualenvwrapper
The following creates an activates a virtualenv for your project:
$ mkvirtualenv django_project
$ workon django_project
After that, you are free to install Django and Python Social Auth
$ pip install django
$ pip install python-social-auth
You will notice that all this will be installed in $HOME/.virtualenvs/django_project
This is a common, recommended practice among Python and Django users. It will solve the permission issues, as well as other dependency issues that you may run into if you use your system's Python installation for all your projects.
Note that Python Social Auth does in fact require the creation of a migration before its use in a Django project, the migration adds a related_name to the foreign key 'user' in the 'UserSocialAuth' model