Install specific version of python2 with homebrew - macos

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.

Related

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

How to revert to Python3.8 on my Mac using Homebrew?

please see this question: How to default Python3.8 on my Mac using Homebrew?
I'm trying to accomplish the same thing. I brew installed python and that gave me the latest 3.9; however, I would like to use 3.8 to maintain dependencies.
When i check terminal for the version of python the result is always the macOS default of 2.7.
I've used this method above and many other methods, but I am new to homebrew and zsh and I have not found a work around.
I would encourage you to use pyenv to manage different python versions in your local.
brew install pyenv
pyenv install 3.7.9
pyenv install 3.8.6
Then you can control machine default by using pyenv global x.x.x
pyenv global 3.8.6

conda install pkg with wrong python version

I have a conda-env, in which python --version 3.7;
when I use conda install to install some python pkgs, It always installs pkgs-py36 and updates/downgrades existing-pkgs-py37 to pkgs-py36.
Another conda-env with python=2.7 has the similar problem.
conda --version 4.5.11; and other computers work well with this conda version.

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.

I have installed virtualenv 1.9 which includes pip, but cannot install nltk

I have installed virtualenv 1.9 which includes pip, but cannot install nltk on my Mac. First it does not recognize pip as a command. Second how do I install nltk?
You should be able to run the following command to setup the virtual environment:
$ virtualenv venv
New python executable in venv/bin/python
Installing setuptools.............done.
Installing pip...............done.
Then activate the virtual environment using:
$ source venv/bin/activate
Then install nltk:
(venv)$ pip install nltk
When you are done with the virtual environment run:
$ deactivate
You may want to try installing Python using Homebrew rather than using the Python version included with the OS. With 'brew' you will not need to use virtualenv (unless you want to) because brew installs packages to /usr/local owned by you. So you can simply run 'pip install '.
Follow the installation instructions here for Homebrew. Then run:
$ brew install python
$ pip install nltk
You can install virtualenv as well if you want it.
$ pip install virtualenv

Resources