Python 未找到符号:__PyCodecInfo_GetIncrementalDecoder

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34386527/
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 14:55:19  来源:igfitidea点击:

Symbol not found: __PyCodecInfo_GetIncrementalDecoder

pythonpython-2.7pycharmsetuptools

提问by orome

Since updating from Homebrew Python 2.7.11 (from 2.7.10) I'm suddenly unable to test register my package on PyPi from the PyCharm IDE console.

自从从 Homebrew Python 2.7.11(从 2.7.10)更新后,我突然无法从 PyCharm IDE 控制台测试在 PyPi 上注册我的包。

Running (as an "External Tool")

运行(作为“外部工具”)

python -B setup.py register -r pypitest

I now get

我现在得到

Traceback (most recent call last):
  File "setup.py", line 22, in <module>
    from setuptools import setup
  File "/usr/local/lib/python2.7/site-packages/setuptools/__init__.py", line 12, in <module>
    from setuptools.extension import Extension
  File "/usr/local/lib/python2.7/site-packages/setuptools/extension.py", line 8, in <module>
    from .dist import _get_unpatched
  File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 16, in <module>
    from setuptools.depends import Require
  File "/usr/local/lib/python2.7/site-packages/setuptools/depends.py", line 6, in <module>
    from setuptools import compat
  File "/usr/local/lib/python2.7/site-packages/setuptools/compat.py", line 17, in <module>
    import httplib
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in <module>
    import mimetools
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Process finished with exit code 1

I'm not sure how to proceed. I only get this issue if I execute from within my IDE's console. If I do it directly at the system command line (Terminal on OS X) I have no problems.

我不知道如何继续。如果我从 IDE 的控制台中执行,我只会遇到这个问题。如果我直接在系统命令行(OS X 上的终端)上执行此操作,则没有问题。



OS X 10.11.3; Homebrew Python 2.7.11; PyCharm 5.0.3

OS X 10.11.3;自制 Python 2.7.11;PyCharm 5.0.3

回答by ivan_pozdeev

According to https://github.com/klen/python-mode/issues/634:

根据https://github.com/klen/python-mode/issues/634

I had the same issue, but successfully fixed. In my case I compiled python and vim with homebrew, when PYTHON_PATH has been specified and set to one of my dev environments, where I also had some libraries, including io. Workaround was simple: open new terminal, make sure that you do not have custom PYTHON_PATH, uninstall python, uninstall vim. Reinstall both of them.

我有同样的问题,但成功修复。在我的情况下,当 PYTHON_PATH 已被指定并设置为我的开发环境之一时,我用自制软件编译了 python 和 vim,在那里我也有一些库,包括 io。解决方法很简单:打开新终端,确保您没有自定义 PYTHON_PATH,卸载 python,卸载 vim。重新安装它们。

and

Problem solved.

Culprit is the update from python 2.7.10 to 2.7.11.

If you are using conda package control, simply run "conda install python=2.7.10" will solve this problem.

问题解决了。

罪魁祸首是从 python 2.7.10 到 2.7.11 的更新。

如果您使用的是 conda 包控制,只需运行“conda install python=2.7.10”即可解决此问题。

This doesn't give the root cause though. Since this happens with _io, this looks like a bug in python 2.7.11 (unlikely, there would be a world-scale outcry and a prompt fix if it was) or some packaging bug or version mismatch specifically with the homebrew version (and maybe some related ones, too).

但这并没有给出根本原因。由于这种情况发生在_io,这看起来像是 python 2.7.11 中的一个错误(不太可能,如果是的话,会有世界范围的抗议和及时修复)或者一些打包错误或版本与自制软件版本不匹配(可能还有一些也有相关的)。

Try to import _ioin the console and if it succeeds, check if it was loaded from the same path.

尝试import _io在控制台中,如果成功,请检查它是否从同一路径加载。

回答by Yanan

I had the same issue, it is successfully fixed by just replacing the _io.so file.

我遇到了同样的问题,只需替换 _io.so 文件即可成功修复。

sudo find / -name _io.so

copy the path of the _io.sofile which DOES NOTbelong to python-2.7.11. For example, copy the path of _io.so which is under python-2.7.5: /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

复制属于 python-2.7.11的_io.so文件的路径。比如复制python-2.7.5下的_io.so的路径:/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-动态加载/_io.so

Replace the /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.sofile with the _io.sothat you just found.

用您刚刚找到的/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so文件替换该文件_io.so

回答by Stuart Berg

tl;dr: Fix this issue by doing one of the following:

tl;dr:通过执行以下操作之一来解决此问题:

  • type hash -r python, OR
  • log out and log in.
  • hash -r python,OR
  • 注销并登录。

EDIT:An answer to my related questionmakes it clear what's happening here. When you install a new version of python, you may need to run hash -r pythonto tell bash to reset the "cached" location to the pythonexecutable.

编辑:对我的相关问题的回答清楚地说明了这里发生了什么。当您安装新版本的 python 时,您可能需要运行hash -r python以告诉 bash 将“缓存”位置重置为python可执行文件。

In my case, I was typing python, which was on my $PATHat /usr/local/bin/python. But bashwas still using the old cache location /usr/bin/python. So, the old executable was called, but the newpath was provided to python in sys.argv[0]. This means that the old executable was running, but the new sys.executablevalue caused all the wrong modules to get loaded (including the iomodule).

