Python:导入错误:/usr/local/lib/python2.7/lib-dynload/_io.so:未定义符号:PyUnicodeUCS2_Replace

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

Python: ImportError: /usr/local/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS2_Replace

pythonpython-2.7ubuntu-12.04

提问by Mr. Concolato

I am trying to build a triviol Python script that will grab data from URL and save it onto the server. Concider the below code:

我正在尝试构建一个简单的 Python 脚本,它将从 URL 中获取数据并将其保存到服务器上。考虑以下代码:

#!/usr/bin/python
import pprint
import json
import urllib2

def getUSGS_json():
    print "Fetch data from URL"

    fileName = 'data/usgsEarthquacks_12Hrs.json'
    url = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson'
    data = urllib2.urlopen(url).read()

    if data:
        try:
            with open(fileName) as jsonGetData:
                filePut = open(fileName, 'w+')
                #add data
                filePut.write(data)
                filePut.close()

                j = json.load(jsonGetData)
                print j
        except Exception, e:
            print e
            raise
        else:
            pass
        finally:
            pass
    #end if
#end getUSGS_json

getUSGS_json()

Upon running the script I get the following errors:

运行脚本后,我收到以下错误:

Traceback (most recent call last):
  File "geoJsonFetch.py", line 4, in <module>
    import urllib2
  File "/usr/local/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/usr/local/lib/python2.7/httplib.py", line 79, in <module>
    import mimetools
  File "/usr/local/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/local/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: /usr/local/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS2_Replace

I have looked around on SO and found similar errors like this one, but they do not seem to get at the heart of why some people are able to get this code to run and I am not. They all seem to be dealing with issues concerning developing in C and using Python to access that C module.

我环顾四周的SO,发现类似的错误,像这一个,但他们似乎并没有得到在的心脏为什么有些人能够得到这个代码运行而我不是。他们似乎都在处理有关用 C 进行开发和使用 Python 访问该 C 模块的问题。

Is it the Ubuntu version, Python version??

是Ubuntu版,Python版吗??

Thank you.

谢谢你。

采纳答案by Aaron Digulla

You have (at least) two different versions of Python installed and you're mixing their files. Make sure that $PYTHONPATH, $PYTHONHOMEand sys.pathonly contain folders for a single Python installation. In your case, one installation is in /usr/localand the other is probably in /usr.

您(至少)安装了两个不同版本的 Python,并且正在混合它们的文件。确保$PYTHONPATH,$PYTHONHOME并且sys.path只包含单个 Python 安装的文件夹。在您的情况下,一个安装在/usr/local,另一个可能在/usr.

Also, you can try installing virtualenvwrapperand setting up separate python environment to alleviate any conflicts you might be having. Hereis a tutorial for installing and using virtualenv.

此外,您可以尝试安装virtualenvwrapper和设置单独的 python 环境来缓解您可能遇到的任何冲突。是安装和使用 virtualenv 的教程。