Python 导入 pandas.DataFrame 时出现“IOError: [Errno 13] Permission denied:.”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22736014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:31:19  来源:igfitidea点击:

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

pythonpython-3.xpandasioerror

提问by kave

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

当我尝试导入熊猫时。我不明白为什么。在 python3 控制台中导入熊猫工作得很好。代码的执行也是用 Python3 完成的

start_simulation.py

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:

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'

采纳答案by szxk

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.

这是 python-dateutil 的一个已知问题,其中 pypi 包中的权限设置不正确:https://bugs.launchpad.net/dateutil/+bug/1243202 。这不是 pip 的问题,因为 pip 规范了权限,但是如果您以不同的方式安装它,您可能会遇到问题。

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.

以及在 dist-packages 目录中遇到此问题的任何其他文件上的相同命令。

回答by Stephen Tetreault

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.

我只是在我的机器上遇到了类似的问题。Pip 没有让我安装任何东西,因为没有任何东西可以写入我的 site-packages 目录。不喜欢这个,但我跑了sudo chown -R $USER /Library/Python/2.7/site-packages/,现在 Pip 写入我的 site-packages 目录没有问题。

回答by user1854182

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.

其中 XXX 是它指向的文件。