I installed a Django package on GCP (Debian 9 OS), that comes with the following softwares:
Django (2.2.9)
Git (2.25.0)
Apache (2.4.41)
lego (3.3.0)
MySQL (5.7.29)
Node.js (10.18.1)
OpenSSL (1.1.1d)
PostgreSQL (11.6)
Python (3.7.6)
SQLite (3.31.0.)
Subversion (1.13.0)
When I type the command python -V
I get the following python version: 2.17.13
When I type python3 -V
I get the following version: 3.7.6
How can I uninstall the previous version permanently and keep the current one as the default?
Here's what I tried and I didn't work:
$ ls /usr/bin/python*
usr/bin/python /usr/bin/python2.7 /usr/bin/python3.5 /usr/bin/python3m
/usr/bin/python2 /usr/bin/python3 /usr/bin/python3.5m
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
Returns nothing
# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
Returns nothing
I would not recommend uninstalling python2. Install python3 and make sure the directory where you install it is included in your systems $PATH variable. You will need to do something like this. Note, depending on how you install python3, some installers will automatically update your $PATH variable.
Example installing python3 in "/Library/Frameworks/python3" directory.
Show current $PATH variable.
echo $PATH
update .bashrc in home directory (append to current $PATH)
PATH="/Library/Frameworks/python3:${PATH}"
reload .bashrc (or exit and start terminal back up)
. ~/.bashrc
Confirm correct python install will be run when typing python3 into terminal.
$which python3
/Library/Frameworks/python3
I am using Ubuntu 18.04.03 and recently i have installed anaconda on my system. Currently,
which python --> /home/user/anaconda3/bin/python #good
python --version --> Python 3.7.4
which python2 --> /usr/bin/python2 #good
python2 --version --> Python 2.7.15+
which are fine.
But,
which python3 --> /home/user/anaconda3/bin/python3 #oh no
python3 --version --> Python 3.7.4 #oh no again
#python3.6.8 has been installed in /usr/bin/python3.6
#python3 needs to point /usr/bin/python3.6
which is not fine. Also
which python3.7 --> /home/user/anaconda3/bin/python3.7 #please no
python3.7 --version --> Python 3.7.4
#python3.7 has been installed in /usr/bin/python3.7
#python3.7 needs to point /usr/bin/python3.7 not anaconda's 3.7
is not fine.
As you probably understood that when i write python (some version), i want to call interpreter in /usr/bin not anaconda's except when i write only python, i want to call anaconda's interpreter. How can i achieve that?
Check the content of your $PATH environment variable with echo $PATH. Find the anaconda bin directory in the output and change $PATH in your shell profile script (/etc/bash_profile, .bashrc, or .bash_profile for bash) to put it after /usr/bin. You will probably need to create symbolic links using ln -s in order to keep using anaconda's python and python2.
You could try changing the alias pointed by python3.7
echo 'alias python3.7="/usr/bin/python3.7"' >> ~/.bashrc
Then
source ~/.bashrc
I'm using robotframework for automation. I'm trying to use a method from my python library which needs psutil. The problem is when I execute from the robotframwork it gives error ImportError: No module named psutil but when I execute it with Pycharm I don't get any error. I have installed psutil using pip install psutil . I searched a lot on web but couldn't find any reason for this issue.
My experience with this error was that I had multiple versions of python installed on my ubuntu server 16.04LTS.
My PATH resolved to /usr/local/python -> python 2.7.10 meaning typing python into the commandline I got 2.7.10, but the standard path /usr/bin/python linked to python 2.7.12. The psutil module and others were only installed for version 2.7.10
My resolution was to re-symlink /usr/bin/python to point to my 2.7.10 version:
# Find which python your PATH is pointing at and the version
$ which python
# Returns
/usr/local/bin/python
$ /usr/local/bin/python --version
# Returns
Python 2.7.10
$ /usr/bin/python --version
# Returns
Python 2.7.12
Unlink and relink to correct python version in /usr/bin/python
$ cd /usr/bin
$ sudo unlink python
$ sudo ln -s /usr/local/bin/python python
# check python version points correctly
$ /usr/bin/python --version
# Now correctly returns
Python 2.7.10
P.s. Bear in mind it's still worth checking all your modules are correctly installed now that your environment is pointing at the 1 python version
Could you try setting the PYTHONPATH in your environment or by passing it as an option.
This person had a different issue, but the fix I think will be the same:
setup pythonpath before starting test suite
Cheers,
K
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
I've installed the Mac OSX Python 2.7.3, and tried switching to the new version:
$ python2.7 -V
Python 2.7.3 # It was installed
$ python -V
Python 2.6.1 # Default is 2.6
$ export VERSIONER_PYTHON_VERSION=2.5
$ python -V
Python 2.5.4 # I can switch to 2.5
$ export VERSIONER_PYTHON_VERSION=2.6
$ python -V
Python 2.6.1 # And 2.6
But:
$ export VERSIONER_PYTHON_VERSION=2.7
$ python -V
python: VERSIONER_PYTHON_VERSION environment variable error (ignored)
Python 2.6.1
Can't switch to 2.7! Why is that?
The python.org install will put a python executable in /usr/local/bin . Apple's python is in /usr/bin
To call the python.org python you can use its full path /usr/local/bin/python or change your path to put /usr/local/bin before /usr/bin. You will still be able to call Apple's python by using its full path /usr/bin/python
Some python installs e.g. Macports provide a tool that provides symbolic links to various python installs and allows you to switch between them.
I don't think we can switch the python version on the Mac OS X without resorting to something like MacPorts or ActivePython.
I think it's because VERSIONER_PYTHON_VERSION is specific to python packages built by apple.