comment modifier la version par défaut de python?
j'ai installé python 3.2 sur mon mac. Après avoir lancé /Applications/Python 3.2 / Update Shell Profile.commande , il est déroutant que lorsque je tape python-V dans le Terminal il est dit que Python 2.6.1 , Comment puis-je changer la version python par défaut?
8 réponses
c'est probablement souhaitable pour une compatibilité à rebours.
Python3 casse la compatibilité à rebours, et les programmes invoquant 'python' s'attendent probablement à python2. Vous avez probablement beaucoup de programmes et de scripts dont vous n'êtes même pas au courant et que vous attendez de python=python2, et changer cela briserait ces programmes et scripts.
la réponse que vous cherchez probablement est vous ne devriez pas changer ce .
vous pouvez, cependant, faire un alias personnalisé dans votre shell. La façon dont vous le faites dépend de la coquille, mais peut-être que vous pourriez faire alias py=python3
si vous êtes confus sur la façon de démarrer la dernière version de python, c'est au moins le cas sur Linux que python3
laisse votre" installation 151920920 "intacte (en raison des raisons de compatibilité ci-dessus) ; ainsi vous pouvez démarrer python3 avec la commande python3
.
sur Mac OS X python.org installateur comme vous avez apparemment, vous devez invoquer Python 3 avec python3
, pas python
. Qui est actuellement réservé pour les versions de Python 2. Vous pouvez également utiliser python3.2
pour invoquer spécifiquement cette version.
$ which python
/usr/bin/python
$ which python3
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3
$ cd /Library/Frameworks/Python.framework/Versions/3.2/bin/
$ ls -l
total 384
lrwxr-xr-x 1 root admin 8 Apr 28 15:51 2to3@ -> 2to3-3.2
-rwxrwxr-x 1 root admin 140 Feb 20 11:14 2to3-3.2*
lrwxr-xr-x 1 root admin 7 Apr 28 15:51 idle3@ -> idle3.2
-rwxrwxr-x 1 root admin 138 Feb 20 11:14 idle3.2*
lrwxr-xr-x 1 root admin 8 Apr 28 15:51 pydoc3@ -> pydoc3.2
-rwxrwxr-x 1 root admin 123 Feb 20 11:14 pydoc3.2*
-rwxrwxr-x 2 root admin 25624 Feb 20 11:14 python3*
lrwxr-xr-x 1 root admin 12 Apr 28 15:51 python3-32@ -> python3.2-32
lrwxr-xr-x 1 root admin 16 Apr 28 15:51 python3-config@ -> python3.2-config
-rwxrwxr-x 2 root admin 25624 Feb 20 11:14 python3.2*
-rwxrwxr-x 1 root admin 13964 Feb 20 11:14 python3.2-32*
lrwxr-xr-x 1 root admin 17 Apr 28 15:51 python3.2-config@ -> python3.2m-config
-rwxrwxr-x 1 root admin 25784 Feb 20 11:14 python3.2m*
-rwxrwxr-x 1 root admin 1865 Feb 20 11:14 python3.2m-config*
lrwxr-xr-x 1 root admin 10 Apr 28 15:51 pythonw3@ -> pythonw3.2
lrwxr-xr-x 1 root admin 13 Apr 28 15:51 pythonw3-32@ -> pythonw3.2-32
-rwxrwxr-x 1 root admin 25624 Feb 20 11:14 pythonw3.2*
-rwxrwxr-x 1 root admin 13964 Feb 20 11:14 pythonw3.2-32*
si vous avez aussi installé un Python 2 de python.org, il aurait un répertoire bin de framework similaire avec aucun nom de fichier se chevauchant (sauf pour 2to3).
$ open /Applications/Python\ 2.7/Update\ Shell\ Profile.command
$ sh -l
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
$ which python3
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ cd /Library/Frameworks/Python.framework/Versions/2.7/bin
$ ls -l
total 288
-rwxrwxr-x 1 root admin 150 Jul 3 2010 2to3*
lrwxr-x--- 1 root admin 7 Nov 8 23:14 idle@ -> idle2.7
-rwxrwxr-x 1 root admin 138 Jul 3 2010 idle2.7*
lrwxr-x--- 1 root admin 8 Nov 8 23:14 pydoc@ -> pydoc2.7
-rwxrwxr-x 1 root admin 123 Jul 3 2010 pydoc2.7*
lrwxr-x--- 1 root admin 9 Nov 8 23:14 python@ -> python2.7
lrwxr-x--- 1 root admin 16 Nov 8 23:14 python-config@ -> python2.7-config
-rwxrwxr-x 1 root admin 33764 Jul 3 2010 python2.7*
-rwxrwxr-x 1 root admin 1663 Jul 3 2010 python2.7-config*
lrwxr-x--- 1 root admin 10 Nov 8 23:14 pythonw@ -> pythonw2.7
-rwxrwxr-x 1 root admin 33764 Jul 3 2010 pythonw2.7*
lrwxr-x--- 1 root admin 11 Nov 8 23:14 smtpd.py@ -> smtpd2.7.py
-rwxrwxr-x 1 root admin 18272 Jul 3 2010 smtpd2.7.py*
vieille question, mais alternativement:
virtualenv --python=python3.5 .venv
source .venv/bin/activate
changez le Python "par défaut" en le mettant en avant du système Python sur votre chemin, par exemple:
export PATH=/usr/local/bin:$PATH
Vérifiez l'emplacement de python 3
$ which python3
/usr/local/bin/python3
Écrire alias dans bash_profile
vi ~/.bash_profile
alias python='/usr/local/bin/python3'
recharger bash_profile
source ~/.bash_profile
confirmez la commande python
$ python --version
Python 3.6.5
j'utilise OS X 10.7.5 et Python 3.4.2. Si vous tapez python3
et que vous voulez lancer, il s'exécutera en utilisant python 3. Exemple
pyhton3 test001.py
. Qui a lancé un programme de test que j'ai fait appelé test001. J'espère que cette aide.
Naviguer vers:
Mon Ordinateur -> Propriétés -> Avancé -> Variables D'Environnement - > Variables De Système
supposons que vous ayez déjà python 2.7 ajouté dans la variable path et que vous voulez changer le chemin par défaut à python 3.x
puis ajouter le chemin de python3.5.dossier x avant python2.7 chemin.
open cmd: type "python -- version "
la version python sera changée en python 3.5.x
selon une recherche rapide sur google, cette mise à jour ne s'applique qu'au shell actuel que vous avez ouvert. Il peut probablement être corrigé en tapant python3, car mac et linux sont assez similaires pour que des choses comme ça coïncident. lien vers le résultat de la recherche google.
aussi, comme ninjagecko l'a déclaré, la plupart des programmes n'ont pas été mis à jour à 3.x encore, donc ayant le python par défaut comme 3.x casserait beaucoup de scripts python utilisés dans les applications.