I am trying to install timestring library into python3.5 on ubuntu 16.04 using the command: pip3 install timestring

Getting this error:

Traceback (most recent call last):
  File "/home/user/.local/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/user/.local/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
  File "/home/user/.local/lib/python3.5/site-packages/pip/req/req_set.py", line 742, in install
  File "/home/user/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/home/user/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
  File "/home/user/.local/lib/python3.5/site-packages/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/user/.local/lib/python3.5/site-packages/pip/wheel.py", line 317, in clobber
  File "/home/user/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/pytz-2013b0.dist-info'

I am not sure what's exactly wrong. How can I get the timestring library installed?

2 Answers 2


It's trying to install in a system directory and your user doesn't have permissions to do that.

You have 2 options:

  1. Install locally, usually in a virtualenv. See here: http://docs.python-guide.org/en/latest/dev/virtualenvs/
  2. Install globally, with sudo so you have root privileges: sudo pip install timestring

Personally I prefer option 1, and to keep each project's dependencies isolated in a venv, but that's up to you.


Looking at the traceback, pip3 is trying to create a directory in /usr/local/lib/python3.5/dist-packages but it does not have permissions to do so because you probably did not run pip3 with sudo. The best way to install timestring though is to avoid sudo altogether and use virtualenv instead. The following code worked for me:

sudo apt update && sudo apt install virtualenv  # install virtualenv if you haven't
cd ~/<project directory>  # cd to your project directory
virtualenv venv -p python3  # create virtualenv named venv for Python 3
source venv/bin/activate  # activate virtualenv
pip install timestring

After you are done with writing code for the project, run deactivate to deactivate the virtualenv.

You must log in to answer this question.

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