"Reprint" Registry issues after Windows installation python2.7

Source: Internet
Author: User

Source: https://www.cnblogs.com/tlz888/p/6879227.html

"Feed" on the win platform, the python2.7 official website installation package will not add environment variables after installation and will not write the installation information to the registry.

Adding Python and Pip installation paths to environment variables is a necessary step for Python development, and the reason for writing to the registry is that some Python packages

Windows Installer is installed in the form of Python registry information, such as NumPy, scipy.

Installation steps:

(1) Download the installation package to Python website, www.python.org/downloads, run the installation;

(2) Add the path of the Python.exe (Python installation path) and the Pip.exe path (the script file under the Python installation path) to the PATH environment variable.

For example, my python is here: "C:\Python27", then add the path: "C:\Python27" and "C:\Python27\Scripts" to the PATH environment variable;

(3) Add Python registration information to the registry for Python to operate the Windows registry, and you can run Python files to complete this step.

The following is the Python source code, copy it out, put it anywhere and run it with Python.

ImportSYS from_winregImport*#tweak as necessaryVersion = 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)defRegisterpy ():Print "begin Registerpy"    Try:        Print "Open key:%s"%Regpath Reg=Openkey (HKEY_CURRENT_USER, Regpath)exceptEnvironmentError 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 "* * * except:unable to register!"             return                             Print "---Python", version,"is now registered!"         return       if(QueryValue (Reg, installkey) = = InstallPath andQueryValue (Reg, Pythonkey)==Pythonpath): Closekey (REG)Print "= = = Python", version,"is already registered!"             returnClosekey (REG)Print "* * * error:unable to register!"     Print "* * * reason:you probably have another Python installation!"defUnregisterpy ():#print "Begin Unregisterpy"    Try:        Print "Open HKEY_CURRENT_USER key=%s"%(Regpath) Reg=Openkey (HKEY_CURRENT_USER, Regpath)#reg = Openkey (HKEY_LOCAL_MACHINE, Regpath)    exceptEnvironmentError:Print "* * Python not registered?!"        return    Try: DeleteKey (Reg, Installkey) DeleteKey (Reg, Pythonkey) DeleteKey (HKEY_LOCAL_MACHINE, Regpath) except:       Print "* * * Unable to un-register!"    Else:       Print "---Python", version,"is no longer registered!"            if __name__=="__main__": Registerpy ()

As shown, the Pyhton 2.7 is now Registered! Word is registered successfully.

  

You can also see the corresponding information in the registry:

  

If the registry information is incorrect because of reasons such as installing and uninstalling multiple versions of Python, you can edit the registry manually and then reregister.

The method of manually adding registration information to the registry is consistent with the procedures in the Python code above.

"Reprint" Registry issues after Windows installation python2.7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.