LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   making python3.6.4 default python3 (https://www.linuxquestions.org/questions/linux-newbie-8/making-python3-6-4-default-python3-4175627404/)

Astral Axiom 04-10-2018 07:50 PM

making python3.6.4 default python3
 
I recently installed Python 3.6.4 and when I open the terminal and run
Code:

python3
I still get python 3.5.2 but if I run
Code:

python3.6
I get python 3.6.4. I want to know how to make 3.6.4 my default python3. Here are the locations of the three versions:
Code:

$ which python
/usr/bin/python
$ which python3
/usr/bin/python3
$ which python3.6
/usr/local/bin/python3.6

Do I need to remove python3.6 and install it so that somehow it has the path
Code:

/usr/bin
instead of being in
Code:

/usr/local/bin
or can I simply move it there, or is all of that unnecessary and I can just set the default in some text file in /etc or something? here is the code I ran to install python 3.6.4:
Code:

apt install build-essential checkinstall
apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
tar xvf Python-3.6.4.tar.xz
cd Python-3.6.4/
./configure
make
make altinstall

Oh right, you may want to know that I am running KDE Neon. On my laptop I run Arch and python 3.6.4 is already the default on that system and it has the path
Code:

/usr/bin
I guess it was put there by default when I installed the base system since I did not explicitly install it.

JockVSJock 04-10-2018 09:24 PM

What does the following command show?

Code:

export $PATH
Where does Python 3.6.4 live?

Code:

whereis python3.6.4

RockDoctor 04-11-2018 05:28 AM

On my system (Fedora, so /bin is a link to /usr/bin) /usr/bin/python3 is a link to /usr/bin/python3.6. Perhaps it's as simple as changing the python3 link to point to the installed python3.6.4

Astral Axiom 04-11-2018 08:20 AM

Here is the ouptput:
Code:

$ export $PATH
bash: export: `/home/me/bin:/home/me/.local/bin:/usr/local/sbin

:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

:/usr/local/games:/snap/bin': not a valid identifier

$ echo $PATH
/home/me/bin:/home/me/.local/bin:/usr/local/sbin:/usr/local/bin

:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

:/snap/bin

I have been looking at the "export" man pages a bit. Out of curiosity, what is the difference in
Code:

export $PATH
and
Code:

echo $PATH
? They seem to provide the same information, save the "not valid identifier" warning with "export" and the part at the beginning; "bash: export:". Can you enlighten me a bit as to what export is. As is often the case, the man pages are somewhat vague for beginners like me. I am working through a series of online Linux courses with Jason Cannon through Udemy, however I still have trouble interpreting some of the man pages at this point.

The interesting thing to me is that in my PATH
Code:

/usr/local/bin
comes before
Code:

/usr/bin
So why is the command not executed there first as it should be the first place the command is found when I type "python3"? Perhaps a link like you said RockDoctor, I need to see how to veiw all the links and learn how to create one where I want it then. I am guessing that would be in the "ln" man pages?

pan64 04-11-2018 09:35 AM

export PATH, there is no $
This is the main difference.
see man bash and look for export command, this is a built-in.

AwesomeMachine 04-11-2018 12:46 PM

You just change the python3 link to point to the version you wish. But that might break more than a few things on the system. But, you can try it.

Astral Axiom 04-11-2018 01:39 PM

Quote:

Originally Posted by AwesomeMachine (Post 5841961)
You just change the python3 link to point to the version you wish. But that might break more than a few things on the system. But, you can try it.

So basically, just type in
Code:

python3.6
when I wish to use python 3.6.4, which is always. I guess the safest and best solution would be to create an alias for python3 as python3.6?

Astral Axiom 04-11-2018 05:36 PM

Creating an alias does not solve the issue and avoiding the typing of two extra characters is not the goal nor worth creating an alias for so I've scrapped that idea. Is there no way to simply upgrade the default python3 version to the latest stable release? It seems that there should be, and that it should be relatively straight forward. I created a virtual KDE Neon and explicitly installed Python 3.6.5 to
Code:

/usr/bin
and still the
Code:

python3
command starts Python 3.5.2, not that I thought it wouldn't just thought I'd try it.

Does anyone know if there is a way to simply upgrade the default Python3 to the latest stable version?

AwesomeMachine 04-13-2018 08:45 PM

You would do it likw this
Code:

$ cd /usr/bin
$ ls -al python3 #make sure it's a link and not a file
$ rm python3
$ ln -s python3 python3.6.4


Astral Axiom 04-14-2018 01:22 AM

Quote:

Originally Posted by AwesomeMachine (Post 5842921)
You would do it likw this
Code:

$ cd /usr/bin
$ ls -al python3 #make sure it's a link and not a file
$ rm python3
$ ln -s python3 python3.6.4


Is that a different process than you meant when you wrote:
Quote:

You just change the python3 link to point to the version you wish. But that might break more than a few things on the system. But, you can try it.
? I created a virtual KDE Neon in my KDE Neon with Virtual-Box so that I can try things out that I am a bit nervous about to see if it works or if it breaks anything, I will have to try that there. I have already installed Python 3.6 in the virtual Neon in:
Code:

/usr/bin
So I will try this method there.

On a side note there is an interesting anomaly in the virtual Neon. In my other virtual machines (Centos, Debian) it is necessary to click in the machine to capture the mouse and keyboard and then press right cntrl to return mouse and keyboard to the system, but in the Neon virtual machine the mouse is always available to both the virtual machine and the system. It is hard to tell whether the keyboard is the same as it is available to the currently active window under normal operation. I think that is weird and thought I would share it .......any thoughts?

pan64 04-14-2018 03:53 AM

I think that should be:
ln -s python3.6.4 python3

Astral Axiom 04-14-2018 09:32 AM

This is straight from the ln man pages:
Code:

SYNOPSIS
      ln [OPTION]... [-T] TARGET LINK_NAME  (1st form)
      ln [OPTION]... TARGET                  (2nd form)
      ln [OPTION]... TARGET... DIRECTORY    (3rd form)
      ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

DESCRIPTION
      In  the 1st form, create a link to TARGET with the name LINK_NAME.  In the 2nd form, create a link to
      TARGET in the current directory.  In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
      Create  hard links by default, symbolic links with --symbolic.  By default, each destination (name of
      new link) should not already exist.  When creating hard links,  each  TARGET  must  exist.  Symbolic
      links  can  hold arbitrary text; if later resolved, a relative link is interpreted in relation to its
      parent directory.

-t, --target-directory=DIRECTORY
 specify the DIRECTORY in which to create the links

-T, --no-target-directory
 treat LINK_NAME as a normal file always

I am still not experienced with the ln command, but I think if no options are supplied and there are 2 arguments(python3.6.4[target], python3[link name]) then 1st form would be applied. In which case, I think it would be correct that the command should be
Code:

ln -s python3.6.4 python3
If I understand correctly the "-T" option is applied when no options are supplied and using the command:
Code:

ln -s python3 python3.6.4
would be the 4th form, in which case the "-t" option and the full path to python3 would both need to be supplied, making the command:
Code:

ln -s /usr/bin/python3 python3.6.4
if I understand correctly. Which is a big if since I still have much trouble interpreting man pages at this time. It seems, if I understand correctly(once again), that it would be safer to be more explicit and use either that(4th form command above) or use the 3rd form:
Code:

ln -s python3.6.4 /usr/bin/python3
In any case you are, I believe, both saying to do:
Code:

$ cd /usr/bin
$ ls -al python3 #make sure it's a link and not a file
$ rm python3
$ whichever ln command is correct to create the python3 link

correct?

pan64 04-14-2018 10:07 AM

if you wish to play/learn ln, just create a new dir (as regular user) and try any combinations - on simple, short text files. That will not harm your system and you will understand the meaning of those options...
Post #11 should work only if you are already in /usr/bin, otherwise it will not make what you need.
The 4th form is not really applicable in your case I think.

https://www.cyberciti.biz/faq/creati...symbolic-link/
https://unix.stackexchange.com/quest...he-usage-of-ln

Astral Axiom 04-14-2018 10:09 AM

Ok, so some of my last post on this thread was forgetting that the suggested commands were being run from within the directory i.e.:
Code:

$ cd /usr/bin
being the first command to run, so forget all that. So, In my virtual Neon I ran this command(which I believe is in either the 3rd or 1st form):
Code:

$ ln -s /usr/bin/Python-3.6.5/python /usr/bin/python3
from my home directory after removing the was current python3 link from within the /usr/bin directory. This worked, now when I type python3 from the home directory, python3.6.5 is opened for use. I do not know if it broke anything else yet, as AwesomeMachine suggested it might. I will play around with it for a while and then let you know. Do either of you have any suggestions on what to check, what things might this have broken?

pan64 04-14-2018 10:28 AM

in general there are a lot of things running with python (=python2) and python3. The installed python codes/scripts assume an installed and compatible python executable. Replacing this may cause incompatibilities. You need to know what are the differences between 3.5.2 and 3.6.4 and which code will depend on those changes. Most probably none, but maybe there is something....


All times are GMT -5. The time now is 06:13 PM.