简体   繁体   English

无法使用PyCharm导入模块,为什么?

[英]Cannot import module with PyCharm, why?

PyCharm 2018.1.3 pro / Python 3.6.1 / Module: neo4j-driver 1.5.3 PyCharm 2018.1.3 Pro / Python 3.6.1 /模块:neo4j-driver 1.5.3

The strange thing is that if I trying to import neo4j.v1 using script editor in PyCharm and run it I'm getting error: 奇怪的是,如果我尝试在PyCharm中使用脚本编辑器导入neo4j.v1并运行它,则会出现错误:

Traceback (most recent call last): File "C:/experiment/Cypher.py", line 1, in from neo4j.v1 import GraphDatabase ModuleNotFoundError: No module named 'neo4j' Process finished with exit code 1 追溯(最近一次调用):文件“ C:/experiment/Cypher.py”,行1, 来自neo4j.v1 import GraphDatabase ModuleNotFoundError: 没有名为'neo4j'的模块的进程以退出代码1结束

But this script works just fine if I call it using Windows PowerShell environment using simple command prompt: 但是,如果我使用Windows PowerShell环境通过简单的命令提示符调用此脚本,则该脚本可以正常工作:

> python C:/experiment/Cypher.py

So, I think that something is wrong with settings or with PyCharm. 因此,我认为设置或PyCharm有问题。 What should I do to solve this problem? 我该怎么做才能解决这个问题?

From pycharm, 从pycharm,

goto settings -> project Interpreter 转到settings -> project Interpreter

Click on + button on top right corner and you will get pop-up window of Available packages. 单击右上角的+按钮,您将弹出“可用软件包”的弹出窗口。 Then search for neo4j python package. 然后搜索neo4j python软件包。

Then click on Install package to install the package. 然后单击“安装软件包”以安装软件包。

neo4j.v1 is not a default python module, it is not automatically installed when you install python. neo4j.v1不是默认的python模块,在安装python时不会自动安装。

To install neo4j.v1 Follow the instructions here . 要安装neo4j.v1按照此处的说明进行操作。

Its possible to install it directly from pycharm, as other answers have pointed out, but its better to download from the official source to make sure all related dependencies and packages are properly installed. 如其他答案所指出的,可以直接从pycharm安装它,但最好从官方来源下载以确保所有相关的依赖项和软件包都已正确安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM