对于我的新手问题真的很抱歉。
我正在尝试在 python 中为 neo4j 安装模块,但出现错误。
这是导入:
from scripts.vis import vis_network
from scripts.vis import draw
这是错误:
ModuleNotFoundError: No module named 'scripts'
我尝试过“pip安装脚本”
提前致谢
ModuleNotFoundError
仅仅意味着Python解释器找不到该模块。我建议您阅读有关 python 模块和打包的内容here。
我已经查看了您指出的源代码,它工作得很好。我怀疑你的路径设置得不好。
确保在
scripts.vis
中运行导入 app.py
,目录结构如下所示:
./scripts
./scripts/__init__.py
./scripts/vis.py
....
./app.py #in app.py, you can import as 'from scripts.vis import x'
这是它在我的系统上的样子:
app.py
能够成功地从 vis
子模块导入。您可以使用 IPython 笔记本,它也应该可以正常工作。
如果您想在Python环境(Jupyter)中可视化图形,您可以尝试使用
neo4jupyter
库。在这里,您将使用 neo4jupyter.draw
来可视化图表。
安装
!pip install neo4jupyter
例如:
import neo4jupyter
neo4jupyter.init_notebook_mode()
from py2neo import Node
nicole = Node("Person", name="Nicole", age=24)
drew = Node("Person", name="Drew", age=20)
graph.create(nicole | drew)
options = {"Person": "name"}
neo4jupyter.draw(graph, options)
您可能会发现这很有用:
https://github.com/merqurio/neo4jupyter
https://nicolewhite.github.io/neo4j-jupyter/hello-world.html
我也收到模块错误:ModuleNotFoundError:没有名为“scripts”的模块
我的 mac 上有 pip3,就像我对其他软件包所做的那样 - 仍然是同样的错误。请帮忙