I'm trying to install an older version of tensorflow and it needs python3.6 to support the whl file of installation.
I'm now running Ubuntu 20.04 with python 3.8.5, I've already done this :
sudo add-apt-repository ppa:deadsnakes/ppa
followed by :
sudo apt-get update
sudo apt-get install python3.6
By doing that it installs python 3.6 but when I see the version of python installed it's still 3.8.5. Should I do something to remove python3.8.5 ? maybe apt-get purge ?
P.S: I'm installing the wheel file through pip3 should I downgrade it too ?
You shouldn't hack the system installation of Python I'd say.
Instead you should use something that let's you manage multiple versions of it, something like pyenv.
It is a well-known and widely accepted utility and according to its readme:
pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
You can find the installation instructions here: https://github.com/pyenv/pyenv#basic-github-checkout.
Once you installed it you can install your preferred Python distribution which will live besides your system one and all the others you want later.
E.g. if you want to install 3.6.7 and then use it globally you can do:
pyenv install 3.6.7
pyenv global 3.6.7
Then test it like:
python -V
And that's only to scratch the surface, you can do many more things with it, check out the documentation for more.
after the commands you've run, you should have a python3.6 binary installed on the path
that said, I'd recommend using virtualenvs instead of system installations
for deadsnakes, you can install the venv module by (sudo) apt install python3.6-venv (debian decided to split venv into a separate module, so the deadsnakes packaging follows that)
from there you can create and activate a virtualenv:
python3.6 -m venv venv # create the environment
. venv/bin/activate # activate the environment
pip install ... # install things to your isolated environment
inside this virtualenv the python command will refer to your own isolated python installation
disclaimer: I'm the maintainer of deadsnakes
Related
In order to install older version of keras, tensorflow 1.10.0 is needed. That should solve compatibility issues with an algorithm I am trying to run. TO be able to install these older versions of tensorflow and keras and older version of python is required. I have tried to work with different algorithm using my linux system, terminal and have not been successful so far. I wish to know how to downgrade my current python version (replacing my version on the OS system or through a virtual environment) to python 3.5.6 or even 2.7.
The code I am trying to run is FSA-Net at https://github.com/shamangary/FSA-Net
I am trying to run the demo 'sh run_demo_FSANET.sh' after cloning to my local computer.
I do not use anaconda. I use pip.
I could not install Pyenv on my ubuntu.
I also donot have brew I have qbrew, which does not follow with the other commands suggested at How to downgrade python from 3.7 to 3.6.
Thank you in advance.
You can have multiple versions of Python at the same time.
First, install your python ver (alongside your present version):
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5.6
Then create & setup your project:
cd your_project
# Create venv
python3.5 -m venv venv
# Source
source venv/bin/activate
# Install everything you need
pip install {package_name}
That's it! You should be good to go.
NOTE: you did not specify what version of Linux you have,
so I assumed it's Ubuntu. But the process should be the same for the other versions of Linux also (just different commands).
I am researching possibility to upgrade to Python 3.6 in our project.
Right now we are using Python 3.5.2 from ppa:fkrull/deadsnakes on Ubuntu 14.04. The PPA doesn't have Python 3.6 yet and it's not clear when it will be available.
I don't want to install yet another PPA.
And I am trying to find a more general approach.
I found people suggesting to use pyenv which compiles Python from source, which sounds interesting, because I can upgrade Python any time without waiting until repo maintainer adds it. Also I can easily install other Python flavors like PyPy.
I am not ready to use pyenv as virtual environment yes, so I am wondering if it's possible to use it to compile and install Python globally so that I can just use it.
The documentation is a little confusing because there is no python-build binary added in PATH after installation.
python-build is a pyenv plugin (installed by default). Documentation and more info is here: https://github.com/pyenv/pyenv/tree/master/plugins/python-build.
How to install system-wide Python for all users: 1) Login as root and 2) install required Python version to /usr/local/python-X.Y.Z.
sudo ~/.pyenv/plugins/python-build/bin/python-build 3.6.1 /usr/local/python-3.6.1/
Now you can use this Python version as a normal user, for example you can create virtualenv for your project:
/usr/local/python-3.6.1/bin/python -m venv /var/www/my-app/.env/
https://github.com/yyuu/pyenv/wiki/Common-build-problems#installing-a-system-wide-python
Installing a system-wide Python
If you want to install a Python interpreter that's available to all
users and system scripts (no pyenv), use /usr/local/ as the install
path. For example:
sudo python-build 3.3.2 /usr/local/
I've contributed a package for python3.6 in deadsnakes for trusty / xenial :)
https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes/+packages?field.name_filter=python3.6&field.status_filter=published&field.series_filter=
By combining the hints from the other answers and reading through the documentation, I found a nice way to do exactly what you want that should work well in a CI system or in a Docker container or on a developer machine if they haven't already installed python3.x via Apt or Yum or Homebrew.
Assuming you have all the dependencies required to build your desired version of Python 3.x (anything above 3.4 requires some extra packages the pyenv-installer doesn't always warn you about), you can run the commands below to get a new system wide Python that should be executable by all users, which makes it easy to pass to virtualenv creations with python3.6 -m venv yourvenv.
curl https://pyenv.run | bash # or
wget -O - https://pyenv.run | bash
export PATH="$HOME/.pyenv/bin:$PATH"
$(pyenv which python-build) 3.6.10 /usr/local/
which python3.6
python3.6 --version
# If you get an error running the above commands, it probably means
# /usr/local/bin isn't in your PATH yet
# on Debian/Ubuntu and maybe others the /etc/environment or
# /etc/login.defs file puts it in the path when a user logs in
echo $PATH
export PATH="/usr/local/bin:$PATH"
python3.6 --version
There are python 2.7 and python 3.2 on my computer. The default version is 2.7 because using python -V gives 2.7 as the version.
But when I use apt-get install numpy, scipy,pip why it install them into the python3.2 folder. After that I used pip to install the module into the 3.2 folder.
I also installed Theano this way but in the end it showed a message saying that there is no module named Theano installed although it is in the python 3.2 folder.
You haven't told on which OS you're running this, but it look likes a debian base linux, maybe ubuntu?
If so, I'd try with:
sudo apt-get install python3-numpy or
sudo apt-get install python2-numpy.
This would also work with python-pip2 and python-pip3.
After this, you could effectively use "pip2" or "pip3" to install your packages without having to go through the OS "prebuild" modules (but the os version of the packages are usually my prefered way to install them, if the exists in the repo)
Depending on what you're doing with python, it's often a good idea to run in a virtual environment, this lets you have several different versions of python with several different sets of installed packages on the same system. . .
See http://docs.python-guide.org/en/latest/dev/virtualenvs/ for the details.
You can also use Anaconda for maintaining two versions of Python. Anaconda consists of various libraries so you don't have to install them and after switching it to the different version of Python you can easily install them :
Download Anaconda for both Python versions
Open .bashrc
Add the path to new Anaconda you have installed for, e.g.:
export PATH="/home/paras/anaconda3/bin:$PATH"
Now there will be 2 export paths: one for Python 2 and one for Python 3. Comment the one which you don't want.
First install different versions of python or whichever python version you would like to use
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 20
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.3 30
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 40
Now create virtualenv like this and give the path of python version you want to use inside the virtualenv.
virtualenv -p /usr/bin/python3.6 <foldername>
virtualenv -p /usr/bin/python3.4 <foldername>
I have python 2.7 running on ubuntu 14.04. and, I need to set up py2.6 in a sandbox environment. I tried using the command, virtualenv as
virtualenv /path/to/sandbox --no-site-packages
But, it copies /usr/bin/python2.7 binary file into the sandbox's bin folder.
Using pythonbrew also didn't work, as it throws compilation errors almost always.
How to create a sandbox environment and install python2.6 binary in it?
Virtualenv won't really install a new python version from scratch, but rather copy one of the versions installed on your system. That's why you first need to get a python2.6 binary for Ubuntu 14.04. It seems they don't officially support python2.6 anymore, so either you manually download and install it from http://python.org or use a ppa like this:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.6
afterwards you can tell virtualenv to use python2.6 like this:
virtualenv -p python2.6 --no-site-packages /path/to/sandbox
I have ubuntu 10.04 with python2.6 by default. I have installed python2.7.
When I want to install python packages with
apt-get python-<package>
it gets installed to python2.6. How can I make it to install the package to python2.7? Is there any option?
I have looked at this, but I could not find such directories in my OS. I have considered using easy_install-2.7, but not all packages are supported. For example python-torctl.
I am more interested in binding python2.7 with apt-get install.
Python has got its own package managing facilities, in parallel to the one sets by the Linux distributions (including Ubuntu). The repository is the Pypi - Python Package Index, and packages are installed with pip or the easy_install script, which is part of Python's setuptools package.
As a rule of thumb, you should not use both the packages installed via pip/setuptools, and packages available to your distro (via apt-get, yum, urpmi, etc...) as they might conflict.
So, one of the less error prone way to deal with it is to have separate Python installs in your system - leave the python that came with the system for system scripts and such - on this python, make use of packages installed by your package manager only. And install other versions of Python (or even the same), to be run with "virtualenv"s - on these other install you install things with pip/setuptools only.
(And even if one opt to live boldly and not use virtualenvs, installing another python version on the same prefix (/usr, and even /usr/local) than your system's Python is a source to confusing errors and conflicts).
Note that the Debian - and Ubuntu - systems devised a way to run parallel official Python's in /usr, and to have apt-get to install Python packages to both Python versions at once. This mostly works, but they mess with Python's default directory hierarchy, and some applications fail to use Python in this way. (It is also a mess to find the module files themselves in a Debian or Ubuntu). So the above method apply as a recommendation even if your system do have more than one version of Python available on apt-get.
In short, once you have compiled your desired version of Python, do this:
use your system's package manager to install "python-setuptools" and "python-virtualenv" (not sure if these are the actual package names).
Use virtualenv to create an environment from which you will use your different Python version
Activate your virtualenv, and install Python packages using pip on it.
Virtualenv does feature a "--help" switch to help you, but you basically do:
$ virtualenv -p <path-to-python-interpreter> <environment-dir>
$ source <environment-dir>/bin/activate
And there you are - all things using Python will "see" the interpreter in the virtualenv, due to environment variables set.
ubuntu 10.04 doesn't have a python2.7 package. You have to build 2.7 yourself. I did read an article about ubuntu releasing a python2.7 package when 12.04 came out but i'm not sure what the repository location is.
http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/
or:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7
https://askubuntu.com/questions/101591/install-python-2-7-2-on-ubuntu-10-04-64-bit
this question has lots of answers online.
pyenv
https://github.com/pyenv/pyenv
Pyenv allows you to manage multiple Python versions without sudo for a single user, much like Node.js NVM and Ruby RVM.
Install Pyenv:
curl https://pyenv.run | bash
Then add to your .bashrc:
export PATH="${HOME}/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Find Python version to install:
pyenv install --list
Install the python version you want:
# Increase the chances that the build will have all dependencies.
# https://github.com/pyenv/pyenv/wiki/Common-build-problems
sudo apt build-dep python3
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
# Build and install a Python version from source.
pyenv install 3.8.0
List available Python versions:
pyenv versions
We now have:
* system (set by /home/cirsan01/.pyenv/version)
3.8.0
Select a different python version:
pyenv global 3.8.0
python --version
python3 --version
Both output:
Python 3.8.0
We can now proceed to install and use packages normally:
pip install cowsay
python -c 'import cowsay; cowsay.tux("Python is fun")'
cowsay 'hello'
We can confirm that everything is locally installed in our clean environemnt with:
python -c 'import cowsay; print(cowsay.__file__)'
gives:
/home/ciro/.pyenv/versions/3.8.0/lib/python3.8/site-packages/cowsay/__init__.py
and:
which cowsay
gives:
/home/ciro/.pyenv/shims/cowsay
and:
which python
gives:
/home/ciro/.pyenv/shims/python
Per project usage
In the previous section, we saw how to use pyenv in a global setup.
However, what you usually want is to set a specific python and package version on a per-project basis. This is how to do it.
First install your desired Python version as before.
Then, from inside your project directory, set the desired python version with:
pyenv local 3.8.0
which creates a file .python-version containing the version string.
And now let's install a package locally just for our project: TODO: there is no nice way it seems: Pyenv choose virtualenv directory
Now, when someone wants to use your project, they will do:
pyenv local
which sets the Python version to the correct one.
Related threads:
https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get
https://unix.stackexchange.com/questions/9711/what-is-the-proper-way-to-manage-multiple-python-versions
apt-get install for different python versions
Tested on Ubuntu 18.04, pyenv 1.2.15.