就我而言,我正在输入python,这是在我的$PATHat 上/usr/local/bin/python。但bash仍在使用旧的缓存位置/usr/bin/python。因此,旧的可执行文件被调用,但路径以sys.argv[0]. 这意味着旧的可执行文件正在运行,但新sys.executable值导致所有错误的模块被加载(包括io模块)。



I'm having the same problem. I installed python 2.7.11 via an installer from Python.org. Strangely, the issue seems to be related to some subtle difference between how OSX launches pythonwhen I invoke it from the shell using the full path vs. using just the word python.

我有同样的问题。我通过 Python.org 的安装程序安装了 python 2.7.11。奇怪的是,这个问题似乎与python我使用完整路径从 shell 调用OSX与仅使用单词python.

So, for me, this works (invoking python via the full path /usr/local/bin/python):

所以,对我来说,这是有效的(通过完整路径调用 python /usr/local/bin/python):

$ which python
/usr/local/bin/python
$ /usr/local/bin/python -c "import io"
$

... but this doesn't:

……但这不是:

$ python -c "import io"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

So, as a workaround, you can try doing the same thing.

因此,作为一种解决方法,您可以尝试做同样的事情。

Elsewhere, I've posted a separate questionabout this puzzling behavior. Maybe somehow merely calling pythoninvokes some strange mix of the 2.7.11 executable with the 2.7.10 dylibs??

在其他地方,我已经发布了一个关于这种令人费解的行为的单独问题。也许不知何故只是调用python调用了 2.7.11 可执行文件与 2.7.10 dylib 的奇怪组合?

回答by kizzx2

This happened to me as well in MacVim. I solved it by making sure :python print(sys.path)is using system Python(e.g. /Library/Python/2.7/...)

这在 MacVim 中也发生在我身上。我通过确保:python print(sys.path)使用系统 Python来解决它(例如/Library/Python/2.7/...

Since I installed MacVim via Homebrew, I just did that by:

由于我通过 Homebrew 安装了 MacVim,我只是通过以下方式做到了:

  1. Spawn a new shell that had which python-> /usr/bin/python. For my case I needed to remove the pyenvline from my .bash_profile. If you installed Python via Homebrew you may want to brew unlink pythonfirst

  2. brew reinstall macvim

  1. 生成一个具有which python->的新外壳/usr/bin/python。对于我的情况,我需要pyenv从我的.bash_profile. 如果您通过 Homebrew 安装了 Python,您可能需要brew unlink python

  2. brew reinstall macvim

回答by Ethan Keller

This happened when I already had tried to create a venv in a folder, and mistakenly was trying to initialize a second one! So I just removed venv directory and re-ran the command. Very likely this is not the answer to this solution, but searching my error brought me here, so it may help some others who are stuck.

当我已经尝试在文件夹中创建一个 venv 并且错误地尝试初始化第二个时,就会发生这种情况!所以我只是删除了 venv 目录并重新运行了命令。这很可能不是这个解决方案的答案,但搜索我的错误把我带到了这里,所以它可能会帮助其他一些被卡住的人。

回答by tngn

Can't add comment (?) so this just to share my exp., downgrade to 2.7.10 works fr me.

无法添加评论 (?) 所以这只是为了分享我的经验,降级到 2.7.10 对我有用。

回答by Noel Ruault

Reinstall python.

重新安装蟒蛇。

brew unlink python && brew reinstall python

Secure the path

确保路径

export PYTHONPATH=$PYTHONPATH:/usr/local/bin/

BACKUPand Change the order of "paths" file.

备份和更改“路径”文件的顺序。

sudo nano /etc/paths

it seems, the order of paths, it is decisive to run python properly. In my case, the result was:

看来,路径的顺序,是决定正确运行python的决定性因素。就我而言,结果是:

#sudo nano /etc/paths
  /usr/bin  
  /usr/local/bin
  /bin
  /usr/sbin
  /sbin

On my mac, path is like this.

在我的 Mac 上,路径是这样的。

$ which python
    /usr/local/bin/python

Now I can run both:

现在我可以同时运行:

$ /usr/local/bin/python -c "import io"
$ python -c "import io"

回答by gogasca

I got this error after a failed NLTK download, I needed to uninstall anaconda:

NLTK 下载失败后出现此错误,我需要卸载 anaconda:

sudo rm -rf ~/anaconda 
update PATH variable

回答by Fermat's Little Student

If your problem is caused by anaconda, it is unnecessary to remove //anacondadirectory.

如果您的问题是由 引起的anaconda,则无需删除//anaconda目录。

Just open your ~/.bash_profile, find the line

只需打开您的~/.bash_profile,找到该行

export PATH="//anaconda/bin:$PATH

and comment it out, then restart your terminal session.

并将其注释掉,然后重新启动您的终端会话。

回答by skeller88

Another quick workaround if you don't mind sticking with Python 2.7.10 is to specify the path of the Python interpreter executable that will be used for the virtualenv. On OSX that path is usually /usr/bin/python:

如果您不介意坚持使用 Python 2.7.10,另一个快速解决方法是指定将用于 virtualenv 的 Python 解释器可执行文件的路径。在 OSX 上,该路径通常是/usr/bin/python

virtualenv venv --python=/usr/bin/python