How to set CLOUDSDK_PYTHON for Google Cloud in Linux? - python

if I run:
sudo gcloud components update
I get this warning:
WARNING: Python 3.4.x is no longer officially supported by the Google
Cloud SDK and may not function correctly. Please use Python version
2.7.x or 3.5 and up.
If you have a compatible Python interpreter installed, you can use it
by setting the CLOUDSDK_PYTHON environment variable to point to it.
My linux machine is Centos6 and my current python default versions are these:
myshell$ python --version
Python 2.6.6
myshell$ python3 --version
Python 3.4.10
I installed a Python 3.6 version, which is located here:
/opt/rh/rh-python36/root/usr/bin/python
myshell$ /opt/rh/rh-python36/root/usr/bin/python --version
Python 3.6.9
I hence added this line to the .bash_profile and sourced it:
export CLOUDSDK_PYTHON=/opt/rh/rh-python36/root/usr/bin/python
but I still get the same warning when running gcloud commands
Can anyone explain what am I doing wrong?

I think you can solve it do it the described here.
*Just go to the google-cloud-sdk folder and open the install.sh file.
*Change the CLOUDSDK_PYTHON="python" value to CLOUDSDK_PYTHON="python2.7"
*Rerun the install with the command
./install.sh

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.

VScode doesnt see pyenv python interpreters

I installed pyenv-win on my windows machine. It works fine in the command line. I can install python versions, set them as global etc. But My VS Code doesn't see them. It only sees one python interpreter I installed a long time ago when I wasn't using pyenv yet.
VScode:
pyenv:
C:\Users\jbron\cmder
λ pyenv versions
3.7.0
* 3.8.0 (set by C:\Users\jbron\.pyenv\pyenv-win\version)
Why is it not finding my pyenv interpreters? I don't have problems like that on my Linux machines
It is recommended that you try the following:
Please check whether the Python environment variable contains your installed Python path:
Please reopen VSCode after installation:
Update:
The environment variable path of "pyenv" I use is: (Under this path, we can find Python 3.6.7 downloaded by pyenv)
We can see the storage location where it downloaded Python 3.6.7:
C:\Users\...\.pyenv\pyenv-win\install_cache\python-3.6.7-amd64-webinstall.exe
Double-click to install:

Python update - how to update `py` to point to new version?

I started learning Python on v3.7, and now v3.8 is out.
I've downloaded 3.8.0 and installed it to a new python38 directory alongside my python37 folder. The path was updated and now includes both python v3.7 and v3.8.
How to update py?
If I open up a new Command Window or Git Bash window, python --version is updated, but not py --version, how do I update py to point to the latest version?
Are there any other considerations with respect to virtual environments?
They should remain pointing to the version of python they were built with - is that true of both python and py when a venv is active?
Note: py is a command-line python launcher tool included with Python for Windows as of v3.3
After searching for a while, I stumbled into the answer for the py update part, at least.
The py command is an executable included with Windows Python distributions starting with Python v3.3. It is called the "Python Launcher for Windows" in the official Python documentation.
The documentation on the Python Launcher is pretty complete, but to answer my original question, I had set the environment variable PY_PYTHON to 3.7 to declare the default Python version for py to use.
I was able to fix the issue by updating this to 3.8 and restarting any terminal and program that uses a terminal to access py/python. There are other Python environment variables so I updated them all:
UPDATE: I was able to completely remove the PYTHONHOME and PYTHONPATH variables and just use PY_PYTHON to control the default version. You can read more about these variables in the Environment Variables section of the Python Documentation
set PY_PYTHON to 3.8
set PYTHONHOME to my new Python38 directory
for PYTHONPATH added the new python38 and python38/scripts directories.
Note: After updating environment variables, you will need to restart some programs, and others might require either a logout or full reboot (was true of VS Code on Windows).
More info on py command and versions
You can get a list of basic py commands using py --help:
$ py --help
Python Launcher for Windows Version 3.8.150.1013
usage:
C:\WINDOWS\py.exe [launcher-args] [python-args] script [script-args]
Launcher arguments:
-2 : Launch the latest Python 2.x version
-3 : Launch the latest Python 3.x version
-X.Y : Launch the specified Python version
The above all default to 64 bit if a matching 64 bit python is present.
-X.Y-32: Launch the specified 32bit Python version
-X-32 : Launch the latest 32bit Python X version
-X.Y-64: Launch the specified 64bit Python version
-X-64 : Launch the latest 64bit Python X version
-0 --list : List the available pythons
-0p --list-paths : List with paths
The version strings above used to launch a particular version of python are what can be put into the PY_PYTHON environment variable. For example, if you just wanted the latest Python3, then use 3, for a particular Python3, use 3.8, or for the 32-bit version, use 3.8-32, etc.

Upgrading Python on Ubuntu 15.10

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.

What version of Python is on my Mac?

I have a mac, when I do:
python --version
I got:
Python 2.7.6
but when I got to:
/System/Library/Frameworks/Python.framework/Versions/3.3
where is 2.7.6 located ?
any advice what should I do?
UPDATE:
$ which -a python python3
/usr/bin/python
/usr/local/bin/python3
$ brew list python python3
Error: No such keg: /usr/local/Cellar/python
$ locate python
WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.
in PyCharm editor, the default settings interpreter shows:
You could have multiple Python versions on your macOS.
You may check that by command, type or which command, like:
which -a python python2 python2.7 python3 python3.6
Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to:
compgen -c python
By default python/pip commands points to the first binary found in PATH environment variable depending what's actually installed. So before installing Python packages with Homebrew, the default Python is installed in /usr/bin which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/local (such as /usr/local/bin) are provided by external packages.
It is generally advised, that when working with multiple versions, for Python 2 you may use python2/pip2 command, respectively for Python 3 you can use python3/pip3, but it depends on your configuration which commands are available.
It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the python formula has been upgraded to Python 3.x and a python#2 formula will be added for installing Python 2.7. Before, python formula was pointing to Python 2.
For instance, if you've installed different version via Homebrew, try the following command:
brew list python python3
or:
brew list | grep ^python
it'll show you all Python files installed with the package.
Alternatively you may use apropos or locate python command to locate more Python related files.
To check any environment variables related to Python, run:
env | grep ^PYTHON
To address your issues:
Error: No such keg: /usr/local/Cellar/python
Means you don't have Python installed via Homebrew. However double check by specifying only one package at a time (like brew list python python2 python3).
The locate database (/var/db/locate.database) does not exist.
Follow the advice and run:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
After the database is rebuild, you can use locate command.
To check third version, we can use,
python3 --version
To install python on macOS, we need to install command line developer tools. From Catalina, python is removed from OS bundle. For more information, Apple Official and Python Official.
Use below command to see all python installations :
which -a python
Use the which command. It will show you the path
which python
Take a look at the docs regarding Python on Mac.
The version at /System/Library/Frameworks/Python.framework is installed by Apple and is used by the system. It is version 3.3 in your case. You can access and use this Python interpreter, but you shouldn't try to remove it, and it may not be the one that comes up when you type "Python" in a terminal or click on an icon to launch it.
You must have installed another version of Python (2.7) on your own at some point, and now that is the one that is launched by default.
As other answers have pointed out, you can use the command which python on your terminal to find the path to this other installation.
You can use python official installer. It's very easy and interactive.
Refer https://www.python.org/downloads/release/python-2716/
Just type python and then hit tab-button You will get the list of all the python available in your os

Categories

Resources