Python 3.4中ciscoconfparse模块无法正确导入
我正在尝试在Linux Mint 17上安装一个叫做ciscoconfparse的Python模块。当我用Python 2通过pip安装时,一切都很顺利,导入的时候没有问题。但当我用pip3(针对Python 3.4)安装时,模块确实出现在安装目录里,但我却无法导入它的任何部分。
我可以在这里找到这个模块
/usr/local/lib/python3.4/dist-packages/ciscoconfparse-1.1.1-py3.4.egg/ciscoconfparse
在这个目录里有一个ciscoconfparse.py文件,里面有CiscoConfParse这个类,但我无法用
from ciscoconfparse import CiscoConfParse
来导入它。当我尝试安装时,似乎有一些问题,但仍然显示安装成功。
~/Downloads/ciscoconfparse-1.1.1 $ sudo pip3 install ciscoconfparse Downloading/unpacking ciscoconfparse Downloading ciscoconfparse-1.1.1.tar.gz (76kB): 76kB downloaded Running setup.py (path:/tmp/pip_build_root/ciscoconfparse/setup.py) egg_info for package ciscoconfparse zip_safe flag not set; analyzing archive contents... Installed /tmp/pip_build_root/ciscoconfparse/setuptools_hg-0.4-py3.4.egg warning: no previously-included files matching '__pycache__' found under directory '*' warning: no previously-included files matching '*.orig' found under directory '*' warning: no previously-included files matching 'BUILD.ME' found under directory '*' warning: no previously-included files matching 'BITBUCKET_HG' found under directory '*' warning: no previously-included files matching '.hgrc' found under directory '*' warning: no previously-included files matching '*' found under directory '.hg' warning: no previously-included files matching '*' found under directory 'sphinx-doc' Installing collected packages: ciscoconfparse Running setup.py install for ciscoconfparse warning: no previously-included files matching '__pycache__' found under directory '*' warning: no previously-included files matching '*.orig' found under directory '*' warning: no previously-included files matching 'BUILD.ME' found under directory '*' warning: no previously-included files matching 'BITBUCKET_HG' found under directory '*' warning: no previously-included files matching '.hgrc' found under directory '*' warning: no previously-included files matching '*' found under directory '.hg' warning: no previously-included files matching '*' found under directory 'sphinx-doc' File "/usr/local/lib/python3.4/dist-packages/ciscoconfparse/excldiff_test.py", line 31 print diffs ^ SyntaxError: invalid syntax Successfully installed ciscoconfparse Cleaning up...
在作者的网站上,他说这个模块已经在Python 3.2以上的版本上测试过可以正常工作。我正在使用Pycharm作为开发环境。目前看来,我可以选择使用一个Python 3的虚拟环境,看看这样是否会有所不同,或者我可以把这个模块直接放到我正在制作的模块里。请问安装不成功的原因可能是什么?或者,有没有什么好的方法可以把这个模块包含到我的项目中?
2 个回答
我也遇到过同样的问题,不过在最新的版本1.1.3中已经修复了。你可以试试这个版本,链接在这里:https://pypi.python.org/pypi/ciscoconfparse/1.1.3。
有没有什么原因导致安装可能不成功?或者说,最好的方法是什么来把这个模块放到我的项目里?
ciscoconfparse 版本 1.1.1 在所有 Python3 版本中都失败了,因为相对导入出了问题。
相对导入的问题是因为 PEP 366 没有被 ciscoconfparse
版本 1.1.1(以及之前的版本)遵循。为了解决这个问题,ciscoconfparse 在这个包里添加了一个 __main__.py
文件。我手动测试过这个文件,分别在 Python2.7 和 Python3.4.1 上运行;据我所知,版本 1.1.2 修复了 Python3 的问题。