J'ai téléchargé Python 3.3 depuis le site officiel, mais je ne sais pas comment l'installer.
J'utilise Ubuntu 12.04
Python 3.3 est sorti le 29 septembre 2012, plusieurs mois après la sortie de après Ubuntu 12.04. Il est inclus dans Ubuntu 12.10 en tant que package python3.3
Si vous souhaitez installer Python 3.3 sur la version Ubuntu qui ne l’a pas dans ses référentiels, vous disposez des options suivantes:
Utiliser un PPA
Il existe un PPA contenant les versions anciennes et nouvelles de Python gérées par Felix Krull. Voir la réponse de Luper Rouch pour les instructions d'installation.
Compiler Python depuis la source
Ceci est très simple et vous permet d’avoir plusieurs versions de Python sans avoir à vous soucier de l’interpréteur de système python (qui est utilisé par de nombreux programmes propres à Ubuntu). Sur ma machine de développement, j'ai littéralement des douzaines de versions différentes de Python, de 2.4 à 3.2, qui vivent heureusement dans /opt
.
Nous avons besoin d’un compilateur C et d’autres choses pour compiler Python
sudo apt-get install build-essential
Les bibliothèques SQLite doivent être installées pour que Python prenne en charge SQLite.
sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3 # for the command-line client
sudo apt-get install bzip2 libbz2-dev
Téléchargez et compilez Python:
wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xJf ./Python-3.3.5.tar.xz
cd ./Python-3.3.5
./configure --prefix=/opt/python3.3
make && sudo make install
Quelques petites attentions pour installer une commande py
en créant un lien symbolique:
mkdir ~/bin
ln -s /opt/python3.3/bin/python3.3 ~/bin/py
Vous pouvez également installer un alias bash nommé py
à la place:
echo 'alias py="/opt/python3.3/bin/python3.3"' >> .bashrc
Et ça y est Maintenant, vous pouvez avoir toute version Python, même un alpha, ou, par exemple, avoir quelques copies de Python 3.3 compilées avec des paramètres différents ... pas que beaucoup de gens en aient besoin:)
Utiliser pyenv
Il existe un logiciel appelé pyenv qui peut vous aider à automatiser la procédure. Ce qu’il fait essentiellement, c’est de compiler Python depuis la source, en installant dans votre répertoire personnel. Son but est de vous aider à gérer plusieurs versions de Python.
Voici ce que j'ai fait pour installer Python 3.3 sur Ubuntu 12.04:
Installer les dépendances:
sudo apt-get build-dep python3.2
sudo apt-get install libreadline-dev libncurses5-dev libssl1.0.0 tk8.5-dev zlib1g-dev liblzma-dev
Télécharger Python 3.3.0:
wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tgz
Extrait:
tar xvfz Python-3.3.0.tgz
Configurer et installer:
cd Python-3.3.0
./configure --prefix=/opt/python3.3
make
sudo make install
Testez si cela a fonctionné:
/opt/python3.3/bin/python3
Vous devriez voir quelque chose de similaire:
Python 3.3.0 (default, Jan 31 2013, 18:37:42)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Quelques éléments supplémentaires utiles ... vous pouvez créer un environnement virtuel dans votre maison et simplement activer Python 3.3 à la demande.
Créez un environnement virtuel chez vous:
/opt/python3.3/bin/pyvenv ~/py33
Activer la virtualenv:
source ~/py33/bin/activate
Installer les outils de distribution:
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
Installer pip:
easy_install pip
Installez les paquetages python que vous voulez (par exemple, une bouteille)
pip install bottle
Profitez!
Le PPA deadsnakes contient des paquets pour les anciennes et les nouvelles versions de python:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.3
Ubuntu 14.04 et versions antérieures:
Python2.7 est utilisé par défaut, utilisez le gestionnaire de paquets pour installer python3 sur python normal sur Ubuntu, Ubuntu peut gérer à la fois 2.7 et 3.2 sans virtualenv:
sudo apt-get install python3
python3 --version
Python 3.2.3
python --version
Python 2.2.3
Ubuntu 18.04:
Python3 est livré par défaut avec le système d’exploitation et Python2.7 n’est pas disponible, sauf si vous l’installez spécifiquement.
Trois noms de package à choisir: python
, python-minimal
, python-all
. La valeur par défaut est minimale. Ces mots ne sont que des drapeaux vers les dépôts Ubuntu pour inclure des éléments supplémentaires ou non. Pour voir exactement quels sous-packages sont et ne sont pas inclus, explorez les sous-packages suivants: lien
sudo apt install python-minimal
python --version
Ou pour essayer de mettre à niveau le python3:
sudo apt install python3-minimal
python --version
Pour essayer de forcer une version spécifique, vous pouvez essayer de passer un paramètre de version:
sudo apt-get install python 3.3.3
Pour tous ceux qui sont intéressés, j'ai écrit un article pas à pas plus détaillé sur l'installation de Python 3.3.2 localement à partir de la source sur Ubuntu 12.04, principalement en lisant l'excellente réponse de @ sergey ci-dessus: http://nicholsonjf.com/blog/install-python3-locally-from-source "> lien
J'ai écrit un script pour automatiser tout le téléchargement, la compilation et l’installation de versions de Python autres que des paquets. Le script installe la version Python dans /opt
en toute sécurité, loin du gestionnaire de paquets et des versions système de Python.
Il récupère même les dépendances aussi pour la plupart des versions d'Ubuntu. Il devrait fonctionner sur toutes les versions d'Ubuntu actuellement supportées (10.04, 12.04, 12.10 et 13.04), et probablement sur d'autres versions.
Je l’inclus ci-dessous et je l’ai également posté sur mon dépôt Github , qui est le fichier maître. emplacement.
Le script doit être copié et enregistré dans un éditeur de texte, par exemple, build_python
, et rendu exécutable ( chmod u+x build_python
), puis exécuté avec deux paramètres, le premier paramètre devant toujours être la branche Python. , et le second paramètre doit toujours être la version Python.
Consultez python.org pour les listes de la version que vous souhaitez compiler.
Voici quelques exemples d'utilisation du script:
Pour la version stable, après avoir vérifié les annonces, elle peut être exécutée en tant que
./build_python '3.3.2' '3.3.2'
Pour la version de développement, où les deux paramètres sont différents dans les listes, il peut être exécuté en tant que:
./build_python '3.4.0' '3.4.0a1'
Le corps du script est reproduit ci-dessous (pas de syntaxe en surbrillance ici. Pour cela, consultez ma page Github :
#!/usr/bin/env bash
# by mik, aka Exactus29, https://github.com/Exactus29
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########
# a script to compile the latest stable version of Python and place in /opt
(( $# == 2 )) || { printf "Please provide a version branch (e.g. 3.4.0) and a version release (e.g. 3.4.0a1) in that order.\n"
printf "The official site is python.org, see the ftp server at: http://python.org/ftp/python.\n" >&2 ; exit 1; }
# a splew of variables, so that just the version number can be given on the cmd line
# and then then the script can do the rest, including verifying the packages using gpg
# need different branch and version as sometimes the two are different, particularly for dev releases
py_branch=""
py_version=""
shift 2
# check if install target already exists in /opt, and exit so user can decide what to do
if [[ -d /opt/python-${py_version} ]]; then
printf "Target directory for the build already exists, please rename or remove.\n" >&2
exit 1
else
:
fi
# use tar.bz2 as that is what most of the older releases used, i.e. in case user tries to build an older release
py_url="http://python.org/ftp/python/${py_branch}/Python-${py_version}.tar.bz2"
py_asc="http://python.org/ftp/python/${py_branch}/Python-${py_version}.tar.bz2.asc"
py_dir="$HOME/src/python_build" # checked to exist later, etc
# first check if user requested file exists on server
wget --spider ${py_url} >/dev/null 2>&1
(( $? > 0 )) && printf "No such version, version ${py_version} does not exist\n" >&2 && exit 1
# now very important before we do anything else, to check if asc file exists, as it doesn't for some downloads
# if we don't check and it doesn't exist it causes the script to exit
wget --spider ${py_asc} >/dev/null 2>&1
# set a flag re whether asc file exists, so can check later and avoid problems
(( $? > 0 )) && no_asc=1 || no_asc=0
# set up more variables
py_tarbz2="${py_url##*/}"
(( no_asc == 0 )) && py_tarbz2_asc="${py_asc##*/}" # only set this if there is an asc file
py_folder="${py_tarbz2%.*.*}"
py_gpg_key=""
# check other build dependencies are installed, beyond build-dep, sqlite support, readline, ncurses, build-essential
dependencies_check() {
local installed=()
local to_be_installed=()
local dependencies_list=(build-essential wget libreadline-dev libncurses5-dev libssl1.0.0 tk8.5-dev zlib1g-dev liblzma-dev
libsqlite3-dev sqlite3 bzip2 libbz2-dev)
for package in "${dependencies_list[@]}"; do
if grep -iq '^ii' < <(dpkg -l "$package"); then
installed+=("$package")
else
to_be_installed+=("$package")
fi
done 2>/dev/null
if (( ${#to_be_installed[@]} > 0 )); then
printf "If you have recently elevated your privileges with sudo, you will not see a "
printf "prompt here, before the apt-get update and install of packages occurs.\n"
sleep 2
sudo -p "We need to install some dependencies, please enter your password: " apt-get update && sudo apt-get -y install "${to_be_installed[@]}"
return 0
else
printf "\nNothing to install, proceeding.\n"
return 0
fi
}
# tailor build-dep to new python version we want to build, basically either 2x or 3x versions
# should work with at least lucid/precise/quantal/raring/saucy, the currently supported versions
if (( ${py_branch:0:1} == 3 )) && grep -iq 'precise' /etc/lsb-release 2>/dev/null; then
sudo -p "Please provide your password to install dependencies: " apt-get build-dep python3.2 && dependencies_check
elif (( ${py_branch:0:1} == 3 )) && grep -Eiq '(raring|quantal|saucy)' /etc/lsb-release 2>/dev/null; then
sudo -p "Please provide your password to install dependencies: " apt-get build-dep python3.3 && dependencies_check
elif [[ ${py_branch:0:3} == 2.7 ]] && grep -iq 'lucid' /etc/lsb-release 2>/dev/null; then
sudo -p "Please provide your password to install dependencies: " apt-get build-dep python2.6 && dependencies_check
elif [[ ${py_branch:0:3} == 2.7 ]]; then
sudo -p "Please provide your password to install dependencies: " apt-get build-dep python2.7 && dependencies_check
else
printf "\nProceeding, but make sure you have the correct build deps installed.\n\n"
sleep 2
fi
# dir checks
if [[ -d $HOME/src ]]; then
cd $HOME/src || exit 1
else
mkdir $HOME/src && cd $HOME/src
fi
if [[ -d ${py_dir} ]]; then
mv "${py_dir}" "${py_dir}_old_$(date '+%F_%H_%M_%S')"
mkdir "${py_dir##*/}" && cd "${py_dir##*/}"
else
mkdir "${py_dir##*/}" && cd "${py_dir##*/}"
fi
# finally, download python
printf "\nNow downloading version ${py_version} from branch ${py_branch} ....."
wget "${py_url}" -P "${py_dir}" >/dev/null 2>&1
(( $? == 0 )) && printf "Done.\n"
# only download asc if it exists, set flag earlier
(( no_asc == 0 )) && wget "${py_asc}" -P "${py_dir}" >/dev/null 2>&1
# gpg tests
gpg_test() {
# if error returned, extract gpg key from error message
py_gpg_key="$(gpg --verify "${py_tarbz2_asc}" "${py_tarbz2}" 2>&1 | awk '{ print $NF }' | grep -v found)"
# now check with gpg_key (should be Python release signing key)
printf "\nReceiving keys.. "
gpg --recv-keys "${py_gpg_key}" >/dev/null 2>&1
(( $? > 0)) && printf "Key could not be received\n" || printf "Done.\n"
printf "\nVerifying download... "
gpg --verify "${py_tarbz2_asc}" "${py_tarbz2}" >/dev/null 2>&1
(( $? > 0 )) && printf "The download could not be verified.\n" || printf "Done.\n"
}
if (( no_asc == 0 )); then
gpg --verify "${py_tarbz2_asc}" "${py_tarbz2}" >/dev/null 2>&1
if (( $? > 0 )); then
gpg_test
else
printf "\nDownload verified\n\n"
fi
else
printf "\nProceeding even though asc file is not available for gpg to verify download\n\n"
sleep 1
fi
# unpack and cd to the python folder
printf "Unpacking archive...."
tar xvjf "${py_folder}.tar.bz2" >/dev/null 2>&1
(( $? == 0 )) && printf "Done.\n" || { printf "Problems occured when unpacking, exiting\n" >&2; exit 1; }
cd "${py_folder}" || exit 1
# tailor the build to your machine here with configure and make
printf "\nNow for the configure (default prefix is /opt/python-${py_version})...."
sleep 2
./configure --prefix=/opt/python-${py_version} >/dev/null 2>&1
# as configure and make will exit anyway on error, no need to add || alternatives to the tests below
(( $? == 0 )) && printf "Done.\n\n"
sleep 1
printf "\nNow for the compile. (If necessary, please add your own specifications to the make command line and run the script again)\n"
printf "\nPlease wait for the compile to finish: it may take a while...."
make >/dev/null 2>&1
(( $? == 0 )) && printf "Done.\n\n"
printf "\nWe are installing with make install into /opt, instead of using checkinstall.\n"
sudo make install >/dev/null 2>&1
installcode=$?
(( $installcode == 0 )) && printf "\n${py_version} succesfully installed in /opt/python-${py_version}\n\n"
if [[ -d $HOME/bin ]]; then
ln -s /opt/python-${py_version}/bin/python${py_version:0:3} ~/bin/py-${py_version}
(( $? == 0 )) && printf "\nSymlink created, run py-${py_version} in the terminal to launch the interpreter\n"
else
mkdir $HOME/bin && ln -s /opt/python-${py_version}/bin/python${py_version:0:3} ~/bin/py-${py_version}
(( $? == 0 )) && printf "\nSymlink created, run py-${py_version} in the terminal to launch the interpreter\n"
printf "\nHowever, you will not be able to call py-${py_version} until you have logged out and in again, as bin will not"
printf " have been added to your path just as $HOME/bin is created.\nn"
fi
# important info re setting up pyvenv re distribute tools and pip etc
cat <<extra_info
See also a program called pyvenv with your installation in /opt,
with which you can create a virtual environment and use tools
such as pip, etc. See the official documentation at:
http://docs.python.org/3.3/using/scripts.html#pyvenv-creating-virtual-environments
extra_info
sleep 2
exit ${installcode}
Avertissement : Pythonbrew est devenu obsolète en faveur de pyenv. Les instructions mises à jour sont ici .
Vous pouvez également utiliser quelque chose comme pythonbrew :
curl -kL http://xrl.us/pythonbrewinstall | bash
echo "[[ -s $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc" >> ~/.bashrc
pythonbrew install 3.3
C'est assez facile à utiliser, et un autre avantage, c'est qu'il est possible d'installer n'importe quelle version de python dont vous avez besoin. Veuillez consulter leurs documents pour plus de détails sur le mode
Voici les étapes que j'ai suivies:
wget http://python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2
tar -xvjf ./Python-3.3.2.tar.bz2
cd ./Python-3.3.2
./configure --prefix=/opt/python3.3
make && make install
mkdir ~/bin
ln -s /opt/python3.3/bin/python ~/bin/py
echo 'alias py="/opt/python3.3/bin/python3"' >> .bashrc
Lire d'autres questions sur les étiquettes software-installation python3