Skip to main content
 首页 » 编程设计

来自pypi的python模块没有安装

2025年04月02日19qlqwjy

我正在使用 windows 机器 python 2.7。我正在尝试将十六进制转换为颜色名称。我已经从 pypi 下载了 webcolors 1.5,当我使用 cmd 安装它时

python d:\webcolors-1.5\setup.py install 

我越来越像

setup.pyrunning install 
running build 
running build_py 
file webcolors.py (for module webcolors) not found 
file webcolors.py (for module webcolors) not found 
running install_lib 
warning: install_lib: 'build\lib' does not exist -- no Python modules to install 
running install_egg_info 
Removing C:\Python27\Lib\site-packages\webcolors-1.5-py2.7.egg-info 
Writing C:\Python27\Lib\site-packages\webcolors-1.5-py2.7.egg-info 

当我运行 import webcolors 时,它显示没有模块错误。如何正确安装这个包?是那个“webcolors”包的问题吗?

编辑 当我安装时使用

pip install webcolors 

我得到了

Requirement already satisfied (use --upgrade to upgrade): webcolors in c:\python27\lib\site-packages 

但是还是显示没有模块错误

编辑 我的代码

import cv2 
from collections import namedtuple 
from math import sqrt 
import random 
import webcolors 
 
def main(): 
 img = cv2.imread('d:/Emmanu/project-data/bu5.jpg') 
 res=cv2.resize(img,(400,300)) 
 crop_img = res[100:200, 150:250] 
 cv2.imwrite("d:/Emmanu/project-data/color-test.jpg", crop_img) 
 
 im = Image.open("d:/Emmanu/project-data/color-test.jpg") 
 n, color = max(im.getcolors(im.size[0]*im.size[1])) 
 print rgb_to_name(color) 
if __name__ == '__main__':main() 

请您参考如下方法:

我使用了 pip 命令并安装了 webcolors。

pip install webcolors 


我可以导入