How to uninstall and install a specific python version - python-3.x

Am using ubuntu 20.04 LTS by default I have 3.8.2 as python version but when I issue sudo apt-get update its getting updating to 3.8.5 I need 3.8.2 as the version.How to uninstall 3.8.5 and install 3.8.2?

It might not directly answer your question, but it's an alternative solution. You could install something like pyenv which simplifies the process of handling different python versions. After installing it, pyenv install 3.8.2 && pyenv global 3.8.2 should do the trick.

Related

how to install python 3.9.6 using homebrew on Mac m1

Im new to programming and stuff and was looking to install python 3.9.6 using home-brew. To do that would I just have to type in brew install python#3.9 into the terminal, or is there some other way? Thanks!
You can't ensure a specific version 3.9.6 with brew package python#3.9. Homebrew is a package manage designed to get latest pacakge. python#3.9 will be kept updating to the latest patch version 3.9.x.
If you REALLY to stick with specific python version, choose conda (miniconda is preferred) or pyenv.

Pip install on Mac OS gets error: command '/usr/bin/clang' failed with exit code 1

I want to install google-cloud-pubsub via pip installation on Mac OS but I get an error: distutils.errors.CompileError: command '/usr/bin/clang' failed with exit code 1. The command I run: pip install google-cloud-pubsub==2.1.0.
Here the complete error message.
Any suggestion? Thank you!
More info:
$ python -V
Python 3.9.0
$ pip -V
pip 20.2.4 from /.../lib/python3.9/site-packages/pip (python 3.9)
$ sw_vers
ProductName: macOS
ProductVersion: 11.0.1
BuildVersion: 20B29
I've seen other similar cases but them don't solve my issue. I tried:
Pip install error in Mac OS(error: command '/usr/bin/clang' failed with exit status 1)
Mac OS Mojave installation error - error: command 'clang' failed with exit status 1
Try to add these env var before
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install google-cloud-pubsub==2.1.0
If it does not work you can try with virtualenv:
pip install virtualenv
virtualenv my-test-env
source my-test-env/bin/activate
my-test-env/bin/pip install google-cloud-pubsub==2.1.0
Because is written on github:
Install this library in a virtualenv using pip. virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions.
With virtualenv, it's possible to install this library without needing system install permissions, and without clashing with the installed system dependencies.
I was using pyenv and facing the similar kind of issue. Then I did the following and it worked.
First, upgrade pip
pip3 install --upgrade pip
Then, update the setup tools:
python3 -m pip install --upgrade setuptools
I just had this same problem but I'm using homebrew to manage my Mac packages.
My error result was the same as yours but within the error message it was:
plyvel/_plyvel.cpp:632:10: fatal error: 'leveldb/db.h' file not found
#include "leveldb/db.h"
This can be fixed using homebrew by just installing leveldb:
brew install leveldb
This allowed the plyvel dependency to be satisified. I then manually installed plyvel just to be safe:
pip3 install plyvel
And lastly because I'm trying to install the airflow libraries that include pubsub:
pip3 install apache-airflow-providers-google
I ended up just using Python 3.8.13 instead, managed with pyenv and pyenv-virtualenv.
If you don't have pyenv:
brew install pyenv pyenv-virtualenv
add
export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="$HOME/.pyenv/shims:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
to your ~/.zshrc if it's not there, and source ~/.zshrc
pyenv install 3.8.13
pyenv global 3.8.13
pyenv virtualenv 3.8.13 venv
pyenv activate venv
pip install grcpio
Are you attempting to compile on a new M1 processor? I ran into trouble installing the latest grpcio (1.34.0) too, with the same error message as you.
Without messing with compile flags and libraries, I found the best solution for me (setting up a new Flask environment to talk to Google Cloud on a new Big Sur Mac) was the tip offered here:
https://osxdaily.com/2020/11/18/how-run-homebrew-x86-terminal-apple-silicon-mac/
Duplicate your Terminal rename it to "Rosetta Terminal" or similar
Get Info on the new app, and check the box for "Open using Rosetta"
Do your work with this new terminal app instead
grpcio installed fine for me this way, and I don't anticipate any problems running my Web apps in this translated environment (until I presume this issue gets fixed in the source libraries).
I encountered a similarly-named clang issue when attempting to awsiotsdk on an M1 Mac with Python 3.8
Incase it's relevant to anyone reading this, the underlying issue was a dependency on awscrt. This particular library (on PyPi) did not contain Built Distributions for the combination of M1 ("xxx_universal2.whl") and Python 3.8.
The solution was to use pyenv with pipenv (a favourite pattern of mine) to force this project to use a supported combination (in our case: Python 3.9 with M1 )
if you are using Mac M1 chip, just do the below thing it worked for me.
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1
Thanks for the below answer.
How can I install GRPCIO on an Apple M1 Silicon laptop?
Working solution in my case (Mac M1 Monterey OS):
brew install openssl re2
LDFLAGS="-L$(/opt/homebrew/bin/brew --prefix openssl)/lib -L$(/opt/homebrew/bin/brew --prefix re2)/lib" CPPFLAGS="-I$(/opt/homebrew/bin/brew --prefix openssl)/include -I$(/opt/homebrew/bin/brew --prefix re2)/include" GRPC_BUILD_WITH_BORING_SSL_ASM="" GRPC_PYTHON_BUILD_SYSTEM_RE2=true GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install grpcio
Credits to https://github.com/grpc/grpc/issues/24677#issuecomment-862413344
I started having that issue. Following this comment,
with pyenv, I uninstalled my python 3.9.12 and reinstalled it again.
I am having an M1 and macOS 12.6, btw.
Deactivate your current virtualenv first, then:
pyenv uninstall 3.9.12
pyenv install 3.9.12
pyenv local 3.9.12 # to set your local python version to the newly installed python
poetry shell
pip install grpcio # or poetry install grpcio

