Nice programing

Windows 10에서 Python 설치를 어떻게 업그레이드합니까?

nicepro 2020. 11. 28. 12:27
반응형

Windows 10에서 Python 설치를 어떻게 업그레이드합니까?


내 LAB 스테이션 중 하나에 Python 2.7.11이 설치되어 있습니다. Python을 3.5 이상으로 업그레이드하고 싶습니다.

어떻게해야합니까? 2.7.11을 완전히 제거하고 새 버전을 설치하는 것을 선호해야합니까? 그것을 업데이트하는 방법이 있습니까? 업데이트가 좋은 생각입니까?


3.x 및 2.x 버전 인 모든 Python 부 버전은 컴퓨터에 다른 버전과 나란히 설치됩니다. 패치 버전 만 기존 설치를 업그레이드합니다.

따라서 설치된 Python 2.7을 유지하려면 설치 프로그램을 사용하여 새 버전을 설치하십시오. Python 2.7을 제거하려는 경우 새 버전을 설치하기 전이나 후에 제거 할 수 있습니다.이 경우에는 차이가 없습니다.

현재 Python 3 설치 py.exe에는 기본적으로 시스템 디렉토리에 설치되는 런처 가 함께 제공됩니다. 이렇게하면 PATH에서 사용할 수 있으므로 명령 py대신 사용하여 모든 쉘에서 자동으로 실행할 수 있습니다 python. 이렇게하면 현재 Python 설치를 PATH에 직접 넣을 필요가 없습니다. 이렇게하면 서로 간섭하지 않고 여러 Python 설치를 나란히 쉽게 설치할 수 있습니다. 실행할 때 런처를 사용하는 py script.py대신 python script.py사용하십시오. 예를 들어 py -3또는 py -3.6특정 버전을 실행하기 위해 버전을 지정할 수도 있습니다 . 그렇지 않으면 실행기가 현재 기본값 (일반적으로 최신 3.x)을 사용합니다.

Python 2.7 설치를 유지하기로 결정한 경우 런처를 사용하여 Python 2 스크립트 (종종 Python 3과 구문이 호환되지 않음)를 실행할 수도 있습니다. 그냥 사용 py -2 script.py하는 스크립트를 실행합니다.


PyPI 패키지의 경우 모든 Python 설치에는 모듈이 설치된 자체 폴더가 있습니다. 따라서 새 버전을 설치하고 이전 버전 용으로 설치 한 모듈을 사용하려면 먼저 새 버전 용으로 설치해야합니다. 현재 버전의 설치 프로그램도 설치할 수 있습니다 pip. 기본적으로 활성화되어 있으므로 이미 pip모든 설치에 대해 사용하고 있습니다. Python 설치를 PATH에 명시 적으로 추가하지 않으면 사용할 수 없습니다 pip. 운 좋게도 py.exe런처를 사용하여 간단히 실행할 수도 있습니다 : py -m pipruns pip. 예를 들어 Python 3.6 용 Beautiful Soup을 설치하려면 py -3.6 -m pip install beautifulsoup4.


Chocolatey Windows 패키지 관리자를 사용하여 Python 설치 / 업그레이드

Python 2.7.16이 있다고 가정 해 보겠습니다.

    C:\Windows\system32>python --version
    python2 2.7.16

... (현재 현재) 3.xy 버전으로 업그레이드하려고합니다. Windows 패키지 관리 도구를 사용하여 Python 3.xy 병렬 설치 를 설치하는 간단한 방법이 있습니다 .

이제 최신 Windows에는 패키지 관리 기능이 있습니다. 마치 Debian Linux 배포판에는 apt-get이 있고 RedHat에는 dnf가 있습니다. 우리를 위해 사용할 수 있습니다! Chocolatey 라고 합니다.

Chocolatey는 무엇입니까?

Chocolatey는 .NET 4.0 및 Visual Studio에 구워진 nuget 패키지 관리자를 기반으로하는 스크립트 가능한 명령 줄 도구입니다.

Chocolatey에 대해 알아보고이를 사용하는 이유를 알고 싶다면 여기에서이 글을 읽고 특히 유용 할 수 있습니다. https://chocolatey.org/docs/why

Chocolatey 설치

Chocolatey 패키지 관리자를 얻으려면, 당신은에서 설명하는 과정에 따라 https://chocolatey.org/docs/installation#installing-chocolatey을 ,

여기에 요약하겠습니다. 기본적으로 cmd 프롬프트 사용 또는 PowerShell 프롬프트 사용의 두 가지 옵션이 있습니다.

CMD 프롬프트 초콜릿 설치

관리 명령 프롬프트를 시작 합니다. Windows 10에서이를 수행하려면 다음을 수행하십시오.

  • Windows+R
  • 유형 cmd를
  • ctrl+ shift+ 누르기Enter

시스템에 대한 관리자 권한이없는 경우 Chocolatey 웹 사이트 로 이동하십시오 . 완전히 운이 좋지 않고 제한된 로컬 설치를 수행 할 수는 있지만 여기서는 다루지 않겠습니다.

  • 아래 문자열을 명령 프롬프트에 복사하고 Enter를 입력합니다.
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Chocolatey는 아래와 같이 다운로드 및 설치됩니다.

