2016-01-21 22 views
1

我安裝了pyenv來管理不同版本的Python,並使用pip install printtable來下載和安裝printtableImportError:無法在Python 3.5.1中導入名稱'PrintTable'by pyenv

但是,當我在交互式shell中導入該模塊時,它不起作用並顯示ImportError

$ pyenv versions 
    system 
    2.7.11 
* 3.5.1 (set by /Users/apple/.pyenv/version) 
$ pip list 
    pip (8.0.0) 
    printtable (1.2) 
    setuptools (18.2) 
$ python 
    Python 3.5.1 (default, Jan 21 2016, 12:50:43) 
    [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin 
    Type "help", "copyright", "credits" or "license" for more information. 
    >>> import printtable 
    Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Users/apple/.pyenv/versions/3.5.1/lib/python3.5/site-packages/printtable/__init__.py", line 1, in <module> 
    from printtable import PrintTable 
    ImportError: cannot import name 'PrintTable' 

如何在pyenv中管理模塊?

PS。我正在按照步驟Automate the boring stuff一步一步來。該printtable部分是在第6章

訪問結束:https://automatetheboringstuff.com/chapter6/

+0

試着做一個「pip3安裝打印表」,也許這將工作。 Pip最有可能安裝了python2.x的庫 – ishaan

+0

'pip --version'告訴python版本的pip安裝軟件包。 –

+0

是的,OP做到了。雖然OSX很可能有python2.x作爲默認,所以點也可能指向該python。 – ishaan

回答

0

我下載printtable

pip3 install --download /tmp printtable 

和檢查printtable-1.2.tar.gz的contentents。在printtable/printtable.py有像

def printTable(self,line_num=0): 
.... 
    print self.StrTable 

碼指示該包是不蟒3兼容。

它可能會通過

tar xfv printtable-1.2.tar.gz 
cd printtable-1.2/ 
2to3-3.5 --write printtable/*.py tests/*.py 
python3.5 setup.py build 
python3.5 setup.py install 
0

你沒有做錯什麼安裝此模塊;可打印模塊的寫法與Python 3完全不兼容。

由於您已經使用pyenv,並且根據pyenv versions的輸出,您已經安裝了Python 2.7.11,所以您可以簡單地安裝printtable for Python解釋器:

pyenv shell 2.7.11 
pip install printtable 
相關問題