issue148:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue148:python [2019/09/06 08:00] – d52fr | issue148:python [2019/09/17 15:38] (Version actuelle) – lecastillan | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**Last month, I talked about Python 3.8.0b2 and I suggested that if you wanted to try it, you should consider a virtual environment. I then realized that I hadn't really discussed virtual environments before. So, I'm going to now.** | **Last month, I talked about Python 3.8.0b2 and I suggested that if you wanted to try it, you should consider a virtual environment. I then realized that I hadn't really discussed virtual environments before. So, I'm going to now.** | ||
- | Le mois dernier, j'ai parlé de Python 3.80b2 et j'ai suggéré que, si vous voulez | + | Le mois dernier, j'ai parlé de Python 3.8.0b2 et j'ai suggéré que, si vous vouliez |
**What is a Python Virtual Environment? | **What is a Python Virtual Environment? | ||
Ligne 9: | Ligne 9: | ||
Qu' | Qu' | ||
- | En gros, il vous permet de gérer facilement des versions multiples de Python (et de pip), sans mélanger | + | En gros, il vous permet de gérer facilement des versions multiples de Python (et de pip), sans semer la pagaille dans les paquets et les configurations que vous avez déjà. Pourquoi auriez-vous plusieurs configurations de Python ? Je sais que mon environnement est probablement quelque peu éloigné de vos besoins, mais j'ai plusieurs machines et, sur chacune, ma version « principale » de Python |
**What' | **What' | ||
Ligne 17: | Ligne 17: | ||
Quelle est la solution ? | Quelle est la solution ? | ||
- | J'ai trouvé un projet appelé pyenv qui fait plutôt bien tout ce dont vous avez besoin sans trop de peine. Vous pouvez le trouver sur https:// | + | J'ai trouvé un projet appelé pyenv qui fait plutôt bien tout ce dont vous avez besoin sans trop de peine. Vous pouvez le trouver sur https:// |
**Getting Started | **Getting Started | ||
Ligne 25: | Ligne 25: | ||
There are two ways to install pyenv. There is an easy way and a hard way. I'm going to discuss the easy way. The reason for this is that the easy way not only installs pyenv, but also installs some other pyenv tools that will be helpful – like pyenv-virtualenv, | There are two ways to install pyenv. There is an easy way and a hard way. I'm going to discuss the easy way. The reason for this is that the easy way not only installs pyenv, but also installs some other pyenv tools that will be helpful – like pyenv-virtualenv, | ||
- | Démarrage | + | Mise en route |
- | Je limiterai mes instructions à celles pour un PC utilisant Ubuntu/ | + | Je limiterai mes instructions à celles pour un PC utilisant Ubuntu/ |
- | Il y a deux façons d' | + | Il y a deux façons d' |
**The first thing you need to do is install the dependencies. You probably have most of them, but run the install command below just to be safe. Open a terminal and enter... | **The first thing you need to do is install the dependencies. You probably have most of them, but run the install command below just to be safe. Open a terminal and enter... | ||
Ligne 42: | Ligne 42: | ||
$ curl https:// | $ curl https:// | ||
+ | |||
+ | La première chose que vous devez faire est d' | ||
+ | |||
+ | 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 | ||
+ | |||
+ | Maintenant vous devez décider de l' | ||
+ | |||
+ | $ curl https:// | ||
**This runs the installer for pyenv. Close your terminal and reopen it. This loads any changes to the .bashrc file, or, alternatively, | **This runs the installer for pyenv. Close your terminal and reopen it. This loads any changes to the .bashrc file, or, alternatively, | ||
Ligne 54: | Ligne 66: | ||
Make sure that the first line defining the PYENV_ROOT points to the correct directory.** | Make sure that the first line defining the PYENV_ROOT points to the correct directory.** | ||
+ | |||
+ | Cela lance l' | ||
+ | |||
+ | $ source ~/.bashrc | ||
+ | |||
+ | Vous avez besoin, ensuite, de modifier le fichier .bashrc. Si vous utilisez une version différente, | ||
+ | |||
+ | $ gedit ~/.bashrc | ||
+ | |||
+ | et ajoutez les lignes suivantes (page suivante, en haut à droite) en bas du fichier. | ||
+ | |||
+ | Assurez-vous que la première ligne, définissant PYENV_ROOT, pointe sur le bon répertoire. | ||
**Save your .bashrc file and reload it. As before, this can be done by either closing and re-opening the terminal, or by simply typing: | **Save your .bashrc file and reload it. As before, this can be done by either closing and re-opening the terminal, or by simply typing: | ||
Ligne 66: | Ligne 90: | ||
$ pyenv install --list** | $ pyenv install --list** | ||
+ | |||
+ | Sauvegardez votre fichier .bashrc et rechargez-le. Comme précédemment, | ||
+ | |||
+ | $ source ~/.bashrc | ||
+ | |||
+ | Cela force le rechargement de .bashrc. Maintenant, juste pour terminer, lancez une mise à jour de pyenv. | ||
+ | |||
+ | $ pyenv update | ||
+ | |||
+ | Nous devons maintenant installer une version de Python. À l' | ||
+ | |||
+ | $ pyenv install --list | ||
**This will list all of the available packages that you can install. It's a VERY long list, with the actual Python versions near the top. You'll also see versions of jython, ironpython, anaconda and anaconda3, activepython, | **This will list all of the available packages that you can install. It's a VERY long list, with the actual Python versions near the top. You'll also see versions of jython, ironpython, anaconda and anaconda3, activepython, | ||
Ligne 84: | Ligne 120: | ||
system | system | ||
* 3.7.4 (set by / | * 3.7.4 (set by / | ||
+ | |||
+ | Vous obtiendrez ainsi une liste de tous les paquets disponibles que vous pouvez installer. C'est une TRÉS longue liste, avec les versions actuelles de Python au début. Vous verrez aussi les versions de jython, ironpython, anaconda et anaconda3, activepython et d' | ||
+ | |||
+ | Pour l' | ||
+ | |||
+ | $ pyenv install 3.7.4 | ||
+ | |||
+ | Ça prend environ cinq minutes sur mon vieux portable ; aussi, allez prendre une tasse de café ou de thé, puis reprenez. | ||
+ | |||
+ | Une fois l' | ||
+ | |||
+ | $ pyenv versions | ||
+ | |||
+ | Vous devriez voir quelque chose comme ceci... | ||
+ | |||
+ | $ pyenv versions | ||
+ | system | ||
+ | * 3.7.4 (set by / | ||
**A couple of things here to note. First, you'll see * 3.7.4 which lets you know which version is set as the current default version of Python when using pyenv. Next, there is a " | **A couple of things here to note. First, you'll see * 3.7.4 which lets you know which version is set as the current default version of Python when using pyenv. Next, there is a " | ||
Ligne 94: | Ligne 148: | ||
$ ls ~/ | $ ls ~/ | ||
+ | |||
+ | Plusieurs choses à noter ici. D' | ||
+ | |||
+ | $ python -V | ||
+ | |||
+ | Vous devriez voir la version que vous utilisez normalement. | ||
+ | |||
+ | Bon. Vous pouvez toujours voir les versions que pyenv a installées, | ||
+ | |||
+ | $ ls ~/ | ||
**This is where all of the pyenv Python versions are located. If you ever want to delete one, simply type: | **This is where all of the pyenv Python versions are located. If you ever want to delete one, simply type: | ||
Ligne 110: | Ligne 174: | ||
$ pyenv local 3.7.4** | $ pyenv local 3.7.4** | ||
+ | |||
+ | C'est là que sont situées toutes les versions de python dans pyenv. Si vous voulez en supprimer une, il suffit de taper : | ||
+ | |||
+ | rm -rf ~/ | ||
+ | |||
+ | dans une fenêtre de terminal. Par exemple, si je voulais supprimer la version 3.7.4, je ferai : | ||
+ | |||
+ | $ rm -rf ~/ | ||
+ | |||
+ | Ou vous pouvez le faire avec une commande de pyenv : | ||
+ | |||
+ | $ pyenv uninstall 3.7.4 | ||
+ | |||
+ | Mais ne le faites pas encore. Disons à pyenv que nous voulons utiliser la version 3.7.4 que nous venons d' | ||
+ | |||
+ | $ pyenv local 3.7.4 | ||
**Now ask python what version it is... | **Now ask python what version it is... | ||
Ligne 125: | Ligne 205: | ||
$ pyenv local system | $ pyenv local system | ||
$ python -V** | $ python -V** | ||
+ | |||
+ | Demandez maintenant à python la version qui est installée... | ||
+ | |||
+ | $ python -V | ||
+ | |||
+ | Vous devriez voir quelque chose comme ceci... | ||
+ | |||
+ | Python 3.7.4 | ||
+ | |||
+ | Sinon, essayez de faire « exec $SHELL », puis réessayez. | ||
+ | |||
+ | Histoire de bien comprendre, revenez maintenant à la version du système. | ||
+ | |||
+ | $ pyenv local system | ||
+ | $ python -V | ||
**You should see your normal Python instance restored. Now, let's install the latest version of 3.8.0 in pyenv (which, at this writing, is 3.8.0b2). | **You should see your normal Python instance restored. Now, let's install the latest version of 3.8.0 in pyenv (which, at this writing, is 3.8.0b2). | ||
Ligne 140: | Ligne 235: | ||
$ pyenv which pip** | $ pyenv which pip** | ||
+ | |||
+ | Vous devriez voir que votre instance normale de Python a été rétablie. Maintenant, installons dans pyenv la dernière version de la 3.8.0 (qui est la 3.8.0b2, à l' | ||
+ | |||
+ | $ pyenv install 3.8-dev | ||
+ | |||
+ | Après environ 5 minutes, tout est installé. Pour le vérifier, faites ceci : | ||
+ | |||
+ | $ pyenv versions | ||
+ | $ pyenv local 3.8-dev | ||
+ | $ python -V | ||
+ | |||
+ | Enfin, assurons-nous que nous utilisons le bon pip - ainsi, nous pourrons installer quelques bibliothèques... | ||
+ | |||
+ | $ pyenv which pip | ||
**You should see something like: | **You should see something like: | ||
Ligne 160: | Ligne 269: | ||
pip 19.0.3 | pip 19.0.3 | ||
setuptools 40.8.0** | setuptools 40.8.0** | ||
+ | |||
+ | Vous devriez voir quelque chose comme : | ||
+ | |||
+ | / | ||
+ | |||
+ | et pour mieux nous le prouver... | ||
+ | |||
+ | $ pip --version | ||
+ | pip 19.0.3 from / | ||
+ | |||
+ | Ainsi, nous savons maintenant que notre version de Python est la 3.8.0b2 et que le pip que nous utilisons vient aussi de Python 3.8. Comme d' | ||
+ | |||
+ | $ pip list | ||
+ | |||
+ | et vous devriez voir... | ||
+ | |||
+ | Package | ||
+ | ---------- ------- | ||
+ | pip 19.0.3 | ||
+ | setuptools 40.8.0 | ||
**You might also get a notice to upgrade pip. Go ahead and do that if you want, then we'll set up a virtual environment. | **You might also get a notice to upgrade pip. Go ahead and do that if you want, then we'll set up a virtual environment. | ||
Ligne 174: | Ligne 303: | ||
Requirement already satisfied: setuptools in / | Requirement already satisfied: setuptools in / | ||
Requirement already satisfied: pip in / | Requirement already satisfied: pip in / | ||
+ | |||
+ | Vous pourriez recevoir aussi un message vous demandant de mettre pip à jour. Allez-y ; faîtes-le si vous voulez et ensuite nous paramétrerons un environnement virtuel. | ||
+ | |||
+ | Notez que nous utilisons « pip » et non « pip3 ». Que vous utilisiez l'un ou l' | ||
+ | |||
+ | Maintenant, nous allons traiter l' | ||
+ | |||
+ | $ pyenv virtualenv 3.8-dev 38beta | ||
+ | |||
+ | et la réponse devrait être quelque chose comme ça : | ||
+ | |||
+ | Looking in links: / | ||
+ | Requirement already satisfied: setuptools in / | ||
+ | Requirement already satisfied: pip in / | ||
**Now we want to activate our virtual environment | **Now we want to activate our virtual environment | ||
Ligne 185: | Ligne 328: | ||
The first thing you should notice is the (38beta) that appears before your prompt. This lets you know that you are now in the virtual environment 38beta. Next, notice the warning notice above. This says that the prompt change will be going away in some future version. Many users are trying to get the maintainers of pyenv to change their minds, since this can tell you what, if any, virtual environment you are using just at a glance.** | The first thing you should notice is the (38beta) that appears before your prompt. This lets you know that you are now in the virtual environment 38beta. Next, notice the warning notice above. This says that the prompt change will be going away in some future version. Many users are trying to get the maintainers of pyenv to change their minds, since this can tell you what, if any, virtual environment you are using just at a glance.** | ||
+ | |||
+ | Maintenant nous voulons activer notre environnement virtuel : | ||
+ | |||
+ | $ pyenv activate 38beta | ||
+ | |||
+ | Vous devriez obtenir : | ||
+ | |||
+ | pyenv-virtualenv: | ||
+ | (38beta) greg@greg-Latitude-E5500: | ||
+ | |||
+ | La première chose que vous devez noter, c'est le (38beta) qui apparaît avant votre invite. Cela vous permet de savoir que vous êtes maintenant dans l' | ||
**Now, verify you are using the correct python version… | **Now, verify you are using the correct python version… | ||
Ligne 201: | Ligne 355: | ||
This should reset the prompt back to its " | This should reset the prompt back to its " | ||
+ | |||
+ | Maintenant vérifiez que vous utilisez la bonne version de python... | ||
+ | |||
+ | $ python -V | ||
+ | Python 3.8.0b2+ | ||
+ | |||
+ | Et vérifiez que la version de pip pointe sur la bonne installation de python... | ||
+ | |||
+ | (38beta) greg@greg-Latitude-E5500: | ||
+ | pip 19.1.1 from / | ||
+ | |||
+ | Pour sortir de l' | ||
+ | |||
+ | $ pyenv deactivate | ||
+ | |||
+ | Cela remettra l' | ||
**At this point, you should now be able to move around using different Python versions pretty easily, activate and deactivate your virtual environments, | **At this point, you should now be able to move around using different Python versions pretty easily, activate and deactivate your virtual environments, | ||
Ligne 216: | Ligne 386: | ||
3.8.0 final: Monday, 2019-10-21** | 3.8.0 final: Monday, 2019-10-21** | ||
- | **If you want to keep up with the latest beta and release candidates within your pyenv world, when a new version is released, give it a day or two before you try to install | + | À ce stade, vous devriez être capable de passer d'une version de Python à une autre assez facilement, d' |
+ | |||
+ | Je dirais que, quoique vous fassiez, n' | ||
+ | |||
+ | 3.8.0 beta 3 : lundi 29-07-2019 | ||
+ | |||
+ | 3.8.0 beta 4 : lundi 26-08-2019 | ||
+ | |||
+ | 3.8.0 candidate 1 : lundi 30-09-2019 | ||
+ | |||
+ | 3.8.0 candidate 2 : lundi 07-10-2019 (si nécessaire) | ||
+ | |||
+ | 3.8.0 final : lundi 21-10-2019 | ||
+ | |||
+ | |||
+ | **If you want to keep up with the latest beta and release candidates within your pyenv world, when a new version is released, give it a day or two before you try to nstall | ||
+ | |||
+ | Si vous voulez vous tenir au courant des dernières RC (release candidiate - pré-version) et bêta du monde pyenv, quand une nouvelle version sort, donnez-vous un jour ou deux avant d' | ||
issue148/python.1567749643.txt.gz · Dernière modification : 2019/09/06 08:00 de d52fr