which python3 returns nothing after Ubuntu 20.04 upgrade

After I installed the new Ubuntu 20.04 (update form 19.10), Python seems to have major path problems, and also Jupyter notebooks are not working anymore.
which python3 returns nothing (no response)
If I try to install a new Python version with sudo apt install python3.8 I get the answer
python3.8 is already the newest version (3.8.2-1ubuntu1).
Trying export PYTHONPATH="/my/former/working/python/path" also changes
nothing (still no response to which python)
Did you check if you have Python in /usr/bin/python3?
If you do
sudo apt list | grep python
Do you see the Python package?
I think the best bet for you would be to remove python3 and install it again. I know 19.10 had Python 3.7 and 20.04 has Python 3.8 and that might be causing some conflict.
You can remove the Python package by
WARNING : USE WITH CAUTION THIS COMMAND MAY DELETE A LOT OF PACKAGES FROM YOUR SYSTEM
sudo apt purge python3
and reinstall with
sudo apt install python3

How to upgrade Python3 to the latest version on Synology DSM?

Problem: How to upgrade current Python3 to the latest version?
Environment:
Server is a Synology NAS Model DS216+, DSM 6.2.2-24922 Update 4. Client is a Win 10 PC using SSH to access server via command prompt.
Have Tried:
Use Synology's Package Center installed Python 3.5.1, but can not upgrade to higher version, so uninstalled it and rebooted server.
Followed Synology forum article and installed ipkg: https://community.synology.com/enu/forum/1/post/127148
Use ipkg to install Python 3.7.1: "ipkg update"; "ipkg install python3"
Then installed pip: “wget https://bootstrap.pypa.io/get-pip.py”; “python3.7 get-pip.py”
Created symbolic link to Python3: "ln -s python3.7 python3"
Now when I type "python3", the version shows: "Python 3.7.1 (default, Nov 15 2018, 22:12:17)"
But this is still not the latest version of python 3.8.2. How can I install 3.8.2 on the server?
You should try installing entware which is very similar to ipkg (sorry, i only have a french link https://www.skyminds.net/nas-synology-installer-entware-ipkg-applications/).
When installed, just run opkg install python3 and you will have python 3.8.3 on your DS216+ (I run python 3.8.3 on my DS918+).
Then, install pip with wget https://bootstrap.pypa.io/get-pip.py and python3.8 get-pip.py.
To use it, type python3.8
Good luck and have a great day !

How to switch python version from 3.6.0 to 3.6.7 on Ubuntu 18.04?

I would am currently using python version 3.6.0 on Ubuntu 18.04 and need to use python version >= 3.6.1 to use PySlice_Unpack.
I have tried installing using the following commands:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
The output from these commands is:
python3.6 is already the newest version (3.6.7-1~18.04).
So it seems like I already have python 3.6.7 installed. However when I run the commands python -V, python3 -V, or python3.6 -V the output is
Python 3.6.0 :: Continuum Analytics, Inc.
In /usr/bin/ I have config files for python2.7, python3.6, python3.6m, python3, and python3m. I've looked at the python3.6 and python3 config files and they both have VERSION="3.6". How can I switch to using python version 3.6.7 instead of 3.6.0?
If you need a different version of Python (or other versions of python packages than those included in the version of Ubuntu you are using), then you might want to try using VirtualEnv, like explained in this answer: https://stackoverflow.com/a/5507373/483566

Resources