2016-01-21 21 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 
相关问题