Python 3.4 模块中的 ciscoconfparse 无法正确导入 [英] ciscoconfparse in Python 3.4 module doesn't import correctly
问题描述
我正在尝试在 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类,但是我不能用
导入<前>从 ciscoconfparse 导入 CiscoConfParse当我尝试安装时,看起来有一些问题,但仍然说它已成功安装.
<前>~/Downloads/ciscoconfparse-1.1.1 $ sudo pip3 install ciscoconfparse下载/解压 ciscoconfparse下载ciscoconfparse-1.1.1.tar.gz (76kB): 下载76kB运行 setup.py(路径:/tmp/pip_build_root/ciscoconfparse/setup.py)egg_info 包 ciscoconfparsezip_safe 标志未设置;分析存档内容...安装/tmp/pip_build_root/ciscoconfparse/setuptools_hg-0.4-py3.4.egg警告:在目录*"下找不到与__pycache__"匹配的先前包含的文件警告:在目录*"下找不到与*.orig"匹配的先前包含的文件警告:在目录*"下找不到与BUILD.ME"匹配的先前包含的文件警告:在目录*"下找不到与BITBUCKET_HG"匹配的先前包含的文件警告:在目录*"下找不到与.hgrc"匹配的先前包含的文件警告:在目录.hg"下找不到与*"匹配的先前包含的文件警告:在目录sphinx-doc"下找不到与*"匹配的先前包含的文件安装收集的软件包:ciscoconfparse为 ciscoconfparse 运行 setup.py install警告:在目录*"下找不到与__pycache__"匹配的先前包含的文件警告:在目录*"下找不到与*.orig"匹配的先前包含的文件警告:在目录*"下找不到与BUILD.ME"匹配的先前包含的文件警告:在目录*"下找不到与BITBUCKET_HG"匹配的先前包含的文件警告:在目录*"下找不到与.hgrc"匹配的先前包含的文件警告:在目录.hg"下找不到与*"匹配的先前包含的文件警告:在目录sphinx-doc"下找不到与*"匹配的先前包含的文件文件/usr/local/lib/python3.4/dist-packages/ciscoconfparse/excldiff_test.py",第31行打印差异^语法错误:无效语法成功安装ciscoconfparse打扫干净...在作者网站上,他说它已经过测试,可以在 Python > 3.2 上运行.我使用 Pycharm 作为 ide.到目前为止,我似乎可以在 python3 中使用虚拟环境,看看是否有任何改变,或者我可以将模块放入我正在制作的模块中.是否有任何原因安装可能无法正常工作?或者将模块包含在我自己的项目中的最佳方法是什么?
安装是否有任何原因可能不起作用?或者将模块包含在我自己的项目中的最佳方法是什么?
ciscoconfparse 1.1.1 版在所有 Python3 版本中都失败,因为相对导入损坏.
由于在 PEP 366 中不合规,相对导入中断了code>ciscoconfparse 1.1.1 版(及之前);为了解决这个问题,ciscoconfparse 在包中添加了一个 __main__.py
.我对 Python2.7 和 Python3.4.1 进行了手动测试;据我所知,1.1.2 版修复了 Python3 的问题.
I'm trying to install a python module called ciscoconfparse on Linux Mint 17. When I install it with pip with python 2, all works well when I try to import, but when I try it with pip3 (for Python 3.4), the module shows up in the install directory, but I can't import any parts of it.
I can find the module here
/usr/local/lib/python3.4/dist-packages/ciscoconfparse-1.1.1-py3.4.egg/ciscoconfparse
Inside this directory is the ciscoconfparse.py file, which has the CiscoConfParse class, but I can't import it with
from ciscoconfparse import CiscoConfParse
When I try to install, it looks like there is a few problems, but still says it has sucessfuly installed.
~/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...
On the authors site, he says that it has been tested to work on Python > 3.2. I'm using Pycharm as an ide. So far it seems like I can either use a virtual environment with python3 and see if that changes anything, or I can drop the module into the module I'm making. Is there any reason the install may not be working? Or else what is the best way to include the module with my own project?
Is there any reason the install may not be working? Or else what is the best way to include the module with my own project?
ciscoconfparse version 1.1.1 failed in all Python3 versions due to broken relative imports.
Relative imports broke due to lack of compliance with PEP 366 in ciscoconfparse
version 1.1.1 (and prior); to resolve this, ciscoconfparse added a __main__.py
in the package. I manually tested this against Python2.7 and Python3.4.1; as far as I can tell, version 1.1.2 fixes the issues with Python3.
这篇关于Python 3.4 模块中的 ciscoconfparse 无法正确导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!