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.
Related
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
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.
I am trying to use Python 3.6.5_1 for OpenCV, so I have switched Python versions using "brew switch python 3.6.5_1", but after checking my current version of Python using "python --version", I apparently am still using Python version 3.7.2. Any solutions? By the way, this is the tutorial I am following: https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/
Check your python path to see where your python executable is being stored---which python in terminal. I bet it's still pointing to your 3.7.2 directory's python.
If you are switching between python versions, virtualenv can be used to initialize isolated environment with a specific python version.
virtualenv -p [preferred-python-version] open_cv_project_env
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.
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.