Getting latest version of the Chocolatey package for download.
Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.11.
Downloading 7-Zip commandline tool prior to extraction.
Extracting C:\Users\blahblahblah\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\blahblahblah\AppData\Local\Temp\chocolatey\chocInstall...
Installing chocolatey on this machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
  Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
  before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
  (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
  and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey folders if they do not already exist.

WARNING: You can safely ignore errors related to missing log files when
  upgrading from a version of Chocolatey less than 0.9.9.
  'Batch file could not be found' is also safe to ignore.
  'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
WARNING: Not setting tab completion: Profile file does not exist at 'C:\Users\blahblahblah\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
 first prior to using choco.
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder

어느 종료 CMD를 프롬프트 또는 환경 변수를 다시로드하려면 다음 명령을 입력합니다 :

refreshenv

PowerShell Chocolatey 설치

cmd 프롬프트보다 PowerShell을 선호하는 경우 여기에서 직접이 작업을 수행 할 수 있지만 제대로 작동하려면 적절한 스크립트 실행 정책으로 실행하도록 PowerShell에 지시해야합니다. Windows 10에서이 작업을 수행하는 가장 간단한 방법은 Windows 버튼 옆에있는 Cortana 검색 창에 다음을 입력하는 것입니다.

PowerShell.exe

다음으로 팝업 메뉴에서 '최적 일치'항목을 마우스 오른쪽 버튼으로 클릭하고 '관리자 권한으로 실행'을 선택하십시오.

이제 PowerShell에서 관리자 권한으로 실행 중이므로 다음을 실행하여 Chocolatey를 설치합니다.

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

PowerShell은 Chocolatey를 다운로드하고 설치를 시작합니다. 몇 분 밖에 걸리지 않습니다. 그것은 보이는 정확히 아마도 몇 가지 화려한 컬러 텍스트 저장, CMD를 설치처럼.

어느 종료 PowerShell을하거나 환경 변수를 다시로드하려면 다음 명령을 입력합니다 :

refreshenv

Python 업그레이드

choco 명령은 PowerShell을 사용하든 cmd 프롬프트를 사용하든 동일합니다. 위의 지침을 사용하여 즐겨 찾기를 시작하십시오. 관리자 cmd 프롬프트를 사용하겠습니다.

C:\WINDOWS\system32>choco upgrade python -y

기본적으로 chocolatey는 2.7.x에서 왔고 2.7 버전을 완전히 별개 로 취급하므로 "Hey, Python이 설치되지 않았습니다"라고 알려줍니다 . 입니다 , 당신에게 3.xy를 최신 버전을 줄 것 (이 글을 쓰는, 3.7.2의로,하지만 몇 달이 변경됩니다)

Chocolatey v0.10.11
Upgrading the following packages:
python
By upgrading you accept licenses for the packages.
python is not installed. Installing...

python3 v3.x.y [Approved]
python3 package files upgrade completed. Performing other installation steps.
Installing 64-bit python3...
python3 has been installed.
Installed to: 'C:\Python37' 
  python3 can be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The upgrade of python3 was successful.
  Software installed as 'exe', install location is likely default.

python v3.x.y [Approved]
python package files upgrade completed. Performing other installation steps.
 The upgrade of python was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey upgraded 2/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

어느 --version / 파워 쉘이 프롬프트를 다시 입력하거나 사용 refreshenv 다음 평 입력 cmd를을 종료

C:\Windows\System32>refreshenv
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..

C:\Windows\system32>py --version
Python 3.7.2

명령 줄에 Python을 입력하면 최신 Python 설치가 이제 인계됩니다. 다음 명령을 사용하여 두 버전 중 하나를 실행할 수 있습니다.

py -2
Python 2.7.16 (v2.7.16:413a49145e, Mar  4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

C:\>py -3
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>exit()
C:\>

From here I suggest you use the Python pip utility to install whatever packages you need. For example, let's say you wanted to install Flask. The commands below first upgrade pip, then install Flask

C:\>py -3 -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 1.6MB/s
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.0.3

c:\>py -3 -m pip install Flask

...will do the trick. Happy Pythoning!


Python 2.x and Python 3.x are different. If you would like to download a newer version of Python 2, you could just download and install the newer version.

If you want to install Python 3, you could install Python 3 separately then change the path for Python 2.x to Python 3.x in Control Panel > All Control Panel Items > System > Advanced System Settings > Environment Variables.


If you are upgrading any 3.x Python version, just go to Python downloads page get the latest version and start the installation. Since you already have Python installed on your machine installer will prompt you for "Upgrade Now". Click on that button and it will replace the existing version with a new one. You also will have to restart a computer after installation.

enter image description here


In 2019, you can install using chocolatey. Open your cmd or powershell, type "choco install python".


You can use pip to upgrade a package. It is super easy and recommended too.

pip install python --upgrade OR pip install python -U

You dont need to uninstall python27. Just set the path of whatever version you like to use as a primary one and use it. Ref : Click here

Sure upgrade is a good idea if you're in the learning phase.

참고URL : https://stackoverflow.com/questions/45137395/how-do-i-upgrade-the-python-installation-in-windows-10

반응형