python -v and python3 -V give different results - python

python -v and python3 -V give different results
Current status.
$ python -V
Python 3.10.10
$ python3 -V
Python 3.9.16
Output results will be different.
What I did
Switched versions in pyenv.
$ pyenv global 3.10.10
What I want to do.
I want both to be Python 3.10.10.
I've tried everything, but I wasn't sure how to do it.
I would appreciate it if you could tell me how to do it.

Related

Why is my pyenv showing the wrong active python version?

I'm using an Intel MacBook Pro and have problems with python and pyenv.
Can anybody explain how this can happen and how I can correct it?
[~] pyenv versions
system
* 3.10.1 (set by /Users/....../.pyenv/version)
[~] python -V
Python 2.7.16
[~] pyenv --version
pyenv 2.2.3
[~]
In my .zshrc file I have
# set correct python version using pyenv
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
In my opinion python -V should return 3.10.1 and not 2.7.16 which seems to be the system version.
I installed pyenv using brew and run MacOS BigSur 11.6.2.
I was able to follow Tim Roberts' suggestion to create a symlink in order to solve this problem on my own Mac. I am writing this answer to help clear up any ambiguity you might have.
The commands I used were:
cd /usr/local/bin
ln -s /usr/local/bin/python3 python
python -V
Which gives me:
[16:57:25] Richards-MBP:bin richardkyu$ python -V
Python 3.8.12
Typing in python to the command line opens up the 3.8.12 interpreter. Also, my python3 is installed by brew I believe.
Following up on the comment, I should clarify that I created a new symlink for python rather than rewriting the one for python3. When I execute
ls -l grep python3
in the /usr/local/bin directory, I get the following output, which I assume is similar to yours:
I am not sure of the exact issue with these symlinks you're seeing, but if you can clarify what you're worried about I would be glad to check it out.

How to fix "python version are always returned 2.7 instead of 3.7"

I downloaded python 3.7.3 but python 2.7.10 already existed.
Now python --version returns 2.7.10
How to fix this?
If you are working on Linux, you can always type python3 --version to check if it is installed and be sure it is the version you want to use.
There are several ways to make python call Python 3 by default. For instance you can create an alias. Type whereis python3 so you get the installation path to python3 (normally it is located in /usr/bin/python3). If that's the case you can simply add to ~/.bashrc the following line:
alias python='/usr/bin/python3'
Then, source that file or reload the session. This assumes that /usr/bin/python3 is the location of Python 3. Please, note that other commands that depend on your Python installation (such as pip or coverage) are still pointing to the ones installed by Python 2, so you may want to do the same for them, or make sure that you call pip3 instead of pip if you want to install any extra package.
If you are using linux or macOS, the python command refers to the built-in Python2. You need to use the python3 command to use Python3.
So running:
python3 --version
should give you the expected output.
Also, when you want to run your scripts in Python3, you need to use:
python3 myscript.py
Both the python2x and python3x can exist on a system. On linux machines the default python version is python2x.
so if you want to work with python2x type python2.7 or python3 otherwise.
Installation
sudo apt update
sudo apt install python3.9
Checking the installation with the python3 --version command still returns the old version. To fix this :
Create a list of update alternatives. First, add the old version to the list with the command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.[old-version] 1
Now add the new version:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
Type the following command to configure the priority status of the versions:
sudo update-alternatives --config python3
check the default version:
python3 --version
DONE

make python3.5 as default in AWS?

Is there a way to make python3.5 as the default python in AWS.
every time i try the next time i connect python2.7 is the default one and pip 6 is the last version, knowing that I did updated it some minutes before.
here is the method i followed : amazon_link
here is another link of amazon telling the versions, actually they are at 3.5 another_link
Thank you in advance, :)
best wishes
alternatives --set python /usr/bin/python3.5
and then back if you want to
alternatives --set python /usr/bin/python2.7
If you want to see what it currently points to
alternatives --display python
This is a system-wide setting not just for the current user. The system settings are stored in /etc/alternatives
A simple safe way would be to use an alias. Place this into ~/.bashrc or ~/.bash_aliases file:
alias python=python3
Example
$ python --version
Python 2.7.6
$ python3 --version
Python 3.4.3
$ alias python=python3
$ python --version
Python 3.4.3
By default, the awscli-bundle install script runs under the system default version of Python. To answer your question you will need to know the path of Python version to use.
Then run:
$ sudo /path/to/python/version awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
In my case I would run:
$ sudo /usr/local/bin/python3.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
To change Python Version 3.x
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.x 1
*** Because sometimes priority is required use, you just add '1' at end of command line.**
To check update
sudo update-alternatives --list | grep python
Reset Python old version'
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
Just close terminal and restart.
Python -V
3.x
Good luck
do above: alias python=python36 in ~.bashrc file (Use emacs, vim, your favorite editor - emacs ~.bashrc) then save file.
then in command line terminal type: source ~/.bashrc (for changes to take effect)
Because AL2 is picky, unfortunately NONE of these answers is exactly correct. Here's what worked for me just now (as root)-
alternatives --install /usr/bin/python python /usr/bin/python2.7 1
alternatives --install /usr/bin/python python /usr/bin/python3.7 2
3.7 SHOULD be the default now, and you can test with python --version.
To change the default at any time:
update-alternatives --config python
The menu system will prompt you through the change.
I used alias and it works for me. (AMI2 AWS)
alias python=python3
Add this command in .bashrc file and then reboot the server
python --version
It will show python version 3

