Program Tip

동일한 컴퓨터에 여러 Python 버전이 있습니까?

programtip 2020. 11. 8. 10:54
반응형

동일한 컴퓨터에 여러 Python 버전이 있습니까?


Linux에서 동일한 컴퓨터에 여러 버전의 Python을 설치하고 실행하는 방법에 대한 Python 웹 사이트 어딘가에 공식 문서가 있습니까?

수많은 블로그 게시물과 답변을 찾을 수 있지만이를 수행하는 "표준"공식 방법이 있는지 알고 싶습니다.

아니면이 모든 것이 OS에 의존합니까?


완전히 독립적이라고 생각합니다. 설치하기 만하면 다음 /usr/bin/python2.5같은 명령이 있습니다 /usr/bin/python2.6. /usr/bin/python기본값으로 사용하려는 항목에 연결 하십시오.

어쨌든 모든 라이브러리는 별도의 폴더 (버전 이름을 따서 명명 됨)에 있습니다.

버전을 수동으로 컴파일하려면 Python 소스 코드의 readme 파일에서 가져온 것입니다.

여러 버전 설치

Unix 및 Mac 시스템에서 동일한 설치 접두사 (구성 스크립트에 대한 --prefix 인수)를 사용하여 여러 버전의 Python을 설치하려는 경우 다른 버전을 설치해도 기본 Python 실행 파일을 덮어 쓰지 않도록주의해야합니다. "make altinstall"을 사용하여 설치된 모든 파일 및 디렉토리에는 주 버전과 부 버전이 포함되어 있으므로 함께 사용할 수 있습니다. "make install"은 $ {prefix} /bin/pythonX.Y를 참조하는 $ {prefix} / bin / python3도 만듭니다. 동일한 접두사를 사용하여 여러 버전을 설치하려는 경우 어떤 버전 (있는 경우)이 "기본"버전인지 결정해야합니다. "make install"을 사용하여 해당 버전을 설치하십시오. "make altinstall"을 사용하여 다른 모든 버전을 설치하십시오.

예를 들어, 2.6이 기본 버전 인 Python 2.5, 2.6 및 3.0을 설치하려면 2.6 빌드 디렉토리에서 "make install"을 실행하고 다른 디렉토리에서 "make altinstall"을 실행합니다.


Windows에서는 "C : \ python26"및 "C : \ python31"이라는 별도의 폴더에 설치되지만 실행 파일은 동일한 "python.exe"이름을 갖습니다.

"python26"및 "python31"에 대한 래퍼 역할을하는 "python.bat"및 "python3.bat"를 포함하는 또 다른 "C : \ python"폴더를 만들고 PATH환경 변수 에 "C : \ python"을 추가했습니다 .

이렇게하면 .bat Python 래퍼 를 입력 python하거나 python3원하는 래퍼를 시작할 수 있습니다.

Linux에서는 #!트릭을 사용하여 스크립트에서 사용할 버전을 지정할 수 있습니다.


다른 Python 버전을 설치하는 방법은 실제로 OS에 따라 다릅니다.

그러나 Linux를 사용하는 경우 pythonbrew 또는 pythonz 와 같은 도구를 사용하여 다른 버전을 쉽게 관리하고 전환 할 수 있습니다.


업데이트 2019 : 사용 asdf

요즘에는 asdf사용하여 다양한 버전의 Python 인터프리터를 나란히 설치할 것을 제안 합니다.

참고 1 : asdfPython뿐만 아니라 모든 주요 언어에서 작동합니다.

참고 2 : pipenvpoetryasdf 와 같은 인기있는 패키지 관리자와 함께 사용하면 잘 작동합니다 .

당신이있는 경우 asdf을 설치 하면 쉽게 다운로드 / 새로운 파이썬 인터프리터를 설치할 수 있습니다 :

# Install Python plugin for asdf:
asdf plugin-add python

# List all available Python interpreters:
asdf list-all python

# Install the Python interpreters that you need:
asdf install python 3.7.4
asdf install python 3.6.9
# etc...

# If you want to define the global version:
asdf global python 3.7.4

# If you want to define the local (project) version:
# (this creates a file .tool-versions in the current directory.)
asdf local python 3.7.4

이전 답변 : 소스에서 Python 설치

Ubuntu / Mint 에 여러 버전의 Python (기본 버전 옆에 있음)을 설치해야하는 경우 : (다른 Unix에서도 유사하게 작동해야합니다.)

1) 소스 컴파일에 필요한 패키지 설치

$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

2) 원하는 Python 버전 다운로드 및 추출

Linux 용 Python 소스를 tarball로 다운로드 하고 /usr/src.

다운로드 한 패키지를 제자리에 추출하십시오. ( 'x'를 다운로드 한 버전으로 대체)

$ sudo tar xzf Python-x.x.x.tgz

3) Python 소스 컴파일 및 설치

$ cd Python-x.x.x
$ sudo ./configure
$ sudo make altinstall

이제 새 Python 저장소가 /usr/local/bin. 새 버전을 테스트 할 수 있습니다.

$ pythonX.X -V
Python x.x.x
$ which pythonX.X
/usr/local/bin/pythonX.X

# Pip is now available for this version as well:
$ pipX.X -V
pip X.X.X from /usr/local/lib/pythonX.X/site-packages (python X.X)

나를 위해 일한 가장 좋은 방법은 pyenv를 사용하는 것입니다!

The commands below are for Mac but pretty similar to Linux (see the links below)

#Install pyenv
brew update
brew install pyenv

Let's say you have python 3.6 as your primary version on your mac:

python --version 

Output:

Python 3.6.4

Now Install python 3.7, first list all

pyenv install -l

Let's take 3.7.3:

pyenv install 3.7.3

Now let's run only on the opened terminal/shell:

pyenv shell 3.7.3

Now run

python --version

Output:

Python 3.7.3

Unset:

pyenv shell --unset

You can run it globally or locally as well


It's most strongly dependent on the package distribution system you use. For example, with MacPorts, you can install multiple Python packages and use the pyselect utility to switch the default between them with ease. At all times, you're able to call the different Python interpreters by providing the full path, and you're able to link against all the Python libraries and headers by providing the full paths for those.

So basically, whatever way you install the versions, as long as you keep your installations separate, you'll able to run them separately.


I did this with anaconda navigator. I installed anaconda navigator and created two different development environments with different python versions

and switch between different python versions by switching or activating and deactivating environments.

first install anaconda navigator and then create environments.

see help here on how to manage environments

https://docs.anaconda.com/anaconda/navigator/tutorials/manage-environments/

Here is the video to do it with conda

https://youtu.be/EGaw6VXV3GI

참고URL : https://stackoverflow.com/questions/2547554/multiple-python-versions-on-the-same-machine

반응형