1

我正在尝试在我的机器上完成这项工作(arch,使用 gnome 3)。我认为设置正常(我替换了所有打印命令)但是当我chemlab在终端上运行时出现错误,告诉我没有核心包:

[yotam@Standing chemlab-master]$ chemlab
Traceback (most recent call last):
  File "/usr/bin/chemlab", line 5, in <module>
    pkg_resources.run_script('chemlab==0.2', 'chemlab')
  File "/usr/lib/python3.3/site-packages/pkg_resources.py", line 505, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3.3/site-packages/pkg_resources.py", line 1246, in run_script
    exec(compile(open(script_filename).read(), script_filename, 'exec'), namespace, namespace)
  File "/usr/lib/python3.3/site-packages/chemlab-0.2-py3.3-linux-i686.egg/EGG-INFO/scripts/chemlab", line 4, in <module>
    import chemlab as cl
  File "/usr/lib/python3.3/site-packages/chemlab-0.2-py3.3-linux-i686.egg/chemlab/__init__.py", line 1, in <module>
    from core.molecule import Molecule, Atom
ImportError: No module named 'core'
[yotam@Standing chemlab-master]$ ls /usr/lib/python3.3/site-packages/chemlab-0.2-py3.3-linux-i686.egg/chemlab/
__init__.py  contrib/     db/          io/          libs/        resources/   
__pycache__/ core/        graphics/    ipython.py   molsim/      utils/       
[yotam@Standing chemlab-master]$ ls /usr/lib/python3.3/site-packages/chemlab-0.2-py3.3-linux-i686.egg/chemlab/

所以我尝试在本地运行文件。我去了相应的文件夹并运行python __init__.pyNo I get

[yotam@Standing chemlab]$ python __init__.py
Traceback (most recent call last):
  File "__init__.py", line 1, in <module>
    from core.molecule import Molecule, Atom
  File "/home/yotam/Applications/Chemlab/chemlab-master/chemlab/core/__init__.py", line 1, in <module>
    from .molecule import Molecule, Atom
  File "/home/yotam/Applications/Chemlab/chemlab-master/chemlab/core/molecule.py", line 6, in <module>
    from ..libs.ckdtree import cKDTree
ValueError: attempted relative import beyond top-level package
[yotam@Standing chemlab]$ 

我搜索了一下,发现我可以(应该?)替换..libs.ckdtree import cKDTreechemlab.libs.ckdtree import cKDTree我这样做只是为了得到

Traceback(最近一次调用最后一次):文件“”,第 1 行,在文件“./core/init .py ”中,第 1 行,在 from .molecule import Molecule,Atom 文件“./core/molecule.py”中,行6、在 from chemlab.libs.ckdtree import cKDTree File "/usr/lib/python3.3/site-packages/chemlab-0.2-py3.3-linux-i686.egg/chemlab/init .py ",第1行, in from core.molecule import Molecule, Atom ImportError: cannot import name Molecule

这让我很困惑。我怎样才能导入/运行它?

编辑:文件夹结构:

chemlab
|
|
+  __init__.py
+  core
   |
   |
   +  molecule.py

编辑 2: chemlab/__init__.py只有一行来自 core.molecule import Molecule, Atom

和 chelab/core/molecule/ 导入部分看起来像

import numpy as np
from collections import Counter
import numpy as np
from copy import copy

from ..libs.ckdtree import cKDTree
from ..db import ChemlabDB
cdb = ChemlabDB()

masses = cdb.get("data", "massdict")

from .attributes import MArrayAttr, MField
from .fields import AtomicField, FieldRequired
from .serialization import data_to_json, json_to_data
4

1 回答 1

0

你有一个循环依赖。但这是由于您chemlab.__init__.py想要 import引起的core.molecule.Molecule,它不应该尝试这样做。删除该导入行。

于 2013-05-20T12:12:17.263 回答