我在导入 PyDictionary 库时遇到问题

I am having a trouble importing the PyDictionary library

基本上,我使用 pip install PyDictionary 下载了这个库,我通过再次编写相同的东西来确保它存在并且出现了:

Requirement already satisfied: PyDictionary in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (2.0.1)
Requirement already satisfied: bs4 in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from PyDictionary) (0.0.1)
Requirement already satisfied: goslate in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from PyDictionary) (1.5.1)
Requirement already satisfied: requests in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from PyDictionary) (2.25.1)
Requirement already satisfied: click in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from PyDictionary) (7.1.2)
Requirement already satisfied: beautifulsoup4 in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from bs4->PyDictionary) (4.9.3)
Requirement already satisfied: soupsieve>1.2 in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from beautifulsoup4->bs4->PyDictionary) (2.2.1)
Requirement already satisfied: futures in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from goslate->PyDictionary) (3.1.1)
Requirement already satisfied: idna<3,>=2.5 in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from requests->PyDictionary) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from requests->PyDictionary) (1.26.4)
Requirement already satisfied: chardet<5,>=3.0.2 in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from requests->PyDictionary) (4.0.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\ziad\appdata\local\programs\python\python39\lib\site-packages (from requests->PyDictionary) (2020.12.5)

然而,当我尝试在 atom 中 运行 这个简单的程序时,它说找不到模块。 这是程序:

from PyDictionary import PyDictionary
dictionary = PyDictionary()

print (dictionary.meaning("indentation"))

这是错误:

Traceback (most recent call last):
  File "C:\Users\Ziad\Desktop\programs\Dictionary.py", line 1, in <module>
    from PyDictionary import PyDictionary
ModuleNotFoundError: No module named 'PyDictionary'

我发现正确执行程序的唯一方法是将文件移动到库所在的文件夹,以便 atom 可以找到库。奇怪的是图书馆 numpy 工作得很好。 我真的很想知道这个问题的答案。

您遇到的问题是您的 pip 命令未连接到您安装的 python3

如果您正在使用 Windows,那么您应该有一个“python 启动器”,您可以使用它来仔细检查您安装的 Python 版本,如下所示:

PS C:\> py -0
Installed Pythons found by C:\windows\py.exe Launcher for Windows
 -3.9-64 *
 -3.7-32

在这里你可以看到我的设备上安装了两个版本的Python。那么,让我们使用它们自己的 pip.

版本检查这两个安装都安装了什么

让我们从我的 3.7 安装开始:

PS C:\> py -3.7 -m pip list
Package            Version
------------------ ---------
beautifulsoup4     4.8.1
Jinja2             2.11.2
keyring            21.2.0

这里可以看到我安装了三个包

现在让我们检查一下我的 3.9 安装:

PS C:\> py -3.9 -m pip list
Package                          Version
-------------------------------- ---------
matplotlib                       3.4.1
numpy                            1.19.4
pandas                           1.1.5
pip                              21.0.1

我在上面所做的基本上是调用不同的 python 安装,并使用以下标志打开它:

-m mod : run library module as a script (terminates option list)

pip 命令基本上只是 <python-installation> -m pip 的别名,所以当我发出上述命令时,我启动了 pip 和特定的 python-安装.


如果您没有上述示例中的“python-launcher”,但您的 python-interpreter 有不同的别名,那么您可以发出相同的命令以同样的方式,只需使用您的别名。

这里有几个例子:

# will show you the installed packages for the alias "python2"
python2 -m pip list

# will show you the installed packages for the alias "python3"
python3 -m pip list

你显然可以使用相同的逻辑向 pip 发出其他命令,所以如果你想安装特定版本的包,你可以这样做:

# will try to install the given package for the alias "python3"
python3 -m pip install <nameOfPackage>

输入这个

python -m pip install --upgrade pip setuptools wheel

确保包含空格。 那么:

C:/Python36/Scripts/pip install Pydictionary

备注: 您正在为特定 python 版本安装 PyDictionary 以查看您在终端上安装的 python 版本,键入 py 并按回车 然后在 Python36 上输入你的版本...确保你在名称 Python 上使用大写字母,脚本...我遇到了同样的问题,我安装了 python27 版本.