How to check all versions of python installed on osx and centos

I just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is used by system tools such as YUM so I should not tamper with it. Then I opened up a terminal on my mac and found that I had python 2.6.8 and 2.7.5 and 3.3.3 installed. Sorry for the long story. In short I just want to know how to lookup all the version of python installed on centos so I don't accidentally install it twice.
The more easy way its by executing the next command:
ls -ls /usr/bin/python*
Output look like this:
/usr/bin/python /usr/bin/python2.7 /usr/bin/pythonw
/usr/bin/python-config /usr/bin/python2.7-config /usr/bin/pythonw2.7
we can directly use this to see all the pythons installed both by current user and the root by the following:
whereis python
Find out which version of Python is installed by issuing the command
python --version:
$ python --version
Python 2.7.10
If you see something like this, Python 2.7 is your default version. You can also see if you have Python 3 installed:
$ python3 --version
Python 3.7.2
If you also want to know the path where it is installed, you can issue the command "which" with python and python3:
$ which python
/usr/bin/python
$ which python3
/usr/local/bin/python3
Here is a cleaner way to show them (technically without symbolic links). This includes python2 and python3 installs:
ls -1 /usr/bin/python* | grep '.*[2-3]\(.[0-9]\+\)\?$'
Where grep filters the output of ls that that has that numeric pattern at the end ($).
Or using find:
find /usr/bin/python* ! -type l
Which shows all the different (!) of symbolic link type (-type l).
Use, yum list installed command to find the packages you installed.
COMMAND: python --version && python3 --version
OUTPUT:
Python 2.7.10
Python 3.7.1
ALIAS COMMAND: pyver
OUTPUT:
Python 2.7.10
Python 3.7.1
You can make an alias like "pyver" in your .bashrc file or else using a text accelerator like AText maybe.
As someone mentioned in a comment, you can use which python if it is supported by CentOS. Another command that could work is whereis python. In the event neither of these work, you can start the Python interpreter, and it will show you the version, or you could look in /usr/bin for the Python files (python, python3 etc).
It depends on your default version of python setup. You can query by Python Version:
python3 --version //to check which version of python3 is installed on your computer
python2 --version // to check which version of python2 is installed on your computer
python --version // it shows your default Python installed version.
compgen -c python | grep -P '^python\d'
This lists some other python things too, But hey, You can identify all python versions among them.
Sift through the output of this script.
sudo find / -name 'python*' -type f -exec du -h {} + | sort -r -h ~/Documents/python_locations.txt
ls -l /usr/bin/python* & ls -l /usr/local/bin/python*
I would add to #nurealam siddiq answer,
python --version // it shows your default Python installed version.
python2 --version // to check which version of python2 is installed
python3 --version //to check which version of python3 is installed
python3.X --version // to further check which python3.X is installed
To check python versions installed in your OS you can run the below commands:-
python2 -version
python3 -version

iPython 3 uses Python 2 instead of Python 3

iPython 3 — installed with pip3 and located at /usr/local/bin/ipython3 — runs with Python 2.7.6 in both the console and notebook whereas I want it to run with Python 3 as it should.
This used to work fine before, but I may have reinstalled stuff using MacPorts or HomeBrew that triggered the change.
$ which -a python
/opt/local/bin/python # 2.7.9
/usr/local/bin/python # 2.7.8
/usr/local/bin/python
$ which -a python2
/usr/local/bin/python2 # 2.7.8
/usr/local/bin/python2
$ which -a python3
/usr/local/bin/python3 # 3.2.4
/usr/local/bin/python3
$ pip3 -V
pip 1.5.6 from /usr/local/lib/python3.4/site-packages (python 3.4)
$ ipython3 -V
2.3.1
I edited the shebang on the iPython executable from #!/usr/bin/python to #/usr/local/bin/python3, but I am not sure if this is a hacky or bad solution.
what work for me is changing #!/usr/bin/python to #! /usr/bin/python3 in file /usr/local/bin/ipython3
Just make sure that above address in all files coming out from 'whereis ipython3' should be same.

Categories