我利用自制软件安装了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
env变量中。预先感谢!
答案 0 :(得分:2)
不要像调用python模块或包一样调用自己的python脚本-它会自行启动!
来自the search-path documentation:
导入名为垃圾邮件的模块时,解释器首先搜索 具有该名称的内置模块。如果找不到,则进行搜索 在目录给定的目录列表中查找名为spam.py的文件 变量sys.path。 sys.path从以下位置初始化:
包含输入脚本的目录(或当前目录) 当未指定文件时。)
PYTHONPATH(目录名称列表,语法与shell变量PATH相同)。
与安装有关的默认设置。
因此,在所有条件相同的情况下,首先搜索当前目录。
使用其他任何名称,例如my_blackduck.py
。我建议您为开发脚本使用本地的前缀(可能是项目代码,后跟下划线),以免重复出现此问题。