Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "IOError: [Errno 13] Permission denied:.." when importing pandas.DataFrame

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'
like image 294
kave Avatar asked Mar 29 '14 19:03

kave


2 Answers

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.

like image 115
szxk Avatar answered Nov 04 '22 16:11

szxk


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.

like image 41
Stephen Tetreault Avatar answered Nov 04 '22 17:11

Stephen Tetreault