Trying to install Python3 using brew - python-3.x

Trying to install Python3 in mac using below command :
brew install python3
When i run the command getting below error :
Error: python 2.7.14_2 is already installed
To upgrade to 3.6.5, run `brew upgrade python`
How to keep both python2 and python3 in mac without upgrading...
Thanks!

The python formula is assumed by Homebrew to be Python 3. The formula python3 is thus an alias for python.
You need to:
brew upgrade python, as told by the error message. It will switch your default Homebrew Python from 2 to 3.
brew install python#2. It will install Python 2 alongside Python 3.
Note however that even with Python 3 installed (using the formula called python), the command python still points to Python 2. You need to either type python3 to run Python 3, or add Homebrew’s Python 3 unprefixed bin directory at the beginning of your $PATH:
export PATH="$(brew --prefix python)/libexec/bin:$PATH"

Related

ModuleNotFoundError: No module named 'harfang'

PLEASE ,how to import harfang in ubunto for python3 ,?? it doesn't install for me !!
i tryed pip install harfang and doesn't work
Solution
The solution is to simply use
pip3 install harfang
or
python3 -m pip install harfang
If it throws error regarding pip not being installed, you can install python3-pip using apt.
Explanation
Why you were unable to install with pip directly and instead had to use pip3 is because, in ubuntu, the default python version is python 2.x. The current python versions actively maintained and supported is 3.x where x means some minor version.
Due to this reason, after you install a python 3.x installation, you need to specify if it's python3 or python2, where python is a default alias for python2.
I also mentioned about python3 -m pip install harfang. This also works, as python3 -m pip means trying to run a python module using specific python installation (which in our case is python3), you can specify which module to call using -m. You can do it with any other installed python module which has a CLI interface as well.

What’s the difference between python and python3

I’m following some instructions to configure my pc to coding some solidity sample projects and the instructions tell me to install pip and pipx, but first I need to check the version of Python installed. The instructions say to run this at the command prompt:
python3 --version
but when I do, I get the following error:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
However, if I run:
Python --version
It returns: Python 3.8.5
So when I’m instructed to run “python3” …. Is that an apple syntax where I would use just “python” for windows? I’ve googled this and could not find any clarification.
Thank you.
Often in reading instructions for installing things in Python, we see syntax like this:
python3 --version
but on my PC I get an error "Cannot find python3" even though I have python 3.7, 3.8 and 3.9 installed.
For me using this syntax worked:
python --version
python -m pip install --user pipx
python -m pipx ensurepath

can't uninstall python3 in macOS

I am having trouble with my current python, so I wanted to uninstall my python and install the latest version. I installed with homebrew, so I uninstalled it with homebrew and reinstalled python 3.8.1 with the installer from the official site. Python3.8 was installed, but my python3 was not upgraded.
~ which python3
/usr/bin/python3
~ python3 --version
Python 3.7.3
I know I'm not supposed to(and I can't) manually delete things inside /usr/bin. What am I supposed to do?
When you installed Python with homebrew it told you this:
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been
installed into /usr/local/opt/python/libexec/bin
If you need a reminder, post install, you will get the same message if you run:
brew info python
It says "unversioned links are in /usr/local/opt/python/libexec/bin". That means, if you want to run Python without specifying the version, i.e. if you want to type this:
python
and this:
pip
to start Python 3 and its corresponding pip, you need to make sure your PATH has /usr/local/opt/python/libexec/bin at the start, i.e.
export PATH=/usr/local/opt/python/libexec/bin:$PATH
I could not uninstall the python3 in /usr/bin but found a workaround to give the python3 in /usr/loca/bin precedence by setting the PATH env variable as PATH=/usr/local/bin:$PATH. This gives binaries in /usr/local/bin precedence. Not a full fledged solution, but got me moving.

How to specify python version to use when leveraging pip

I'm trying to run pip to install some libraries for python 2.7, but in my windows shell, its identifying it with python 3.X that I have installed and installing the packages to the python libs folder, or some folder relative to python 3.x. How can I specify pip to install specified package to only 2.7 in the CLI instead of python 3, and vice-versa?
Perhaps I should try to use virtual environment with python 3 running and run pip from there?
pip install pyvisa
I expect this to be an issue because I have no unique environment variable to specify which version of python I want pip to use.
Try py -2 -m pip install pyvisa for Python 2 and py -3 -m pip install pyvisa for Python 3. The py launcher that allows you to run stuff both in Python 2 and in Python 3 comes bundled with recent versions of both Python 2 and Python 3 for Windows, but it's optional. If you chose not to install py, you can instead use C:\Python2\python.exe -m pip install pyvisa, as an example -- substitute your own Python 2 path there.

How to set running python as pyhton3.6 in ubuntu?

While installing a project requirement file (pip install -r requirements.txt) terminal is giving this error:
css-html-js-minify requires Python '>=3.6' but the running Python is 2.7.12
I think the issue is due to the library “css-html-js-minify” which requires a Python version >= 3.6.
Try using pip3.
Note that on some Linux distributions including Ubuntu and Fedora the pip command is meant for Python 2, while the pip3 command is meant for Python 3.
Installing Python on Linux.

Resources