I'm working on a project with the Raspberry Pi that involves connecting it to a MySQL database. After doing some research, I have found PyMySQL to be what I need to install through the terminal. I've tried to download it with

pip install PyMySQL

but I am just getting the following error:

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 295, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
self.move_wheel_files(self.source_dir, root=root)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 214, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 204, in clobber
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/PyMySQL-0.8.0.dist-info'

Storing debug log for failure in /home/pi/.pip/pip.log

Any ideas on how I can fix this?

1 Answer 1


It looks like you're trying to install PyMySql to your system without sufficient permissions. You can see the install script fail when it tries to create a new directory:

File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/PyMySQL-0.8.0.dist-info'

Do not resolve this by using sudo. Installing Python packages via sudo pip can cause serious problems with your system.

The solution is to install any Python packages you want to use for this project into a virtualenv.

A good way to make use of virtualenv is through virtualenvwrapper, which makes using virtualenv quick and easy.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .