gpt4 book ai didi

python - 无法使用pip3模块: ModuleNotFoundError

转载 作者:行者123 更新时间:2023-12-01 00:57:41 31 4
gpt4 key购买 nike

我利用自制程序安装 python3,现在无法运行使用关联的 pip3 二进制文件安装的模块。

from blackduck.HubRestApi import HubInstance
username = "sysadmin"
password = "your-password"
urlbase = "https://ec2-34-201-23-208.compute-1.amazonaws.com"
hub = HubInstance(urlbase, username, password, insecure=True)

运行python3 blackduck.py 结果:

ModuleNotFoundError: No module named 'blackduck.HubRestApi'; 'blackduck' is not a package

包裹证明:

$pip3 install blackduck                                                                                                                                    
Requirement already satisfied: blackduck in /usr/local/lib/python3.7/site-packages (0.0.25)
Requirement already satisfied: requests in /usr/local/lib/python3.7/site-packages (from blackduck) (2.21.0)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (2019.3.9)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (1.24.3)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (3.0.4)

help('modules') -> 包含 blackduck

$pip3 list | grep blackduck          
blackduck 0.0.25

我尝试过创建虚拟环境,但没有成功。我还尝试将 /usr/local/lib/python3.7/site-packages 添加到我的 $PYTHONPATH 环境变量中。提前致谢!

最佳答案

不要将您自己的 Python 脚本与 Python 模块或包一样调用 - 它会自行启动!

来自the search-path documentation :

When a module named spam is imported, the interpreter first searchesfor a built-in module with that name. If not found, it then searchesfor a file named spam.py in a list of directories given by thevariable sys.path. sys.path is initialized from these locations:

The directory containing the input script (or the current directorywhen no file is specified).

PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).

The installation-dependent default.

因此,在所有条件相同的情况下,首先搜索当前目录。

将其命名为其他名称,例如 my_blackduck.py。我建议您对开发脚本使用自行开发的前缀,可能是项目代码,后跟下划线之类的内容,这样您就不会重复出现问题。

关于python - 无法使用pip3模块: ModuleNotFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56117002/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com