pywin32找不到python的解决方法

发布时间:2020-09-02 09:43:43 作者:小新
来源:亿速云 阅读:286

这篇文章主要介绍pywin32找不到python的解决方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1、检查一下注册表是否存在python其它版本的信息

方法:

(1)在命令行中输入regedit打开注册表

(2)在HKEY_CURRENT_USER\Software中找一下是否存在python注册信息,如果存在,检查一下是否是python27版本,且是否包含下面两个节点。

再检查一下其对于的安装路径是否正确。如果不知道如何检查,可以把python节点信息右击选择删除。如果python注册信息不存在,这里就不用操作了。

2、新建register.py文件,复制如下代码保存在D盘根目录下,cmd命令行运行 python register.py,当输出“python 2.7 is already registered”就ok了。

(python27使用正常,无需修改任何内容)

#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/ 
msg10512.html
 
import sys
from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
 
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
    installpath, installpath, installpath
)

def RegisterPy():
    try:
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:
        try:
            reg = CreateKey(HKEY_CURRENT_USER, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print "*** Unable to register!"
            return
        print "--- Python", version, "is now registered!"
        return
    if (QueryValue(reg, installkey) == installpath and
            QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print "=== Python", version, "is already registered!"
        return
    CloseKey(reg)
    print "*** Unable to register!"
    print "*** You probably have another Python installation!" 

if __name__ == "__main__":
    RegisterPy()

3、执行后再检查一下注册表。python27的注册信息已经存在了。

4、再次安装pywin32-220.win32-py2.7.exe,结果安装成功。

以上是pywin32找不到python的解决方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. 在python虚拟环境中安装pywin32
  2. 安装PyWin32

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pywin32 python 找不

上一篇:python导入模块时报错的解决方法

下一篇:python加法程序的写法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》