우분투에서 기본 Python 버전을 python3으로 설정할 수 없습니다.
나는에 설정된 기본 파이썬 버전으로 시도되었다 python3
에서 Ubuntu 16.04
. 기본적으로 python2
(2.7)입니다. 나는 아래 단계를 따랐다.
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3
하지만 두 번째 문에 대해 다음과 같은 오류가 발생합니다.
rejeesh@rejeesh-Vostro-1015:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs <link> <name> <path> <priority>
Use 'update-alternatives --help' for program usage information.
나는 우분투를 처음 접했고 내가 뭘 잘못하고 있는지 모르겠다.
.bashrc 파일을 엽니 다 nano ~/.bashrc
. alias python=python3
파일 맨 위에 새 줄을 입력 한 다음 ctrl + o로 파일을 저장하고 ctrl + x로 파일을 닫습니다. 그런 다음 명령 줄 유형으로 돌아갑니다 source ~/.bashrc
. 이제 별칭이 영구적이어야합니다.
편집하다:
업데이트 대안의 경우 우선 순위는 정수입니다. 우선 순위는 어떤 프로그램을 처음 사용해야하는지 나타냅니다. 이 기사는 모든 것을 아주 잘 요약합니다.
언급 된 두 번째 줄은 다음과 같이 변경할 수 있습니다.
update-alternatives --install /usr/bin/python python /usr/bin/python3 10
경로에 대해 우선 순위가 10입니다 python3
. .bashrc
파일 편집의 단점은 명령을 사용하는 동안에는 작동하지 않는다는 것입니다 sudo
.
python3으로 변경하려면 터미널에서 다음 명령을 사용할 수 있습니다 alias python=python3
.
간단하고 안전한 방법은 별칭을 사용하는 것입니다. 이것을 ~ / .bashrc 파일에 넣으십시오. gedit 편집기를 사용하는 경우
gedit ~ / .bashrc
bashrc 파일로 이동 한 다음 bashrc 파일의 맨 위에서 다음과 같이 변경하십시오.
alias python = python3
위의 내용을 파일에 추가 한 후. 아래 명령을 실행하십시오
소스 ~ / .bash_aliases 또는 소스 ~ / .bashrc
예:
$ python-버전
Python 2.7.6
$ python3-버전
Python 3.4.3
$ alias python = python3
$ python-버전
Python 3.4.3
추가로 pip에 대한 별칭도 추가 할 수 있습니다 (.bashrc 또는 bash_aliases에서) :
별칭 pip = 'pip3'
많은 사람들이 python3을 새로 설치하면 실제로 python3.x를 가리 키므로 다음이 필요할 수 있습니다.
alias pip = 'pip3.6'alias
python = 'python3.6'
하다
cd ~
gedit .bash_aliases
다음 중 하나를 쓰십시오
alias python=python3
또는
alias python='/usr/bin/python3'
파일을 저장하고 터미널을 닫은 다음 다시 엽니 다.
이제 괜찮을거야! 링크
파이썬 경로 가져 오기
ls /usr/bin/python*
그런 다음 파이썬 버전을 설정하십시오.
alias python="/usr/bin/python3"
Ubuntu 18.04에서 Python 3.6.8을 기본값으로 Python 3.7로 변경하려면
Python 3.7 설치
Python3.7을 설치하고 기본 인터프리터로 구성하는 단계입니다.
apt-get을 사용하여 python3.7 패키지 설치
sudo apt-get install python3.7
Python3.6 및 Python 3.7 추가
update-alternatives
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
Python 3.7을 가리 키도록 Python 3 업데이트
sudo update-alternatives --config python3
Python 3.7의 경우 2를 입력하십시오.파이썬 버전 테스트
python3 --v
Python 3.7.1
말했듯이 update-alternatives --install
<link> <name> <path> 및 <priority> 인수가 필요합니다.
You have link (/usr/bin/python
), name (python
), and path (/usr/bin/python3
), you're missing priority.
update-alternatives --help
says:
<priority> is an integer; options with higher numbers have higher priority in automatic mode.
So just put a 100
or something at the end
For another non-invasive, current-user only approach:
# First, make $HOME/bin, which will be automatically added to user's PATH
mkdir -p ~/bin
# make link actual python binaries
ln -s $(which python3) python
ln -s $(which pip3) pip
python
pip
will be ready in a new shell.
The best way in ubuntu 18.04 which will work for all users is
sudo vim /etc/bash.bashrc
add lines
alias python=python3
alias pip=pip3
Save the changes and restart .
After restart what ever version of python 3 you have in the system along with python 2.7 will be taken as default. You could be more specific by saying the following in alias if you have multiple version of python 3.
sudo vim /etc/bash.bashrc
add lines
alias python=python3.6
alias pip=pip3.6
At first, Make sure Python3 is installed on your computer
Go to your terminal and type:
cd ~/
to go to your home directory
If you didn't set up your .bash_profile
yet, type touch .bash_profile
to create your .bash_profile.
Or, type open -e .bash_profile
to edit the file.
Copy and save alias python=python3
in the .bash_profile.
Close and reopen your Terminal. Then type the following command to check if Python3 is your default version now:
python --version
You should see python 3.x.y is your default version.
Cheers!
ReferenceURL : https://stackoverflow.com/questions/41986507/unable-to-set-default-python-version-to-python3-in-ubuntu
'your programing' 카테고리의 다른 글
하단 내비게이션 바 아이콘 상단에 배지 표시 (0) | 2020.12.27 |
---|---|
메서드 내에서 호출 메서드 이름 검색 (0) | 2020.12.27 |
Netbeans에서 Tomcat 시작 실패 (0) | 2020.12.27 |
Recyclerview는 Adapter 메서드를 호출하지 않습니다. : onCreateViewHolder, onBindViewHolder, (0) | 2020.12.27 |
NSString에서 하위 문자열의 발생 횟수? (0) | 2020.12.27 |