10

I am getting

IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/python_dateutil-2.2-py2.7.egg/EGG-INFO/top_level.txt'

when I am trying to import pandas. I don't see why. Importing pandas in the python3 console works just fine. Execution of the code is done with Python3 too

start_simulation.py

from Market import Market
from TestingAlgorithm import TestingAlgorithm
from LiteForexHandler import LiteForexHandler
from Broker import Broker
from Portfolio import Portfolio

market = Market('./simulations/', 'test', TestingAlgortihm, LiteForexHandler,
    Broker, Portfolio)
market.run()`

Start of LiteForexHandler.py:

import sqlite3 as lite
from pandas import DataFrame
from DataHandler import DataHandler
import logging as log
from collections import defaultdict
...

And, finally the Traceback

Traceback (most recent call last):
  File "start_simulation.py", line 3, in <module>
    from LiteForexHandler import LiteForexHandler
  File "/home/ioan/Dokumente/finance/stocker/LiteForexHandler.py", line 2, in <module>
    from pandas import DataFrame
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1_501_g4c3b9e5-py2.7-linux-x86_64.egg/pandas/__init__.py", line 38, in <module>
    import pandas.core.config_init
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1_501_g4c3b9e5-py2.7-linux-x86_64.egg/pandas/core/config_init.py", line 17, in <module>
    from pandas.core.format import detect_console_encoding
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1_501_g4c3b9e5-py2.7-linux-x86_64.egg/pandas/core/format.py", line 9, in <module>
    from pandas.core.index import Index, MultiIndex, _ensure_index
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.13.1_501_g4c3b9e5-py2.7-linux-x86_64.egg/pandas/core/index.py", line 11, in <module>
    import pandas.index as _index
  File "index.pyx", line 34, in init pandas.index (pandas/index.c:15559)
  File "/usr/local/lib/python2.7/dist-packages/pytz-2014.2-py2.7.egg/pytz/__init__.py", line 29, in <module>
    from pkg_resources import resource_stream
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2823, in <module>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 710, in subscribe
    callback(dist)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2823, in <lambda>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2255, in activate
    self.insert_on(path)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2362, in insert_on
    self.check_version_conflict()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2401, in check_version_conflict
    for modname in self._get_metadata('top_level.txt'):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2249, in _get_metadata
    for line in self.get_metadata_lines(name):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1219, in get_metadata_lines
    return yield_lines(self.get_metadata(name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1211, in get_metadata
    return self._get(self._fn(self.egg_info,name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1326, in _get
    stream = open(path, 'rb')
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/python_dateutil-2.2-py2.7.egg/EGG-INFO/top_level.txt'
5
  • 2
    One thing you could try is to install every package in a virtualenv. For some reason, one module is trying to access a file in /usr/local/lib, which it can't do, because you haven't ran the script as a superuser. Commented Mar 29, 2014 at 19:54
  • 1
    I recommend anaconda to install pandas, which you can install w/o sudo. Commented Mar 29, 2014 at 20:13
  • I installed pandas from the ubuntu repository in the python3-pandas package...shouldn't that be the best way? Commented Mar 29, 2014 at 20:40
  • You can certainly get read access to /usr/local/lib without sudo. Something went wrong in the way you installed these packages. Virtualenv is your friend in this situation, and install all the packages you need via pip. Things can become inconsistent using apt-get for different python packages, and or mixing with pip. Plus soon hopefully all packages on pypi will use python wheels which will make installation just as fast as the prebuilt binaries in apt-get Commented Mar 29, 2014 at 20:55
  • it'll get you an old version of pandas, definitely not the recommended way. Commented Mar 30, 2014 at 5:20

3 Answers 3

16

This is a known issue with python-dateutil where the permissions aren't set correctly in the pypi package: https://bugs.launchpad.net/dateutil/+bug/1243202. This isn't a problem with pip because pip normalizes permissions, but if you install it differently you might run into problems.

The easy solution is to run

sudo chmod o+r /usr/local/lib/python2.7/dist-packages/python_dateutil-2.2-py2.7.egg/EGG-INFO/top_level.txt

and the same command on any other file you encounter with this problem in the dist-packages directory.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for that szxk. I ran into the 13 error for a whole bunch of packages, so changed the command to: sudo chmod -R o+r /Library/Python/2.7/site-packages to get all of them at once. I didn't think anything was strange with the install: just a pip install xyz, and it still didn't like it.
2

I was just having similar issues on my machine. Pip wasn't letting my install anything because nothing could be written to my site-packages directory. Not in love with this but I ran sudo chown -R $USER /Library/Python/2.7/site-packages/ and now Pip has no problem writing to my site-packages directory.

1 Comment

You probably should have called sudo pip install so that pip can write to shared directories, or pip install --user so that it doesn't try to write to a shared directory.
1

In my case:

sudo chmod o+r /usr/local/lib/python2.7/dist-packages/python_dateutil-2.2-py2.7.egg/EGG-INFO/top_level.txt

In general:

sudo chmod o+r [XXX]

where XXX is the file it is pointing to.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.