GordonWei's Blog


在Python3中安裝uniout



最近一直在處理Python3輸出中文的問題。
後來找到uniout這個套件,但是在Python3上使用pip3或抓Source tar.bz都裝不起來。
使用pip3安裝會出現下方訊息:

pip3 install uniout
Collecting uniout
  Downloading https://files.pythonhosted.org/packages/60/0a/6e6bc11a44be7ebc5e0975425d61963c271c737ee3e6989a6f8a0fb90800/uniout-0.3.7.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "", line 1, in 
      File "/tmp/pip-build-qartspbx/uniout/setup.py", line 6, in 
        import uniout
      File "/tmp/pip-build-qartspbx/uniout/uniout.py", line 9, in 
        if runs_in_ipython():
      File "/tmp/pip-build-qartspbx/uniout/_uniout.py", line 93, in runs_in_ipython
        import __builtin__
    ImportError: No module named '__builtin__'

    ----------------------------------------
接著就直接到錯誤訊息上方的網址抓souce package來安裝。
wget https://files.pythonhosted.org/packages/60/0a/6e6bc11a44be7ebc5e0975425d61963c271c737ee3e6989a6f8a0fb90800/uniout-0.3.7.tar.gz
解壓縮後直接使用python3安裝。
python3 setup.py install
Traceback (most recent call last):
  File "setup.py", line 6, in 
    import uniout
  File "/home/wei/uniout-0.3.7/uniout.py", line 9, in 
    if runs_in_ipython():
  File "/home/wei/uniout-0.3.7/_uniout.py", line 93, in runs_in_ipython
    import __builtin__
ImportError: No module named '__builtin__'
查了之後才發現是python3後將__builtin__改成builtins。
於是直接修改source,
vim  _uniout.py
def runs_in_ipython():
    '''Check if we are in IPython.'''
    import __builtin__
    return '__IPYTHON__' in __builtin__.__dict__ and \
           __builtin__.__dict__['__IPYTHON__']
改為
def runs_in_ipython():
    '''Check if we are in IPython.'''
    import builtins
    return '__IPYTHON__' in builtins.__dict__ and \
           builtins.__dict__['__IPYTHON__']
再重新setup一次。
python3 setup.py install
但,此動作並不會將package丟進sit-package裡,所以要自行複製。
cp -r /home/path/uniout-0.3.7  /Ur/python3/site-package-path/
最後再進到python3或ipython3驗證。
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import uniout
>>>
只要沒跳出錯誤訊息就表示成功。

以上文章皆是原創(廣告文除外),轉載前請先來信通知,本人同意後方可轉載,謝謝!

文章分類:Python


blog comments powered by Disqus

© 2019 www.kmp.tw