Python3 link as python

Change Python Version Mac How to set Python3 as a default python version on MacOS?

By default MacOS ships with Python-2.-. But, I guess most of us have long back started to work with Python-3 and it is very irritating to run python3 every time instead of python in terminal. Here is how to do this. Open the terminal (bash or zsh) whatever shell you are using. Install python-3 using Homebrew (https://brew.sh).

lrwxr-xr-x 1 irfan admin 34 Nov 11 16:32 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3 lrwxr-xr-x 1 irfan admin 41 Nov 11 16:32 /usr/local/bin/python3-config -> ../Cellar/python/3.7.5/bin/python3-config lrwxr-xr-x 1 irfan admin 36 Nov 11 16:32 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.5/bin/python3.7 lrwxr-xr-x 1 irfan admin 43 Nov 11 16:32 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.5/bin/python3.7-config lrwxr-xr-x 1 irfan admin 37 Nov 11 16:32 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.5/bin/python3.7m lrwxr-xr-x 1 irfan admin 44 Nov 11 16:32 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.5/bin/python3.7m-config 

Change the default python symlink to the version you want to use from above.
Note that, we only need to choose the one that end with python3.*. Please avoid using the ones’ that end with config or python3.*m or python3.*m-config. Below command shows how it should be done:

ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python 

Close the current terminal session or keep it that way and instead open a new terminal window (not tab). Run this:

Top comments (85)

I’m not saying anyone would want to install Python 3 without brew, but if they did, pip3 gets installed:
$ pip3 —version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
$ pip3 install —upgrade pip
Collecting pip
Downloading files.pythonhosted.org/packages/54. (1.4MB)
|████████████████████████████████| 1.4MB 1.7MB/s
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2

$ which pip
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip

Now, Irfan’s handy command:
sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python

$ python —version
Python 3.8.2

7 likes Like Comment button

Hey! I tried following your above-mentioned method .. but I don’t know how the path is different . Although this method worked but will that path create any problem later on?
On my mac
which pip results in
/usr/local/bin/pip
instead of
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip

apoorveesinha@Apoorvees-Air ~ % python —version
Python 2.7.16
apoorveesinha@Apoorvees-Air ~ % python3 —version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % pip3 —version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
apoorveesinha@Apoorvees-Air ~ % pip3 install —upgrade pip
Collecting pip
Downloading files.pythonhosted.org/packages/54. (1.4MB)Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
Password:
apoorveesinha@Apoorvees-Air ~ %

Читайте также:  background-position

apoorveesinha@Apoorvees-Air ~ % python —version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % python3 —version
Python 3.8.2

2 likes Like Comment button

Источник

Fixing «Command ‘python’ not found» Error in Ubuntu Linux

Tried running python command but Ubuntu complains that python command is not found? It may already be installed but you’ll still see the error. Here’s why!

However, if you try to use the python command in Ubuntu (and some other distributions), it will throw an error.

Command ‘python’ not found, did you mean:
command ‘python3’ from deb python3
command ‘python’ from deb python-is-python3

If you pay attention to the error message, it clears a lot of things. The python command is actually python3 here. If you don’t understand it, no worries. I’ll explain things in detail here.

Why there is no python command found on Ubuntu?

It’s because the Python language is not installed as python but python3 or python2 (in some older Ubuntu versions). At some point in time in the distant past, Python was actually available as python package/executable. When Python released version 2, Ubuntu and other distros had to provide support for both Python version 1.x and 2.x. So, they named the newer Python version python2 to distinguish between the two. Other applications or libraries also specified python or python2 in their code. Eventually, Python version 1 was discontinued completely but the package continued to be named python2. Similarly, when Python version 3 was released, distributions started providing both python2 and python3 packages. Python 2 is no longer supported and Python 3.x is what you get on Ubuntu. The package is still named python3. To summarize, you have Python installed on Ubuntu already. It is available as python3 package. So, what are your options when you see Python command not found error on Ubuntu? Let me go over them.

Make sure you have Python installed on your system

It should already be installed but no harm in double checking. Ubuntu 18.04 had Python 2 as well but 20.04 and higher versions have Python 3 only. Still, which version(s) you have with:

type python python2 python3

check python version ubuntu

As you can see in the screenshot below, I have Python version 3 installed on my system. If you don’t have any Python version installed, you may install Python version 3 with the following command:

Use python3 instead of python

If it’s not too much of a trouble for you, use python3 command instead of python wherever required. Want to check the installed python version? Use it like this:

[email protected]:~$ python3 --version Python 3.10.4

This should work for you in most cases. However, if you are using some (old) Python application that expects to run the python executable in its code, you’ll have issues. Don’t worry, you can get around it as well.

Читайте также:  Класс view java android

This way, you can run the python command and your system runs python3 . It will work in most cases unless some program expects to run /usr/bin/python. Now, you may create symlink between /usr/bin/python and /usr/bin/python3 but there exists a simpler option for Ubuntu users. For Ubuntu 20.04 and higher versions, you have a package that does all link creation automatically if you install the python-is-python3 package. This is what the original error message has also suggested.

sudo apt install python-is-python3

install python is python3 ubuntuYou can see that symlinks have been created and you can use the python command (which actually runs python3) without any issues. checking python ubuntuI hope this clears the air on the Python package in Ubuntu. Let me know if you have any questions or suggestions.

Источник

Как в linux сделать чтобы python3 вызывался командой python?

В системе установлен python 3 и вызывается он командой «python3». Как сделать что-бы он вызывался командой «python»?
Знаю что это сделать очень просто, но вылетело с головы. Гуглил, но ничего не нашел.

Оценить 2 комментария

DR_Demons

hottabxp

Да просто начал писать скрипты в geany, а при запуски с этого редактора выдает ошибку, мол python не найден. Не мог разобраться, как в geany указать путь к третьему питону. Но уже разобрался.

Olej

Это сделать не просто, а очень просто. — но после этого приготовьтесь переустанавливать систему по-новой.

eselect python list | grep python3 | awk ''| cut -d [ -f 2 | cut -d ] -f 1 | xargs eselect python set

У человека итак вызывается python3, он хочет, чтобы был алиас python на /usr/bin/python3. %)
То бишь alias python=’/usr/bin/python3′

