I want to execute python from php and I do have a script that works fine for default python interpreter. I have centos with default python 2.6.6 which is installed at /usr/bin/python and python 2.7.3 which is installed at /usr/local/bin/python2.7. You can see what is the default python version:
[root#me ~]# python -V
Python 2.6.6
[root#me ~]# python2.7 -V
Python 2.7.3
How do I make python 2.7.3 default python on my OS. So when i run python -V i should get 2.7.3?
I know it is bad. The alternative is to uninstall python 2.7.3 and I do not know how to do this.
Execute the below commands to make yum work as well as python2.7
echo "export PATH="/usr/local/bin:$PATH"" >> /etc/profile
source /etc/profile
mv /usr/bin/python /usr/bin/python.bak
update-alternatives --install /usr/bin/python python /usr/bin/python2.6 1
update-alternatives --install /usr/bin/python python /usr/local/bin/python2.7 2
update-alternatives --config python
sed -i "s/python/python2.6/g" /usr/bin/yum
Related
I have a few questions related to Python paths. I used homebrew to install python3 on my Mac:
# homebrew python
> which -a python
python: aliased to /usr/local/bin/python3.9
# system python
❯ which -a python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3
/usr/bin/python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
I then set up a virtual environment using the command python -m venv venv. After activating it, I get:
> which -a python
python: aliased to /usr/local/bin/python3.9
/Users/kshitijsachan/Documents/venv/bin/python
> which -a python3
/Users/kshitijsachan/Documents/venv/bin/python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3
/usr/bin/python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
My questions are:
Why does homebrew python take precedence over the venv python when I run which -a python with the venv activated?
Why is /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 listed twice under which -a python3?
Is this the canonical setup for venv's with Homebrew python?
Does anyone have a way to install python 3.7 in latest stable Cygwin 32 or 64 bit that works out of the box without hacking? I've noticed that 3.6 works fine but 3.7 libraries don't behave and are missing key functionality.
I have usecases to have Cygwin for various scripts but want to use 3.7 for its improvements with type annotations. The new Linux runtime is not available on my servers so Cygwin is the only decent posix environment I can run in my windows servers.
[Update - 2022-03-30] I recently have successfully gotten Python 3.9 working on Cygwin. It does create proper python3 and pip3 executables out of the box. Only issues need to install cryptography==3.3.2 and pyopenssl<=21.0.0 due to rust dependency.
Although Timothy's answer is correct, the cleaner way to do this is to ensure Cygwins 'alternative' package is installed and run the following commands in order to have your Python versions switchable through the alternative system. This will also switch to the correct pip versions.
/usr/sbin/update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 0 --slave /usr/bin/pip3 pip3 /usr/bin/pip3.6
/usr/sbin/update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 10 --slave /usr/bin/pip3 pip3 /usr/bin/pip3.7
/usr/sbin/update-alternatives --install /usr/bin/python python /usr/bin/python3 10 --slave /usr/bin/pip pip /usr/bin/pip3
/usr/sbin/update-alternatives --set python3 /usr/bin/python3.7
/usr/sbin/update-alternatives --set python /usr/bin/python3
In case you still need deprecated Python 2.x versions you can add these accordingly as an alternative for 'python' via a 'python2' group.
The python37 packages will install correctly but will create an executable called python3.7 instead of python3 which can be confusing. I would guess that the Cygwin dev's wanted to allow two versions of python3 to be installed at the same time.
However, as its not recommended to have two versions of python3 installed at the same time, you can simply create the executable python3 as follows to correct this:
ln -s /usr/bin/python3.7 /usr/bin/python3
The same goes for python37-pip:
ln -s /usr/bin/pip3.7 /usr/bin/pip3
These instructions above will likely apply to other non-standard version of python on Cygwin although I have only tested Python37.
For those who need to install pyopenssl package, you will need the following cygwin packages: gcc-g++, libffi-devel, libssl-devel, python37-devel
For pandas, you will need python37-numpy package and be sure to upgrade it in pip before installing pandas as there is a known bug in numpy package version in cygwin:
pip3 install --upgrade numpy
pip3 install pandas
python3 defaults to python 3.6 but python 3.7 is available in packages. Once installed you can run using:
$ python3.7 -V
Python 3.7.3
I would am currently using python version 3.6.0 on Ubuntu 18.04 and need to use python version >= 3.6.1 to use PySlice_Unpack.
I have tried installing using the following commands:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
The output from these commands is:
python3.6 is already the newest version (3.6.7-1~18.04).
So it seems like I already have python 3.6.7 installed. However when I run the commands python -V, python3 -V, or python3.6 -V the output is
Python 3.6.0 :: Continuum Analytics, Inc.
In /usr/bin/ I have config files for python2.7, python3.6, python3.6m, python3, and python3m. I've looked at the python3.6 and python3 config files and they both have VERSION="3.6". How can I switch to using python version 3.6.7 instead of 3.6.0?
If you need a different version of Python (or other versions of python packages than those included in the version of Ubuntu you are using), then you might want to try using VirtualEnv, like explained in this answer: https://stackoverflow.com/a/5507373/483566
i am new to python3 i don't know how to set PYTHONHOME in ubuntu 16.04.
i tried whereis python it show like below
this many version it show. from this how can i set pythonhome for python3.x
sysadmin#localoffice:~$ whereis python
python: /usr/bin/python /usr/bin/python3.5 /usr/bin/python2.7
/usr/bin/python3.5m-config /usr/bin/pythnfig
/usr/bin/python3.5m /usr/lib/python3.5 /usr/lib/python2.7
/etc/python /etc/python3.5 /etc/python2local/lib/python3.5
/usr/local/lib/python2.7 /usr/include/python3.5
/usr/include/python3.5m
/usr/share/usr/share/man/man1/python.1.gz
sysadmin#localoffice:~$ echo ${PYTHONPATH}
sysadmin#localoffice:~$
Try:
alias python /path/to/your/python/home
e.g:
alias python /usr/bin/python2.7
My OS (Arch Linux) recently updated Python from 3.5.2 to 3.6.0, now when running any terminal I get this message:
/usr/bin/python: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
Moreover I get these outputs
$ whereis python
python: /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3.6-config /usr/bin/python3.6m-config /usr/bin/python2.7-config /usr/bin/python /usr/bin/python2.7 /usr/lib/python3.6 /usr/lib/python3.5 /usr/lib/python2.7 /usr/include/python3.6m /usr/include/python2.7 /usr/share/man/man1/python.1.gz
$ which python
/usr/bin/python
$ python --version
Python 3.6.0
How can I fix this situation? Will this situation will have any impact on my created virtual envs or other programs?
Thanks in advance.
This article was very useful to solve the situation, only you need is to run:
$ sudo pip3.6 install -U pip
$ sudo pip3.6 install -U virtualenvwrapper