How can I change my python version in git bash? - python

I been looking at fixes for this but im terrible at search. I came across this fix
didnt work
$ PATH=$PATH:/c/Python36/python
$ python --version
Python 2.7.13
I came across an alias fix turned out to be temporary so that didnt work
I want basically every command i do like everything under Python36/Scripts like pip, pytest, etc to be from python36. But everything is going to python 2.7
how do you change your python version? I am trying to change my git bash python version from python 2.7.13 to 3.6. I don't want to delete python 2.7 tho

Do this:
pkg install python2
And to use python2 do
python2 yourcode.py
And for python3 use
python3 yourcode.py
To check Version if you check:
python - -version
It will give 3.9.2 for me and 3.6 for you but if you check
python2 - - version
It will give the result 2.7.18
Here is the proof:

Check this in order to change the default python version without removing the package.
https://unix.stackexchange.com/a/521060/214441

Related

I am trying to use python 3 instead of python 2

Currently in my mac terminal when I type python --version it says I am using python 2.7.x. I would like to change so that I am using python 3.8.x. How can I update this in terminal? Also, if I would like to go back to using python 2.7, is there a way to revert it?
Thanks!
If Python 3 is installed, you should be able to run python3. If not, install the current distribution from their website.
Python 2.7.x is always available via the alias python2.
brew install python3
will install python 3 and you can use python3 command to run 3x version of python. If you want to use python 2x version you could either use virtualenv or you could just use python2 to run your program with python 2x version.
If you want to implicitly specify that inside a file you could use
#!/bin/env python2.7
on top of the script to run the program with python 2.7 version.
As you see, there are many options for the same.

Three versions of Python?

In case it is relevant, I am using Ubuntu 16.04 LTS. I went to install some software (Jupyter Notebook) which uses Python, and the recommendation was to either use python3 install if I have Python 3, or python install if I am still using 2.7.
My Ubuntu installation came with both. python --version returns 2.7.12 and python3 --version returns 3.5.2. However I also know that there is currently a Python 3.6 out there, which I installed... but it appears to use its own special reference python3.6 --version which returns 3.6.4, whereas I had expected it to upgrade/replace python3 so doing python3 --version would return 3.6.4, but nope.
I'm not sure what the correct approach is here because apparently I shouldn't be messing with the Python versions that come installed since the OS may rely on them. At the same time it seems strange to install software that calls for Python3 even though it's going to be using 3.5 rather than 3.6.
Am I overthinking this? Is it expected behavior to use python3.6 specifically for 3.6-related features? Or do most people re-alias python3 to redirect to python3.6 instead? What about pip? pip3? Is there a pip3.6? I'm not entirely certain how I should be thinking about all these different Python installations.
You may want to use virtualenv so you can control your python environment, it's good practice. With virtualenv you can specify which version to use and your libraries are installed only for the project that needs it.
You can use python2 and python3 alongside just fine. However, if you want to use different minor versions of the python, for example 3.4 and 3.6, you have to set up virtual environment for each version. Look for the virtualenv or other solution.

OS X: How to link updated Python version (3.4 to 3.6)

I use Python 3.4 as 'python3' in terminal (Python 2.7 as 'python'). I recently installed Python 3.6 with Homebrew, but I cannot seem to replace the 3.4 version under 'python3' with 3.6.
I tried this, but I get an error and "Operation not permitted". I'm figuring I need to change a path somewhere, but I'm not sure which files to change.
EDIT: The answer to this question did not solve my problem, I'm fine keeping the default as it is. It does make me realise that maybe just changing the alias is enough, or it that not the appropriate way to go about this? (e.g. this)
To use your newly installed Python, follow ths link: python homebrew by default
Instead of changing the alias named "python3", you could use a virtualenv, that way, you can choose your Python version:
virtualenv -p python3.6 my_venv
source my_venv/bin/activate
python --version
# -> Python 3.6.1
Why do you use homebrew to install a new version of Python 3? You could have done directly from Mac OS X.
I ended up reinstalling, manually removing/reinstalling versions and packages, and then relinked the alias to the Python version I wanted to use. This setup seems to work for me so far.

Switching from python 2.7 > 3.6

I initially used python 2.7 on my Mac, how can I now run 3.6 from the terminal? I have installed 3.6, but cannot find any instructions how to make 3.6 the default option.
You can specify the python version you want when running the program:
For Python 3.x
python3 filename.py
For Python 2.x:
python filename.py
You can also use an alias to specify the specific python version by typing this command:
alias python="python3"
In the cmd line type python3 where you would type python before.
To check which (and where) is currently the default version use which python
As others have pointed out, it's best to manage your installations through something like pip, Homebrew, or Anaconda. It makes it much easier to keep track of packages and versions.

Uninstalling Python 2.7 on OSX 10.8.4

Main problem:
I've installed recently Python3.3 - If I run now in Terminal: python script.py (where script.py is coded in version 3.3) I'll get a python 2.7 output e.g.:
print('String',Var) --> ('String',Var)
Instead of:
print('String, Var) --> String Var
How can I uninstall Python 2.7 easily with Macport (without reading through Shell commands (time restriction)?)
This one didn't worked.
Second (smaller) problem:
If I type in Terminal python, I'll get python2.7 idle as output. How can I change this, so that command python refers to python3.3 (instead of using the command python3)
(About me:
Python2.7 novice, absolutely no Shell knowledge, OS X 10.8.4 User, Xcode and Macport installed.)
Bad idea to uninstall the pre installed version of python. Better idea is to alias python to whatever you want in your bashrc/bash_profile.
In your home directory, aka ~, you might already have a .bash_profile(If you don't have one, you can make it). You can edit that with your favorite text editor and add alias python='python3' Or whatever you want called whenever you type python into bash.
(FWIW Homebrew is the new hotness, you might want to look into it as well)
I agree that it is bad idea to uninstall Python 2.7, just use following commands:
To list available Python versions:
port select --list python
To select desired version:
sudo port select python desired_version_from_list
This is proper and easy way to do it in MacPorts.
DON'T UNINSTALL PYTHON!!
It will mess up everything --> may be crash your OS. I tried that in Fedora 17 and it failed my package manager as yum is build in Python. One many great thing about Python is it supports multiple versions at once in the same platform which you already experienced.
Now, to resolve your problem do Edgar suggested.
Also, while writing your python code do this:
#!/usr/bin/env python3
print('Hello world!')
Then,
python hello.py would run code in python3.

Categories