1. Вариант на текущую сессию для текущего пользователя:
alias python=’python3′
2. Вариант (1) плюс внесение в конфигурацию .bashrc (чтобы не вводить каждый раз после логина). Надо в конце перелогиниться:

cd ~ echo alias python=\'python3\' >> .bashrc logout

3. Вариант сделать команду python для всех пользователей машины (нужны права, либо попросить админа):
sudo ln -s /usr/bin/python3 /usr/bin/python

Войдите, чтобы написать ответ

Свободен ли manjaro linux?

Источник

Setting the Default python to python3

In this tutorial, let’s look at how to set the default Python in our system based on our preferred Python version. Most Linux distros usually have the latest stable release of Python included as the default, and in older systems, the deprecated Python2.* is the default.

We’ll see how we can change the default Python using the alias and update-alternatives commands.

2. Setting Default Using the alias Command

Before we make any changes, let’s check which version of Python is available in our system:

$ python --version Python 3.10.6 $ python3 --version Python 3.10.6

In the above snippet, the python command with the –version option shows our system’s currently set default Python version. Likewise, python3 displays whichever version of Python3 is installed.

To check for Python2, we run python2 –version. Alternatively, we can run python -V to get the same result.

Читайте также:  Php ldap search operations error

The alias command lets us create shortcuts for commands or override the default options for the existing commands. Assuming we’ve installed Python3.8 in the /usr/bin directory and want it to be our default Python, we can use the alias command:

$ alias python=/usr/bin/python3.8

In this example, we’ve overridden the default Python and set our preferred one:

set default python

Using an alias, we can set both python and python3 commands to the same path. However, upon shutdown or rebooting, the setting isn’t retained. For this reason, to make the change permanent, we need to edit the bash_aliases file by appending our alias to it:

$ sudo vi ~/.bash_aliases alias python=/usr/bin/python3.8 alias python3=/usr/bin/python3.8

We then save the file and activate the alias:

It’s important not to add our alias to the ~/.bashrc file. This is because if we do so, we won’t be able to use the aliased command with sudo.

Again, let’s check the version and find out what is the default version set:

$ python --version Python 3.8.16

3. Using the update-alternatives Command

Now, we’ll look at how we can set the default Python version to whatever version we want using the update-alternatives command. We use this command to maintain symbolic links determining default commands.

Let’s say we’ve got several versions of Python installed. For instance, let’s assume these are the versions we currently have:

$ whereis python python: /usr/bin/python3.5-config /usr/bin/python3.5m-config /usr/bin/python2.7 /usr/bin/python3.5 /usr/bin/python3.5m /usr/bin/python /usr/lib/python2.7 /usr/lib/python3.5 /etc/python2.7 /etc/python3.5 /etc/python /usr/local/bin/python3.11-config /usr/local/bin/python3.11 /usr/local/lib/python2.7 /usr/local/lib/python3.5 /usr/local/lib/python3.11 /usr/include/python3.5 /usr/include/python3.5m /usr/share/python /usr/share/man/man1/python.1.gz

Next, suppose we want the Python in /usr/local/bin/python3.11 set as the default. We’ll use the update-alternatives command following this syntax:

$ sudo update-alternatives —install needs

We should note that flags with higher priority numbers have higher precedence in automatic mode:

$ sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.11 20 $ sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/local/bin/python3.11 20 auto mode 1 /usr/bin/python3 10 manual mode 2 /usr/local/bin/python3 20 manual mode Press to keep the current choice[*], or type selection number:

Depending on the Python version we want to be the default, we select a number shown and then click on the enter key.

Once more, let’s check if the Python version has changed to that contained in the path we chose:

If there’s only a single link, we’ll get this error:

$ sudo update-alternatives --config python There is only one alternative in link group python (providing /usr/bin/python): /usr/bin/python3 Nothing to configure.

Additionally, we’ll also get this error if we don’t set the priority number:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 update-alternatives: --install needs    Use 'update-alternatives --help' for program usage information.

4. Conclusion

In this article, we’ve looked at the two ways to set the default Python version of our preference. We also discussed some common errors we encounter while using the update-alternatives command.

Источник

Оцените статью