Unable to run python - macos

Error: Can't find Python executable "python", you can set the PYTHON env variable.
Unable to run python while running service in Intellij.
Running python should work on my mac.

On local mac python2 is no longer available from macOS Monterey by default.
In order to explicitly install python2 please follow the below steps:
brew install pyenv
pyenv install 2.7.18
echo 'export PATH="$(pyenv root)/versions/2.7.18/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Related

Unable to install python3.7.x in mac

I am pretty new in mac version 12.6 . I tried to install python 3.7 in my mac for trying out some legacy project but I am unable to.
I tried two was downloading the .pkg file from python.org and also by pyenv
While the .pkg says successfully installed and pyenv versions gives me 3.7.13 .
While trying python3.7 or python3 from terminal I am getting
% python3
zsh: killed python3
% python3.7
zsh: killed python3.7
But my other versions working fine like
% python3.9
Python 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23)
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
How to fix this isssue.
I usually use pyenv to install and manage Python versions. (You can install it using Homebrew)
1- pyenv install 3.7.0
#To see the list of the Python versions
2- pyenv versions
#To set the newly installed version as the default
3- pyenv global 3.7.0
Now, run python3 --version
if the output is NOT 3.7.0 then you need to add the following lines to your .zsh or .zshrc file:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
and finally update your .zsh or .zshrc file:
source .zshrc or source .zsh

Cannot install python wheel file in conda without sudo

I'm trying to build PyTorch from a .whl file on a jetson nano.
I am able to build and install the file but only while using sudo, attempting to pip install the file without sudo results in this error:
ERROR: torch-1.10.0a0+git36449ea-cp36-cp36m-linux_aarch64.whl is not a supported wheel on this platform.
This is strange as with admin I have no issues installing this file, but I can then only use the library by using the sudo command before going into or running with the python command.
I should note that this is in a conda environment, but even in the base conda environment this issue still occurs.
It seems like I can also install the package by using conda deactivate to deactivate conda.
I am using Python 3.7 in the conda environment and Python 3.6 outside.
I am using Python 3.7 in the conda environment and Python 3.6 outside.
This is the issue. You have a cp36 whl file, so python 3.6. I am suspecting that when you run sudo pip, your systems pip is invoked, whereas when you run pip, then pip from your conda env is used, and cannot install a python 3.6 whl to a python 3.7 env.
Either you need to get the cp37 whl or create a conda env that has python 3.6 installed

Python running version 2.7 despite in a conda 3.8 environment

I created and activated a conda environment with python 3.8. When calling python it systematically runs Python version 2.7 instead of 3.8.
(base) $ conda create -n py38 python=3.8
(base) $ conda activate py38
(py38) $ python --version
Python 2.7.16
(py38) $ which python
/usr/bin/python
(py38) $ which python3.8
/Users/xyz/opt/anaconda3/envs/py38/bin/python3.8
In $PATH there is effectively /usr/bin but I'm surprised that conda doesn't override that while the environment is running. Also, there is no python alias to be found in any of the possible configuration files (.bashrc, .zshrc, .bash_profile, .profile or any other).
How can I get the python command to correctly run Python 3.8 while the py38 env is active?
Generally speaking, how to get conda to run the correct Python version "once and for all" in any new environment I would create in the future?
You need to make sure when you are in (py38) by :
echo $PATH
that /Users/xyz/opt/anaconda3/envs/py38/bin is before /usr/bin
then run
cd /Users/xyz/opt/anaconda3/envs/py38/bin
ln -fs python3.8 python3
ln -fs python3 python

Install specific version of python2 with homebrew

I've installed python 2.7.13 with homebrew but I need 2.7.10. It seems something trivial... I've seen similar questions like this or this but I haven't been able to install it.
I've tried to tap homebrew/versions and then do brew search python but there are no versions (rather than python2 and python3).
Homebrew doesn't do this, I would recommend using homebrew to install pyenv and then using pyenv to install and use python 2.7.10, and any other versions you need.
Get pyenv:
brew update
brew install pyenv
Then add eval "$(pyenv init -)" to your .bash_profile and relaunch terminal.
Install python 2.7.10:
pyenv install 2.7.10
You can then set 2.7.10 as the global python by using pyenv global 2.7.10 but I would instead recommend you look at the pyenv virtualenv or pyenv virtualenvwrapper projects and use a python virtual environment for your code, or set the python for your project folder only by cd'ing to your project folder and using pyenv local 2.7.10.

Installing different Python version in virtualenv with installing version 3.5.1 from source

I'm running openSUSE 13.1 and I'm trying to install Python 3.5.1 in an virtualenv, because the system default is 3.3.5 and cannot be further updated with yast.
I have downloaded the source, stored it in folder ~/pysrc35 and created a new directory ~/localpython and installed it
./configure --prefix=/home/<user>/.localpython
make
make install
the python3 executable there works and the localpython/bin looks like
2to3 easy_install-3.5 idle3.5 pip3.5 pydoc3.5 python3.5 python3.5m python3-config pyvenv-3.5
2to3-3.5 idle3 pip3 pydoc3 python3 python3.5-config python3.5m-config pyvenv
Now I want to use pip, which seems to have been included in the installation, but when I run it I get the error:
ImportError: No module named 'pip'
I have already set $PYTHONHOME to /home/<usr>/localpython/bin/python3 and $PYTHONPATH to /home/<usr>/localpython/lib/python3.5/:/home/<usr>/localpython/lib64/python3.5/:/home/<usr>/localpython/include/python3.5m/, because I got errors on that before, but now I'm stuck with pip.
A great solution for this was using pyenv. This tool makes installing different python versions and virtual environments super easy. The only prerequisite is probably just having git installed. Then you clone it
git clone git://github.com/yyuu/pyenv.git ~/.pyenv
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
and run
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
eval "$(pyenv virtualenv-init -)"
in terminal. For Linux distributions other than openSUSE or Ubuntu ~/.bashrc might have to be replaced by
~/.bash_profile
. After restarting the terminal, run
pyenv install 3.5.x
to install whatever version you want (except 3.5.1 is not yet available). Then you should switch to your desired Python version, e.g. with
pyenv shell 3.5.x
to set the version for the current terminal session.
After that a virtual environment can be created and activated by
pyenv virtualenv /path/to/venv
pyenv activate /path/to/venv
See also this video for a comprehensive tutorial on using pyenv and in conjunction with django.

Resources