Upgrading Python on Ubuntu 15.10 - python

I'm trying to upgrade my python to 2.7.11 on Ubuntu 15.10, by following the guides here
http://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/
http://mbless.de/blog/2016/01/09/upgrade-to-python-2711-on-ubuntu-1404-lts.html
But after, when I try and reopen terminal, and type in python it still shows the version is 2.7.10
Does anyone know why this is the case?

The post you've linked says explicitly in the first sentence: "you should not touch the Python version of the system." i.e., /usr/bin/python should remain the same and therefore if /usr/bin is earlier in your $PATH envvar than the path to the newly installed python version then python invokes /usr/bin/python and you see the old version.
To install/manage multiple minor python versions, you could use pythonz or similar tools (such as pyenv):
$ pythonz install 2.7.11 # to install 2.7.11 version
$ $(pythonz locate 2.7.11) # to start the corresponding version
You could create a virtualenv using the desired python version (using virtualenvwrapper's command):
$ mkvirtualenv -p $(pythonz locate 2.7.11) py2.7.11
python will refer to 2.7.11 version inside the virtual environment.

Related

How to change python3 version on mac to 3.10.10

I am currently running python 3.9.13 on my mac. I wanted to update my version to 3.10.10
I tried running
brew install python
However it says that "python 3.10.10 is already installed"!
When i run
python3 --version
in the terminal it says that i am still on "python 3.9.13"
So my question is, how do i change the python version from 3.9.13 to 3.10.10? I already deleted python 3.9 from my applications and python 3.10 is the only one that is still there.
I also tried to install python 3.10.10 from the website and installing it. However it does not work. Python 3.10.10 is being installed successfully but the version is still the same when i check it.
Python 3.10.10 is already installed along with Python 3.9.13. Your path is probably pointing to 3.9.13 and that's why you're getting that Python version.
Try modifying your path variable to point to brew's Python installation, or (better yet) make use of a virtual environment.
a) Telling what Python version your PATH variable is pointing to:
$ which python
Will tell you what's the actual executable's path. That way, you are going to see exactly where you main python resides.
b) If you want to create a virtual environment with brew's python try something like:
$ /usr/local/Cellar/python#3.10/3.10.1/bin/python3 -m venv py310
$ source venv/bin/activate
$ python
> # you should be inside a 3.10.1 envornamente
> CTRL+D
$ pip install requests
you can use pyenv to work with multiple python environments
things to do:
install pyenv : brew install pyenv
install particular python: pyenv install 3.10.10
set python3.10.10 to gloabal python env: pyenv global 3.10.10
and can start using python 3.10.10 version
Just delete the current python installation on your device and download the version you want from the offical website. That is the easiest way and the most suitable one for a beginner.

Why there are two python versions in a virtual environment?

I have created a virtual environment using anaconda in VS. When the environment is active. I check the version using python --version, it gives the following output Python 3.9.9, whereas when I use which python and check the version from the path /usr/bin/python --version I get a different version Python 2.7.18. Why is that happening, and which version does the environment use?
Once your virtual environment is activated the python command will use the python version from your venv (located in path/to/.venv/bin/python).
which python and /usr/bin/python forces the use of the python version installed in /usr/bin/python which in your case seems to be version 2.7.18. If you want to change your default Python version (the one thats used with python without a venv being active) you can use sudo ln -s /usr/bin/python /usr/bin/python3.9.

python3 --version command not returning correct version

I am trying to upgrade to the most recent version of python, which is currently 3.8.5.
When I type python3 --version, I get:
Python 3.7.0
So it appears my python is not up-to-date. I then type brew upgrade python and get a warning:
Warning: python 3.8.5 already installed
So, again, I type python3 --version, and again I get:
Python 3.7.0
Why is python3 --version not returning Python 3.8.5?
(PS - if I type python --version I get Python 2.7.11 as expected for my Mac)
Homebrew is installing python 3.8.5 to a different path. Try:
brew link python3
brew update
brew upgrade python3
brew cleanup python3
You may have multiple python binaries on your system but the system path is finding 3.7.0. The command which python3 will show the path of your current python binary.
It might be worthwhile taking a look at the system path with echo $PATH to see where your system is looking for Python
Updating your system environment using export as below should enable the system to find python3.8.5
PATH="/path/to/python3.8.5/bin:${PATH}"
export PATH

How to get the python command to go back to using python 2.7 Ubuntu?

So I made a mistake and routed the python command to point to python 3.6.9 and now certain programs (namely ROS packages) are having issues. I'm on Ubuntu 18.04. I see lots of tutorials telling people how to alias python to python3 but not how to fix this issue. Also I tried to unalias python, but that did nothing.
So now when I run python --version OR python3 --version I see python 3.6.9
And when I run pip --version OR pip3 --version I see pip 20.1.1 from /home/me/.local/lib/python3.6/site-packages/pip (python 3.6)
You can install an isolated Python 2.7 in your system and actually have several versions of Python. One of the easiest ways is pyenv
You can do it like this:
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
Follow the instructions, you may need to reload your env (re-log in into the console).
Then install and set Python 2.7 as a default Python:
pyenv global 2.7.18

python versions management: always results python 2.7 in console

Several versions of python are installed on my Mac.
Usually, I am using Anaconda with Python 2.7. Nowadays I decide to try Python 3.6
Environment parameters:
which python
#/Users/User/anaconda/bin/python
which python3.6
#/usr/local/bin/python3.6
echo $PATH
/Users/User/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/User/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
The problem is:
~ User$ /usr/local/bin/python3.6 --version
Python 2.7.14 :: Anaconda, Inc.
How can I to overcome this trouble?
The output from the second command where running python3.6 --version prints out a Python 2.7.14 string doesn't make sense to me. You might try removing the Anaconda directories from your PATH environment variable and see if that resolves it.
The simplest way to manage and install multiple Python versions is through pyenv.
It allows you to install new versions with pyenv install <version> for dozens of Python versions including CPython as well as alternative interpreters like PyPy.
I would recommend you try installing pyenv:
$ brew install pyenv
Then install Python 3.6.5 via it:
$ pyenv install 3.6.5
You can set this version as your system-wide default Python version as well:
$ pyenv global 3.6.5
Then in projects where you want the python command to point to a Python 2.7 shim, you can set the local version in that directory with:
$ pyenv local 2.7.14
With these commands, you can just run python in any one of your project directories (after you've set a custom override version if desired), and not have to worry about calling python3.6 in some places, python2.7 in others, etc.
In a more advanced setup, you can also provide multiple Python versions if you have a project that needs both Python 2 and Python 3 together, for example, in a shell session:
$ pyenv shell 3.6.5 2.7.14
$ pyenv version
3.6.5 (set by PYENV_VERSION environment variable)
2.7.14 (set by PYENV_VERSION environment variable)
$ python --version
Python 3.6.5
$ python2 --version
Python 2.7.14
$ python3 --version
Python 3.6.5
(In this case whichever version you set first is the one that python points to by default.)

Categories

Resources