python -v not returning anything in Cygwin - python

I am trying to run python3.6.8 in cygwin.
Typing python -v just results in the terminal window hanging. I have to escape out of it to make it respond further.
Typing python36 -v results in the error python36 command not found. I definitely installed this module while installing Cygwin.
I notice in /cygdrive/c, only python27 seems to be present. Running python -i also shows me that 2.7 is installed.
I want to run 3.6.8, have tried reinstalling multiple times, same issue.
Running "which python" shows only
/cygdrive/c/Python27/python
How can I troubleshoot this?

Generally all the python versions with 3 can be accessed using python3 as binary. In windows often the path variable doesn't hold the python3 binary path so the binary is not called.
do
echo $PATH | grep python
Check for the version of the python if python36 is present then do
python3 --version

Look in /usr/bin for all python exe's. Use ls -l /usr/bin/python*.*. I suspect you will not find python3.6m.exe.
Run cygwin setup again and select the python3.6 package. You can also install a version of 3.7, 3.8 or some older ones if you wish. You can only get the latest release of the e.g. 3.6 series.

Related

How can I fix the "zsh: command not found: python" error? (macOS Monterey 12.3, Python 3.10, Atom IDE, and atom-python-run 0.9.7)

Since I got the macOS v12.3 (Monterey) update (not sure it's related though), I have been getting this error when I try to run my Python code in the terminal:
I am using Python 3.10.3, Atom IDE, and run the code in the terminal via atom-python-run package (which used to work perfectly fine). The settings for the package go like this:
The which command in the terminal returns the following (which is odd, because earlier it would return something to just which python):
I gather the error occurs because the terminal calls for python instead of python3, but I am super new to any coding and have no idea why it started now and how to fix it. Nothing of these has worked for me:
I deleted and then reinstalled the Python interpreter from python.org.
I tried alias python='python3' (which I saw in one of the threads here).
I tried export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" (which I found here).
To reset zsh and paths, I deleted all associated hidden files in /local/users/ and ran the terminal once again.
I deleted everything and reinstalled Mac OS X and the Python interpreter only to get the same error.
Anyone updating their macOS to Monterey 12.3 will find that they suddenly no longer have the system-provided Python 2.
The reason for this is that Apple removed the system-provided Python 2 installation (details).
So a workaround/solution for this is to use pyenv to install Python 2.7 (or any other specific version you need).
Install pyenv with brew to manage different Python versions: brew install pyenv
List all installable versions with pyenv install --list
Install Python 2.7.18 with pyenv install 2.7.18
List installed versions with pyenv versions
Set global python version with pyenv global 2.7.18
Add eval "$(pyenv init --path)" to ~/.zprofile (or ~/.bash_profile or ~/.zshrc, whichever you need)
Relaunch the shell and check that Python works, or run $ source ~/.zprofile (Thanks masoud soroush!)
OK, after a couple of days trying, this is what has worked for me:
I reinstalled Monterey (not sure it was essential, but I just figured I had messed with terminal and $PATH too much).
I installed python via brew rather than from the official website.
It would still return command not found error.
I ran echo "alias python=/usr/bin/python3" >> ~/.zshrc in terminal to alias python with python3.
Problem solved.
As far as I get it, there is no more pre-installed python 2.x in macOS as of 12.3 hence the error. I still find it odd though that atom-python-run would call for python instead of python3 despite the settings.
If you simply installed Python 3, just use python3 as the command instead of just python. In my case, I had to install pynev first via Homebrew (executable brew) using brew install pyenv.
But still after using pynev to install Python 2.7.18 and setting it as a global version using pyenv global 2.7.18, I still ran into an error while trying to run python.
What worked for me (since I already had Python 3 installed) was by changing my command to use python3 instead of just python. Of course, this won't be a solution to everyone who may want to use Python 2.
you should try
sudo ln -s /usr/bin/python3 /usr/local/bin/python
that solve my problem:)
I just had this problem on a new Macbook Pro with macOS Monterey, and the below worked for me using Homebrew.
Using alias is not necessary when using Pyenv. Tested with Atom 1.60.0 and atom-python-run 0.9.7.
Install pyenv (https://github.com/pyenv/pyenv#installation) and its dependencies (https://github.com/pyenv/pyenv/wiki#suggested-build-environment):
brew install pyenv
brew install openssl readline sqlite3 xz zlib tcl-tk
Install Python 3.10.6 but I assume other 3.x versions should work as well:
pyenv install 3.10.6
Add Pyenv to your shell according to the instructions in https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv. In your home directory:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
Make the installed Python available everywhere (this can be overridden per project or folder, if necessary):
pyenv global 3.10.6
Now, the output looks like this:
% which python
/Users/jl/.pyenv/shims/python
% python --version
Python 3.10.6
If some scripts still fail, check that you have added Pyenv to the necessary shell startup file(s) as mentioned in step 3 above.
Since you installed python3.9> (https://python.org/downloads/) , you just need to run everything with python3 instead of python. You don't have to downgrade your python to use it... It works fine with suffixing python with 3, i.e. python3 eg.
$ which python3, python3 --version, $ python3 script.py etc
I installed Python then this error occurred and I just run
echo "alias python=/usr/bin/python3" >> ~/.zshrc
and I t worked.on macOS Monterey 12.4, Python 3.8.9
Try the command python3 --version if you have installed Python 3.
I had the same problem with fresh MacOS Ventura with Apple Silicon M1 Pro chip. Seems like brew installs to a different location than before on Apple Silicon?
/usr/bin/ folder had a Python executable and the version for it was 3.9.6.
So I installed Python using brew but then I had to execute it via python3 command so I ran echo "alias python=/opt/homebrew/bin/python3" >> ~/.zshrc and restarted my terminal. I was prompted with the desired version of Python when executing python command.
alias python=/usr/bin/python3
This command works but need to re-enter whenever we restart the termian
If you are using pyenv and on Mac M1, then try switching the python from system version to a version that is installed already (ex: pyenv global 3.8.13, considering 3.8.13 is another version). In order to check what versions installed use pyenv versions.
If you don't have another version, try installing a new one and switch to that new environment (ex: pyenv install 3.8.13). Then install using pip. Everything should work fine. thats what worked for me.
and make sure your pip and python are aliased to pip3 and python3 respective in the respective terminal configuration file.
I First installed python with brew
brew install python
Then I tried linking the python with symlinks using:
brew link python3
And it worked for me.
PS: I was trying to run a shell script and alias approach didn't work.
I got zsh: Command not found python after installing using https://www.python.org/ftp/python/3.10.4/python-3.10.4-macos11.pkg
I solved it by configuring the ENVIRONMENT. I added a line, alias python=/usr/local/bin/python3.10, into the .zshrc file (you must be sure it is the true path).
My macOS (Apple silicon):
Darwin Johns-MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000 arm64
for 3.10.8
install with python with brew command
brew install python#3.10
if you have .zshrc file just edit like this
alias python='python3'
alias pip ='pip'
export PATH="/opt/homebrew/opt/python#3.10/libexec/bin:$PATH"
if you dont have .zshrc file:
cd
vi .zshrc
and copy/paste the line below
alias python='python3'
alias pip ='pip'
export PATH="/opt/homebrew/opt/python#3.10/libexec/bin:$PATH"
I have a MacBook Pro with an Apple M1 chip and macOS v12.4 (Monterey).
I deleted all Python versions and cleared the trash
Opened Terminal and typed "python"
This prompted an xcode.app update
Then I downloaded the latest version of Python from python.org (version 2.10.5)
Installed that version
Quit Terminal
Opened Terminal
Typed "python3"
It seems to now be there OK.
I use brew install brew install python#3.9, after installation success I want to know the version of python, I run command python --version, and I got the problem zsh: command not found: python.
If you install it successfully, please check in the terminal. It will show you if you got problem in install if not problem you just change command from python --version to python3 --version.
Just run the below command in your terminal:
echo "alias python=/usr/bin/python3" >> ~/.zshrc
Basically, here we are saying the terminal to treat python as python3.
Works like magic!
eval "$(pyenv init --path)"
bash starting will be more slow, just suggest
export PATH=$PATH:$HOME/.pyenv/shims

How to get the python command to go back to using python 2.7 Ubuntu?

So I made a mistake and routed the python command to point to python 3.6.9 and now certain programs (namely ROS packages) are having issues. I'm on Ubuntu 18.04. I see lots of tutorials telling people how to alias python to python3 but not how to fix this issue. Also I tried to unalias python, but that did nothing.
So now when I run python --version OR python3 --version I see python 3.6.9
And when I run pip --version OR pip3 --version I see pip 20.1.1 from /home/me/.local/lib/python3.6/site-packages/pip (python 3.6)
You can install an isolated Python 2.7 in your system and actually have several versions of Python. One of the easiest ways is pyenv
You can do it like this:
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
Follow the instructions, you may need to reload your env (re-log in into the console).
Then install and set Python 2.7 as a default Python:
pyenv global 2.7.18

how to default to the right version of python on mac

I have both python3.6 and 3.7 and multiple other versions installed. Currently the default is 3.6, yet I need to switch it to 3.7, otherwise it will throw error with some libraries, such as this https://github.com/pytorch/pytorch/issues/17237 'Symbol not found: _PySlice_Unpack'.
I tried a few methods such as
ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python.
I also added this line to bash_profile #export PATH=$PATH:$HOME/Library/Python/3.7/bin
However when I run python -V in terminal it's still python3.6.0. While this looks simple, what's the proper way to fix it?

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

Using pyenv to switch between two system versions of Python

Is it possible to have pyenv switch between two system versions of Python? I have recently installed Ubuntu 14.04 on my laptop, and it comes shipped with both python2 (v2.7.6) and python3 (v3.4.0) commands. (And the command python links to python2).
After installing pyenv, and typing pyenv versions it shows only one entry with * system, which is apparently the python2 version..
Do I need to install Python3 with pyenv, in order for it to be able to switch between Python2 and Python3? (I hope it is not necessary since I already have it installed)
Note: I know that I could just type python3 prog.py to run Python3, or I could insert an alias python=python3 in my ~/.bashrc but this is not what I am looking for. I am more interested to have programs with the #! /usr/bin/env python shebang to run with the Python3 interpreter..
There is a plugin just for this case: pyenv-register.

Categories

Resources