리눅스에서 두 가지 버전의 파이썬. 2.7을 기본값으로 만드는 방법
내 linuxbox에 두 가지 버전의 파이썬이 있습니다.
$python
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ /usr/local/bin/python2.7
Python 2.7.3 (default, Oct 8 2013, 15:53:09)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ which python
/usr/bin/python
$ ls -al /usr/bin/python
-rwxr-xr-x. 2 root root 4864 Jul 10 22:49 /usr/bin/python
2.7을 기본 버전으로 만들면 어떻게 2.7을 입력 python
할 수 있습니까?
실제로 기본 파이썬을 변경하고 싶지 않을 것입니다.
당신의 배포판은에 표준 시스템 파이썬을 설치했고 /usr/bin
, 이것에 의존하고에 의해 선택된 스크립트를 가지고있을 수 있습니다 #! /usr/bin/env python
. 일반적으로 2.7에서 Python 2.6 스크립트를 실행하여 벗어날 수 있지만 위험을 감수하고 싶습니까?
게다가, Monkeying with를 사용 /usr/bin
하면 패키지 관리자의 패키지 관리 기능이 손상 될 수 있습니다. 그리고 디렉토리의 순서를 변경하면 PATH
파이썬 외에 다른 많은 것들에 영향을 미칩니다. (실제로 /usr/local/bin
앞서 나가는 것이 더 일반적 /usr/bin
이며 실제로 원하는 것일 수도 있지만, 다른 방법이 있다면 그만한 이유가있을 것입니다.)
그러나 입력 할 때 시스템이 2.7을 실행하도록 기본 Python을 변경할 필요 는 없습니다 python
.
먼저, 쉘 별명을 설정할 수 있습니다 :
alias python=/usr/local/bin/python2.7
프롬프트에서 그를 입력하거나에 넣어 ~/.bashrc
당신은 변화가 지속 되길 원한다면, 때 지금 당신이 입력 python
그것은 당신이 2.7을 선택 실행되지만 시스템의 시도에 대한 몇 가지 프로그램이 스크립트를 실행할 때와 /usr/bin/env python
는 표준 2.6을 실행합니다.
또는 2.7 에서 가상 환경을 만들 거나 (다른 프로젝트에 대해 별도의 venv를) venv 내에서 작업을 수행하십시오.
추가 /usr/local/bin
귀하에게 PATH
이전의 목록에서 환경 변수 /usr/bin
.
일반적으로 이것은 쉘의 rc 파일에서 수행됩니다 (예 : bash의 경우) .bashrc
.
export PATH="/usr/local/bin:$PATH"
이렇게하면 쉘이 python
in /usr/local/bin
과 함께 가기 전에 먼저 in 을 찾습니다 /usr/bin
.
(물론, 이것은 또한 /usr/local/bin/python
지적 해야 함을 의미합니다 python2.7
-아직 그렇지 않은 경우 심볼릭 링크해야합니다.)
모든 OS는 기본 버전의 python과 함께 제공되며 / usr / bin에 있습니다. OS와 함께 제공되는 모든 스크립트 (예 : yum)는 / usr / bin에있는이 버전의 파이썬을 가리 킵니다. 새 버전의 python을 설치하려면 새 버전의 python에서 작동하지 않을 수있는 기존 스크립트를 중단하고 싶지 않습니다.
이를 수행하는 올바른 방법은 파이썬을 대체 버전으로 설치하는 것입니다.
e.g.
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --prefix=/usr/local/
make && make altinstall
이제이 작업을 수행하면 yum과 같은 기존 스크립트는 여전히 / usr / bin / python에서 작동합니다. 기본 파이썬 버전은 / usr / local / bin에 설치된 버전입니다. 즉, 파이썬을 입력하면 2.7.3이됩니다.
이 때문에 발생합니다. $ PATH 변수는 usr / bin 앞에 / usr / local / bin이 있습니다.
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
If python2.7 still does not take effect as the default python version you would need to do
export PATH="/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
Enter the command
which python
//output:
/usr/bin/python
cd /usr/bin
ls -l
Here you can see something like this
lrwxrwxrwx 1 root root 9 Mar 7 17:04 python -> python2.7
your default python2.7 is soft linked to the text 'python'
So remove the softlink python
sudo rm -r python
then retry the above command
ls -l
you can see the softlink is removed
-rwxr-xr-x 1 root root 3670448 Nov 12 20:01 python2.7
Then create a new softlink for python3.6
ln -s /usr/bin/python3.6 python
Then try the command python
in terminal
//output:
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type help
, copyright
, credits
or license
for more information.
Verify current version of python by:
$ python --version
then check python is symbolic link to which file.
$ ll /usr/bin/python
Output Ex:
lrwxrwxrwx 1 root root 9 Jun 16 2014 /usr/bin/python -> python2.7*
Check other available versions of python:
$ ls /usr/bin/python*
Output Ex:
/usr/bin/python /usr/bin/python2.7-config /usr/bin/python3.4 /usr/bin/python3.4m-config /usr/bin/python3.6m /usr/bin/python3m
/usr/bin/python2 /usr/bin/python2-config /usr/bin/python3.4-config /usr/bin/python3.6 /usr/bin/python3.6m-config /usr/bin/python3m-config
/usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.4m /usr/bin/python3.6-config /usr/bin/python3-config /usr/bin/python-config
If want to change current version of python to 3.6 version edit file ~/.bashrc:
vim ~/.bashrc
add below line in the end of file and save:
alias python=/usr/local/bin/python3.6
To install pip for python 3.6
$ sudo apt-get install python3.6 python3.6-dev
$ sudo curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python3.6
$ sudo easy_install pip
On Success, check current version of pip:
$ pip3 -V
Output Ex:
pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.6)
I guess you have installed the 2.7 version manually, while 2.6 comes from a package?
The simple answer is: uninstall python package.
The more complex one is: do not install manually in /usr/local. Build a package with 2.7 version and then upgrade.
Package handling depends on what distribution you use.
'Programing' 카테고리의 다른 글
전자 메일 HTML 코드를 만들기 위해 CSS 스타일을 자동으로 인라인하는 도구는 무엇입니까? (0) | 2020.07.10 |
---|---|
Visual Studio에서 .NET 4.5.2를 대상 프레임 워크로 선택하는 방법 (0) | 2020.07.10 |
git에서 병합 커밋의 부모를 얻는 방법은 무엇입니까? (0) | 2020.07.10 |
명명 된 파이프의 예 (0) | 2020.07.10 |
Django와 ReactJS를 함께 사용하는 방법? (0) | 2020.07.10 |