[英]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-installation.
如果您没有上面示例中的“python-launcher”,但您的 python 解释器有不同的别名,那么您可以以相同的方式发出相同的命令,只需使用您的别名。
这里有几个例子:
# 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
发出其他命令,因此,如果您想为特定版本安装 package ,您可以执行以下操作:
# 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 并按 Enter,然后在 Python36 上键入您的版本...确保在名称上使用大写字母Python,脚本...我遇到了同样的问题,我安装了 python27 版本。
python -m pip install --upgrade pip setuptools wheel
Worked for me
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.