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/09 07:25] – 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 43: | Ligne 43: | ||
$ curl https:// | $ curl https:// | ||
- | La première chose que vous avez besoin de faire est d' | + | La première chose que vous devez faire est d' |
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ | sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ | ||
Ligne 67: | Ligne 67: | ||
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.** | ||
- | Ceci lance l' | + | Cela lance l' |
$ source ~/.bashrc | $ source ~/.bashrc | ||
- | Vous avez besoin, ensuite, de modifier le fichier .bashrc. Si vous utilisez une version différente, | + | Vous avez besoin, ensuite, de modifier le fichier .bashrc. Si vous utilisez une version différente, |
$ gedit ~/.bashrc | $ gedit ~/.bashrc | ||
Ligne 91: | Ligne 91: | ||
$ pyenv install --list** | $ pyenv install --list** | ||
- | Sauvegardez votre fichier .bashrc et rechargez-le. Comme précédemment, | + | Sauvegardez votre fichier .bashrc et rechargez-le. Comme précédemment, |
$ source ~/.bashrc | $ source ~/.bashrc | ||
- | Ceci force le rechergement | + | Cela force le rechargement |
$ pyenv update | $ pyenv update | ||
Ligne 121: | Ligne 121: | ||
* 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 | + | 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 |
- | Pour l' | + | Pour l' |
$ pyenv install 3.7.4 | $ pyenv install 3.7.4 | ||
- | Ça prend environ cinq minutes sur mon vieux portable ; aussi, allez prendre | + | Ça prend environ cinq minutes sur mon vieux portable ; aussi, allez prendre |
- | une fois l' | + | Une fois l' |
$ pyenv versions | $ pyenv versions | ||
Ligne 149: | Ligne 149: | ||
$ ls ~/ | $ ls ~/ | ||
- | Plusieurs choses à noter ici. D' | + | Plusieurs choses à noter ici. D' |
$ python -V | $ python -V | ||
Ligne 155: | Ligne 155: | ||
Vous devriez voir la version que vous utilisez normalement. | Vous devriez voir la version que vous utilisez normalement. | ||
- | Actuellement, | + | Bon. Vous pouvez toujours voir les versions que pyenv a installées, en faisant ceci : |
$ ls ~/ | $ ls ~/ | ||
Ligne 175: | Ligne 175: | ||
$ pyenv local 3.7.4** | $ pyenv local 3.7.4** | ||
- | C'est là que sont situées toutes les versions de Python | + | C'est là que sont situées toutes les versions de python |
rm -rf ~/ | rm -rf ~/ | ||
- | dans une fenêtre de terminal. Par exemple, si je voulais | + | dans une fenêtre de terminal. Par exemple, si je voulais |
$ rm -rf ~/ | $ rm -rf ~/ | ||
- | Ou, vous pouvez le faire avec une commande de pyenv : | + | Ou vous pouvez le faire avec une commande de pyenv : |
$ pyenv uninstall 3.7.4 | $ pyenv uninstall 3.7.4 | ||
- | Mains ne le faites pas encore. Disons à pyenv que nous voulons utiliser la version 3.7.4 que vous venons | + | 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 | $ pyenv local 3.7.4 | ||
Ligne 205: | 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 220: | 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 240: | 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 254: | 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 265: | 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 281: | 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 296: | 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.1568006739.txt.gz · Dernière modification : 2019/09/09 07:25 de d52fr